Bifalgorithm post
15 numbers sorted. Find 29 fast. Check them one by 1. 15 checks. Watch this instead. Two flags mark where the answer can lift. Check the middle 2323 is under 29, so everything on the left is out. Eight cells gone. One comparison. Cut the world in half middle of what's left 35 over 29, so the right side goes opposite direction. Same trick, three cells remain middle 29 found free checks. That's the whole search. 15 checks or three O of n or O of log n. Cut the problem in half. Every time.
15 numbers sorted. Find 29 fast. Check them one by 1. 15 checks. Watch this instead. Two flags mark where the answer can lift. Check the middle 2323 is under 2…
Ideas in this flowchart
- Search Process for 29
- Initial Setup
- 15 Numbers Sorted
- Binary Search
- Initial Check
- Middle Comparison
- Middle Value 2323 < 29
- Left Half Eliminated
- Middle Value 35 > 29
- Right Half Eliminated
- Final Check
- 29 Found
- Complexity
- O(n) vs O(log n)