easy5 pts · first answer countsarraysbinary-search
Steps to find a value by binary search
You binary search for 7 in [1, 3, 5, 7, 9] with lo = 0, hi = 4 and mid = floor((lo + hi) / 2). How many elements are compared before 7 is found?
Discussion 0
Join free to post in the discussion.
Related questions
- Cost of reading arr[i]Backend Developer
- Inserting at the front of an arrayBackend Developer
- Why push is amortized O(1)Backend Developer
- Changing one character of a stringBackend Developer
- Reversing a simple stringBackend Developer
- slice vs spliceBackend Developer
- Index of the last elementBackend Developer
- indexOf and NaNBackend Developer