Algorithm Visualizer

Visualize sorting, searching, and graph traversal algorithms with step-by-step animations.

Algorithm Category

Algorithm

Array Settings

Speed: Normal

Bubble Sort

Time
O(n²)
Space
O(1)

Repeatedly compares adjacent elements and swaps them if out of order. Simple but inefficient for large datasets.

Bubble Sort — Step 1 / 0

0% complete
Unsorted
Comparing
Swapping
Sorted
Pivot

Current Step

Press Play or Step Forward to begin.

Share this tool

Help others discover Algorithm Visualizer

About This Tool

How It Works

  • Select an algorithm category: Sorting, Searching, or Graph Traversal
  • Choose a specific algorithm to visualize
  • Use Play, Step Forward, and Step Back controls to explore each step
  • Each step shows a description of exactly what the algorithm is doing
  • Adjust speed to slow down or speed up the animation
  • Regenerate a new random array or reset to the initial state

Common Use Cases

  • Coding interview preparation and algorithm review
  • Understanding sorting algorithm differences and trade-offs
  • Learning graph traversal strategies (BFS vs DFS)
  • Teaching and explaining algorithms to students
  • Studying time and space complexity with visual context
  • Reinforcing computer science fundamentals interactively

Frequently Asked Questions

What algorithms can I visualize with this tool?

The Algorithm Visualizer supports three categories: Sorting algorithms (Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort), Searching algorithms (Linear Search, Binary Search), and Graph Traversal algorithms (BFS - Breadth-First Search, DFS - Depth-First Search).

How do I use the Algorithm Visualizer?

Select a category (Sorting, Searching, or Graph Traversal) from the left panel, then choose a specific algorithm. Use the Play button to start the animation, or use Step Forward / Step Back buttons to go through each step manually. You can also scrub through steps using the timeline slider at the bottom.

Can I control the speed of the animation?

Yes! Use the Speed slider in the left panel to choose between Slow, Normal, and Fast animation speeds. Slow is ideal for carefully studying each step, while Fast is great for seeing the overall algorithm behavior quickly.

What do the different colors mean in sorting visualizations?

In sorting visualizations: Indigo/Blue bars are unsorted elements; Yellow bars are being compared; Red bars are being swapped; Green bars are in their final sorted position; Pink bars indicate the pivot element (used in Quick Sort).

What do the node colors mean in graph traversal?

In graph visualizations: Light indigo nodes are unvisited; Red nodes are the current node being processed; Yellow/orange nodes are queued or discovered but not yet processed; Green nodes are fully visited. Highlighted edges show the traversal path.

Why does Binary Search always show a sorted array?

Binary Search requires a sorted array to work correctly. When you select Binary Search, the tool automatically sorts your array before running the algorithm. This is a fundamental requirement of binary search — it relies on the sorted order to determine which half to search next.

How can I search for a specific value?

When using Linear Search or Binary Search, an input field appears in the left panel where you can enter the target value. The visualization will then show the algorithm searching for that specific value in the array.

What is the difference between BFS and DFS?

BFS (Breadth-First Search) explores all neighbors of a node before going deeper — it uses a queue and finds the shortest path in unweighted graphs. DFS (Depth-First Search) goes as deep as possible along each branch before backtracking — it uses a stack (or recursion) and is useful for cycle detection and topological sorting.

Can I change the starting node for graph traversal?

Yes! When a graph traversal algorithm is selected, a "Start Node" dropdown appears in the left panel. You can choose from nodes A through G to start the traversal from any node in the graph.

Which sorting algorithm is the fastest?

Quick Sort and Merge Sort are generally the fastest with O(n log n) average time complexity. Quick Sort is often faster in practice due to better cache performance, but Merge Sort provides guaranteed O(n log n) performance. Bubble Sort, Selection Sort, and Insertion Sort are O(n²) and become slow for large datasets — but Insertion Sort is excellent for small or nearly-sorted arrays.

How many elements can I visualize at once?

You can adjust the array size between 6 and 30 elements using the Array Size slider. Smaller arrays are easier to follow step-by-step, while larger arrays demonstrate the algorithm's behavior more clearly. For a learning experience, 10–20 elements is recommended.

Can I generate a new random array?

Yes! Click the "New Random Array" button in the left panel to generate a fresh random array. The array size is determined by the Array Size slider. A new random target is also automatically selected for search algorithms.

Share ToolsZone

Help others discover these free tools!

Share this page

Algorithm Visualizer | Sorting, Searching & Graph Traversal