惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
D
DataBreaches.Net
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog
U
Unit 42
有赞技术团队
有赞技术团队
博客园 - 聂微东
GbyAI
GbyAI
宝玉的分享
宝玉的分享
F
Full Disclosure
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MyScale Blog
MyScale Blog
Jina AI
Jina AI
Martin Fowler
Martin Fowler
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
P
Proofpoint News Feed
A
About on SuperTechFans
I
InfoQ
博客园 - 【当耐特】
C
Check Point Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog
Project Zero
Project Zero
WordPress大学
WordPress大学
小众软件
小众软件
AWS News Blog
AWS News Blog
博客园 - 司徒正美
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
I
Intezer
Engineering at Meta
Engineering at Meta
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks
T
Tenable Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes

KIRUPA | Designers and Developers Unite

Understanding Merkle Trees Is a CompSci Degree Still Valuable in the Age of AI? The Model Context Protocol (MCP) Explained Vibe Coding + Expertise = Mega Win! 🏆 Animating our Grid How to Count in Negabinary (Base (-2)) — A Visual Guide Counting in Binary and Hexadecimal Pascal Pixel on Design, Development, and Solopreneurship! Do we really need to know how things work? 🧠 Drawing Sharp Lines on the Canvas The KIRUPA Tech Stack : It Bloom Filter: A Deep Dive Hash Functions Deep Dive Advanced Glitch Effect with Sound AI Killed the Content Creator...Star 🤩 Measuring the Distance Between Two Points by using the Pythagorean Theorem Detecting Browser Zoom Changes in JavaScript Creating a Fullscreen Grid Drawing a Perfect Grid on the Canvas Preserving the Pixel Art Look in Web Content Ensuring our Canvas Looks Good on Retina/High-DPI Screens Finding Prime Numbers Using a Sieve of Eratosthenes Two-Dimensional (2D) Arrays in JavaScript Two-Dimensional (2D) Arrays in JavaScript Animations: From Biology to JavaScript! 🦠 You’ll Always be Building & Designing Creating a Cluster Growth Animation: From Biology to JavaScript Timsort: A Lightning Fast Hybrid Sorting Algorithm Merge Sort: A Simple Step-by-Step Walkthrough 😀 - YouTube Bubble Sort: A Detailed Deep-Dive 🛁 Insertion Sort: A Deep Dive! 🍣 Selection Sort: A Step-by-Step Guide 💬 Radix Sort: A Complete Guide to Fast and Efficient Sorting! ⚡️ Career Growth Secrets Counting Sort : A Friendly (yet Detailed!) Deep Dive! 🎯 Bogosort: Sorting in the Slow Lane! 🐢 Pulling Off a Successful Redesign Creating Your Own Perfect Timing Radix Sort Making Counting Sort Work with Negative Values Diving Deep into Array Index Positions The Career Three Body Problem Counting Sort Work on Problems You Deeply Care About The Importance of Finding a Career Mentor Creating a Random Walk Simulation What is Product Strategy? Thinking about an 8K Resolution Future! 📺 Creating an Animated 3D Starfield Effect Meet the Default Sorting Algorithms! Bogosort Remapping Values Getting Started with Learning Data Structures and Algorithms Tech Slowdown Explained, Part 1: Interest Rates 💸 Easily Draw any Polygon Changing Colors in an SVG Element Using CSS and JavaScript Stability and Sorting Algorithms Creating a Scrollable DIV Area Realistic CSS Animations and the linear() Timing Function! 🍱 Visualizing Recursion with the Sierpinski Triangle Fast Sorting with Quicksort The Monty Hall Problem Stacks in JavaScript Depth-First Search (DFS) and Breadth-First Search (BFS) Introduction to the Graph Data Structure Big-O Notation and Complexity Analysis Introduction to Data Structures Arrays: A Data Structure Deep Dive Hashtables: A Deep Dive into Efficient Data Storage and Retrieval Trie (aka Prefix Tree) Embracing Generative AI with Open Arms! 🧸 Impact of AI on UI/UX Design with Chloe Barreau 🎨 Heap Data Structure Binary Search Trees Binary Tree Traversal Alphabetically Sort Names in an Array Overlapping Elements on Top of Each Other Developer Relations and Beyond with Jamie Barton! 🚀 A Trip Down Memory Lane 💾 Binary Trees Linked List The Present and Future of AI Tools with Ray (aka devbyrayray) Switching Web Hosts in 2023 😱 SVG: Converting Shape to Path The Versatility of SVGs 🌀 Spinning Circular Text Introduction to Trees Faster Searching with Binary Search Search Algorithms and Linear Search Fibonacci and Going Beyond Recursion Guess the Number Game
"Guess the Number" and Binary Searching! 🔍
KIRUPA 🍊 · 2023-03-31 · via KIRUPA | Designers and Developers Unite

Hi everybody - have you ever played the Guess the Number game? If you haven’t, take a few moments and give it a try from this link and start entering some numbers:

If you haven’t figured out the rules from playing the game a few times, here they are:

  1. The game is typically played with two or more players

  2. One player selects a number between a predetermined range (e.g. 1-100), and keeps it a secret from the other players

  3. The other players take turns guessing what the secret number is

  4. After each guess, the player who selected the secret number will respond with a hint such as higher or lower

  5. Players continue taking turns until someone correctly guesses the secret number

Our version of the game here is played between you and the computer, and you will always play the role of number guesser. The computer will pick a random number between 0 and 100.

When you start the game, you will pick a number first. This first guess will act as an anchor that will guide your next guess based on what the computer tells you. If the computer’s chosen number is higher, you’ll guess a higher number. If the computer’s chosen number is lower, you’ll guess a lower number. With each guess, you’ll get more higher or lower guidance from the computer. Eventually, you’ll hone in on the correct number and make a successful guess.

There is a more formal name for the approach we used to find the number our computer guessed. It is known as a binary search. To learn all about binary search, check out my in-depth tutorial here. For a bite-sized overview, do read on!

What makes binary search effective is that it eliminates many unnecessary paths (usually eliminates by half) as it works towards finding the item we told it to find!

Image

It's a divide-and-discard algorithm whose techniques we use in real life all the time. We used a less strict version of binary search when playing our Guess the Number game. When a guess was too large, we discarded all numbers that would have been larger. When a guess was too small, we discarded all numbers that were smaller.

For another example, whenever we look up a word in a physical dictionary, we use binary search again:

We know that all of the letters in the dictionary are alphabetically sorted. We can divide and discard our way toward finding the word we are looking for easily!

Connecting the dots a bit, this explanation of binary search is part of my upcoming book and tutorial series on data structures & algorithms. Periodically, I’ll share some of my latest content with all of you as shown in this newsletter article today.

Speaking of sharing, please feel free to like or retweet my tweet on this topic:

X avatar for @kirupa

🍊 KIRUPA@kirupa

kirupa.com

Faster Searching with Binary Search

11:55 PM · Feb 27, 2023

2 Likes

Lastly, before I forget, there is more fun and learning to be had. The Guess the Number game you played is part of a larger coding exercise where you get to try your hand at creating the whole example and sharing your result with others. There is a cool badge you can earn.

As always, thank you for reading till the end and having my content take up valuable space in your inbox and in your life. See you all next time and feel free to reach out to me on Twitter or on the forums.

Cheers,
Kirupa 😇