Back to algorithmsPodstawowy
Binary Search
Fast searching in a SORTED array: we look at the middle and throw out half of the elements every time. In an array of a million numbers about 20 steps are enough.
O(log n)O(1)OIJOILOGIABOBR
โ๏ธ Binary Search โ Games
Play both games to master the algorithm!
๐ก
Tip: Start with Game 1 โ the sorted lockers show why we always open the middle and how half the lockers drop out at once. In Game 2 you run the code yourself: you compute the middle and keep track of left and right, exactly like on paper in a contest.