Mr. Grummel Get the app
← All notes
LEARNING 5 MIN READ DRAFT — DECEMBER 2027

The difference between checking every single item and knowing exactly where to look

Binary search finds a target in a sorted list by repeatedly eliminating half the remaining possibilities, while breadth-first and depth-first search explore an unsorted structure node by node, and choosing the right one depends on how the data is organised.

Searching algorithms find a specific target inside a larger collection of data, but which algorithm actually makes sense depends entirely on how that data is organised. Binary search finds a target in a sorted list with remarkable speed by repeatedly eliminating half the remaining possibilities, checking the middle element and discarding the half that can't contain the target. Breadth-first search and depth-first search instead explore an unsorted graph or tree structure, checking connected nodes level by level, or diving down one path as far as it goes before backtracking, because a graph has no single sorted order a binary search could exploit in the first place.

Binary search only works because a sorted list guarantees where the target can't be

Binary search's speed comes entirely from the guarantee a sorted list provides: checking the middle element against the target immediately tells you whether the target, if present, must sit in the left half or the right half, letting you discard the other half completely without ever having to examine it. Repeating that halving process quickly narrows the search down to the target's exact location, finding it in a number of steps that grows extremely slowly even as the list itself grows enormous. None of this works on an unsorted list, though, since without a guaranteed order, checking one element tells you nothing reliable about where the target might be relative to it.

BFS and DFS instead systematically visit connected nodes with no shortcut available

A graph or tree structure typically has no single linear order to exploit the way a sorted list does, so breadth-first and depth-first search instead systematically visit every reachable node, just following genuinely different strategies for the order they visit them in. Breadth-first search explores all of a node's immediate neighbours before moving further out, which makes it well suited to finding the shortest path in terms of number of connections. Depth-first search instead follows a single path as deep as it can go before backtracking to try another branch, which tends to use less memory and suits problems like checking whether any path exists at all, rather than finding the shortest one specifically.

Binary search finds a target in a sorted list by repeatedly eliminating half the remaining possibilities, while breadth-first and depth-first search explore an unsorted graph or tree structure by checking every node level by level or by diving down one path at a time, and choosing the right one depends entirely on how the data is actually organised.

What we're still unsure about

That binary search requires sorted data to work at all, and that breadth-first and depth-first search offer genuinely different trade-offs for exploring graph structures, are well established, thoroughly confirmed principles of algorithm design. What's more genuinely a matter of practical engineering judgement is exactly when the upfront cost of sorting a collection specifically to enable binary search is actually worth paying, versus simply running a slower linear search or a graph traversal directly on the unsorted data, since that trade-off depends on how many searches will actually be run against the same data afterward, and engineers continue to make real, context-dependent decisions about that trade-off rather than there being one universally correct answer.

This sits inside Searching Algorithms (Binary Search, BFS, DFS), one of eight topics in Algorithms, one of seven domains in Computer Science, one of seventeen subjects the app can quiz you on.

Draft — not published yet.
Try the pop quiz