Claviro

Algorithms

Binary Search – Efficient Searching

Before You Apply

First observe the behavior in Explore mode, then switch to Apply to test each operation with intent.

Core Idea

Binary search is an efficient searching algorithm that works on sorted arrays by repeatedly dividing the search space in half, achieving O(log n) time complexity.

Observe This First

Prerequisite: Array must be sorted

Then Apply

Standard: Find exact match → O(log n)

Binary Search – Efficient Searching Lab

Binary search needs sorted data. Track LOW, MID, HIGH range visually.

LOW: 0MID: -HIGH: 7

Ready|Waiting for a binary search

Time: O(log n)|Space: O(1)

Current
Comparing
Found
Discarded

Pseudocode

1mid = floor((low + high) / 2)
2if values[mid] == target: found
3if values[mid] < target: move low right
4else: move high left

Binary search works only on sorted data because each comparison discards half the range.

Explore mode: click elements to inspect index and sorted order.

Understanding the Observation

What did you observe?

Divide and Conquer: Split search space in half each time

Why did this happen?

Prerequisite: Array must be sorted

Apply with purpose

In Apply mode, test one operation and explain its complexity before running the next.

Predict next

Before clicking run, predict the next index/pointer movement and then verify it.