Deep Understanding of Binary Search: An Analysis Based on “Grokking Algorithms” by Aditya Y. Bhargava

Khusni Ja'far
Tulisan Khusni
Published in
2 min readSep 30, 2023

Introduction:
In today’s era of information technology, algorithms form the backbone of many applications and systems we use daily. Binary search, as explained in the book “Grokking Algorithms” by Aditya Y. Bhargava, stands out as one of the most efficient search algorithms. For programmers, a profound understanding of this algorithm is not only crucial but also foundational.

The Essence of Binary Search:
Binary search operates by continually halving a sorted list until the sought-after element is found or confirmed absent. Its efficiency stems from its capability to cut the search space in half with each iteration.

Analyzing Binary Search in the Context of a List of Names:

Question 1:
Suppose you have a sorted list of 128 names. How many maximum steps would it take to find a specific name using binary search?

Answer:
By consecutively halving the list:

  1. 128 → 64
  2. 64 → 32
  3. 32 → 16
  4. 16 → 8
  5. 8 → 4
  6. 4 → 2
  7. 2 → 1

It can be concluded that a maximum of 7 steps is needed to find an element in a list of 128 names.

Question 2:
What if the size of the list is doubled to 256 names? How many maximum steps are now required?

Answer:
Using the same principle:

  1. 256 → 128
  2. 128 → 64
  3. 64 → 32
  4. 32 → 16
  5. 16 → 8
  6. 8 → 4
  7. 4 → 2
  8. 2 → 1

Thus, with a list of 256 names, it would take a maximum of 8 steps to either find the desired name or confirm its absence.

Conclusion:
The binary search algorithm offers significant insights into achieving efficiency in search operations. For programmers, understanding how binary search can handle expanding list sizes and how its efficiency is affected is an invaluable skill. Grasping these concepts deeply will equip them for bigger challenges in the world of programming and data analysis.

--

--