We apologize for the inconvenience...
To ensure we keep this website safe, please can you confirm you are a human by ticking the box below.
If you are unable to complete the above request please contact us using the below link, providing a screenshot of your experience.
Please solve this CAPTCHA to request unblock to the website
If you're seeing this message, it means we're having trouble loading external resources on our website.
If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.
Course: computer science > unit 1, binary search.
- Implementing binary search of an array
- Challenge: Binary search
- Running time of binary search
Describing binary search
- Let m i n = 1 min = 1 m i n = 1 m, i, n, equals, 1 and m a x = n max = n m a x = n m, a, x, equals, n .
- Guess the average of m a x max m a x m, a, x and m i n min m i n m, i, n , rounded down so that it is an integer.
- If you guessed the number, stop. You found it!
- If the guess was too low, set m i n min m i n m, i, n to be one larger than the guess.
- If the guess was too high, set m a x max m a x m, a, x to be one smaller than the guess.
- Go back to step two.
Want to join the conversation?
- Upvote Button opens signup modal
- Downvote Button opens signup modal
- Flag Button opens signup modal