advertisement

Search Algorithm Visualizer

Explore Binary Search, DFS, and BFS with interactive step-by-step visualization.

Binary Search

Find elements in O(log n) time

Depth-First

Explore deep before wide

Breadth-First

Explore level by level

Path Tracking

See the search path visualized

Settings

SlowFast

Algorithm Info

Binary Search

Efficiently finds a target in a sorted array by repeatedly dividing the search space in half.

Time (Best)O(1)
Time (Worst)O(log n)
SpaceO(1)

Visualization

Step 0 / 0

Current Step Explanation

Configure your search and click "Start Search" to begin visualization.

Search Path

0
Ready

How to Use

  1. Select a search algorithm
  2. Enter data (array for Binary, graph for DFS/BFS)
  3. Set your target value/node
  4. Click "Start Search" and step through

Limitations

  • Binary Search requires sorted array
  • Graph nodes: single letters only
  • Maximum 20 array elements
  • Educational purposes only

Examples & Anti-patterns

When to Use Binary Search

Sorted Data Lookup

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!
Common Mistake

Using Binary Search on Unsorted Data

Binary search will return incorrect results on unsorted arrays.

// WRONG: Unsorted array
binarySearch([5,2,8,1,9], 8);
// May return -1 (not found)!

Frequently Asked Questions

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.