Find elements in O(log n) time
Explore deep before wide
Explore level by level
See the search path visualized
Configure your search and click "Start Search" to begin visualization.
Binary search excels when data is already sorted and you need fast O(log n) lookup.
// Finding in sorted array
const idx = binarySearch([1,3,5,7,9], 5);
// Only 2-3 comparisons needed!
Binary search will return incorrect results on unsorted arrays.
// WRONG: Unsorted array
binarySearch([5,2,8,1,9], 8);
// May return -1 (not found)!
Use DFS when you need to explore all paths or find any solution. Use BFS when you need the shortest path in unweighted graphs or level-order traversal.
Binary Search: O(log n). DFS and BFS: O(V + E) where V is vertices and E is edges.