Binary Search is magic 1,000 items → ~10 steps 1,000,000 items → ~20 steps No wonder its used in: - Databases → scan indexes fast - Search engines → look up terms - OS kernels → schedulers & symbol tables - Libraries → Python’s bisect, Java’s Arrays .binarySearch - Debugging → “first bad version” problems It’s everywhere a list is sorted.
@theskilledcoder Slight correction... databases actually use B+ trees where the node size is kept equal to the page size on the best effort basis. However, once you load the entire page from disk in memory, you use binary search to search for the key or find the place a new key to be inserted
@theskilledcoder Search engine doesn't sits directly on Btree implementation. Indexes scanning varies depending on their types and it might not be Btree. Scanning could be done on Clustered indexes, GIN...
@theskilledcoder its like the cheat code for searching!
@theskilledcoder Time complexity could be 1. Worst case 2. Expected case 3. Best case If the tree is not balanced, you will end with O(N) The expected case for the balanced tree is O(log_2 N) = log_10 (N) / log_10 (2) If N = 1m T = log_10(1m)/log_10 (2) = 6/0.3010 = 19.93 ~ 20 Max. ops = ~20