Loading algorithms…

SOURAV ROY
Algorithms
  1. SOURAV ROY
  2. /
  3. algorithms

Algorithm Visualizer

A curated, interactive reference for software engineers. Study graph traversal, sorting, dynamic programming, and more — with step-by-step visualizations, complexity analysis, and pseudocode.

30
Algorithms
7
Categories
30
Interactive
0
Coming Soon
/

Showing all 30 algorithms

DifficultyOne core idea with minimal moving parts — ideal if you're new to the category.Combines several concepts or needs careful bookkeeping — comfortable after the Easy tier.Advanced theory, subtle invariants, or heavy state — take it slow and replay steps.
Graph1959

Dijkstra's Shortest Path

InteractiveMedium

Find the shortest path from a source node to all others in a weighted graph with non-negative edges. The quintessential greedy graph algorithm.

TimeO((V+E) log V)
SpaceO(V+E)
GreedyShortest PathPriority Queue
Explore Visualizer
Graph

Breadth-First Search

InteractiveEasy

Explore a graph level by level from a source node. Guarantees the shortest path in unweighted graphs.

TimeO(V+E)
SpaceO(V)
TraversalShortest PathQueue
Explore Visualizer
Graph

Depth-First Search

InteractiveEasy

Explore as deep as possible before backtracking. Foundation for cycle detection, topological sort, and more.

TimeO(V+E)
SpaceO(V)
TraversalRecursionStack
Explore Visualizer
Graph1958

Bellman-Ford

InteractiveMedium

Shortest paths from a source that handles negative edge weights and detects negative cycles.

TimeO(V·E)
SpaceO(V)
Shortest PathDynamic ProgrammingNegative Weights
Explore Visualizer
Graph1962

Floyd-Warshall

InteractiveMedium

All-pairs shortest path algorithm using dynamic programming. Works with negative weights (no negative cycles).

TimeO(V³)
SpaceO(V²)
All-PairsDynamic ProgrammingShortest Path
Explore Visualizer
Graph1968

A* Search

InteractiveHard

Heuristic-guided shortest path algorithm. Faster than Dijkstra's when a good heuristic is available.

TimeO(E log V)
SpaceO(V)
HeuristicShortest PathAI Pathfinding
Explore Visualizer
Graph1956

Kruskal's MST

InteractiveMedium

Build a Minimum Spanning Tree by greedily adding the cheapest edges that don't form cycles.

TimeO(E log E)
SpaceO(V)
MSTGreedyUnion-Find
Explore Visualizer
Graph1957

Prim's MST

InteractiveMedium

Grow a Minimum Spanning Tree one vertex at a time by always picking the cheapest reachable edge.

TimeO(E log V)
SpaceO(V)
MSTGreedyPriority Queue
Explore Visualizer
Graph

Topological Sort

InteractiveMedium

Order the vertices of a directed acyclic graph so every edge points forward. Kahn's in-degree peeling and DFS-based post-order, side by side.

TimeO(V+E)
SpaceO(V)
DAGOrderingQueue/Stack
Explore Visualizer
Graph

Cycle Detection (Directed)

InteractiveMedium

Detect cycles in a directed graph with three-color DFS: white unvisited, gray on the recursion stack, black fully explored. A back edge to a gray node means cycle.

TimeO(V+E)
SpaceO(V)
DFSColored DFSCycle
Explore Visualizer
Sorting1945

Merge Sort

InteractiveMedium

Divide-and-conquer sorting that guarantees O(n log n) time. Stable, predictable, and widely used in production.

TimeO(n log n)
SpaceO(n)
Divide & ConquerStableRecursive
Explore Visualizer
Sorting1959

Quick Sort

InteractiveMedium

Partition-based sort that is extremely fast in practice despite O(n²) worst case. Pick a pivot, partition the array, recurse — average O(n log n) with great cache locality.

TimeO(n log n) avg
SpaceO(log n)
Divide & ConquerIn-PlacePartitioning
Explore Visualizer
Sorting1964

Heap Sort

InteractiveMedium

Sort in-place using a max-heap. Phase 1 builds the heap; phase 2 repeatedly extracts the max. Guaranteed O(n log n) with no extra memory.

TimeO(n log n)
SpaceO(1)
HeapIn-PlaceSelection
Explore Visualizer
Sorting

Bubble Sort

InteractiveEasy

Repeatedly swap adjacent elements that are out of order. The simplest comparison sort — O(n²) worst case, but with an early-termination optimisation that makes it linear on already-sorted input. Stable and in-place.

TimeO(n²)
SpaceO(1)
ComparisonStableEducational
Explore Visualizer
Sorting1887

Radix Sort

InteractiveMedium

Sort integers digit by digit. Achieves linear time by exploiting digit structure instead of comparisons.

TimeO(d·(n+k))
SpaceO(n+k)
Non-ComparisonLinear TimeIntegers
Explore Visualizer
Searching1946

Binary Search

InteractiveEasy

Halve the search space at each step in a sorted array. The canonical O(log n) search algorithm.

TimeO(log n)
SpaceO(1)
Divide & ConquerSorted ArrayLogarithmic
Explore Visualizer
Searching

Linear Search

InteractiveEasy

Check every element until a match is found. Works on unsorted data; baseline for search algorithm comparisons.

TimeO(n)
SpaceO(1)
Brute ForceUnsortedSequential
Explore Visualizer
Searching1977

KMP String Matching

InteractiveMedium

Find a pattern in text in linear time by never re-examining text characters — the failure (LPS) table remembers how much of the pattern already matched.

TimeO(n+m)
SpaceO(m)
StringsLPS TableNo Backtracking
Explore Visualizer
Dynamic Programming

Fibonacci (Memoization)

InteractiveEasy

Cache overlapping subproblems to compute Fibonacci numbers in linear time instead of exponential.

TimeO(n)
SpaceO(n)
MemoizationOverlapping SubproblemsTop-Down
Explore Visualizer
Dynamic Programming

0/1 Knapsack

InteractiveHard

Maximize value in a capacity-limited knapsack. A classic NP-hard problem solved efficiently with DP.

TimeO(n·W)
SpaceO(n·W)
OptimizationBottom-UpNP-Hard
Explore Visualizer
Dynamic Programming

Longest Common Subsequence

InteractiveMedium

Find the longest subsequence common to two strings. Used in diff tools and bioinformatics.

TimeO(m·n)
SpaceO(m·n)
Strings2D DPSequence Alignment
Explore Visualizer
Dynamic Programming

Coin Change

InteractiveMedium

Find the minimum number of coins that make up an amount. Classic unbounded knapsack variant.

TimeO(n·amount)
SpaceO(amount)
OptimizationBottom-UpUnbounded
Explore Visualizer
Dynamic Programming1965

Edit Distance (Levenshtein)

InteractiveMedium

Minimum insertions, deletions, and substitutions to transform one string into another. The classic 2D DP with traceback for the exact edit script.

TimeO(m·n)
SpaceO(m·n)
Strings2D DPTraceback
Explore Visualizer
Tree

Binary Search Tree

InteractiveMedium

A BST maintains the ordering property: left < root < right. Enables O(log n) search, insert, and delete.

TimeO(log n) avg
SpaceO(n)
BSTOrderedRecursive
Explore Visualizer
Tree1962

AVL Tree

InteractiveHard

A self-balancing BST that maintains O(log n) height using rotations. Guarantees worst-case log n operations.

TimeO(log n)
SpaceO(n)
Self-BalancingRotationsBST
Explore Visualizer
Tree1952

Huffman Coding

InteractiveMedium

Build an optimal prefix-free code by repeatedly merging the two least-frequent nodes. Watch the greedy tree take shape and the codes fall out.

TimeO(n log n)
SpaceO(n)
GreedyPrefix CodeCompression
Explore Visualizer
Data Structures

Union-Find (DSU)

InteractiveMedium

Disjoint Set Union with path compression and union by rank. Near-constant time connectivity queries.

TimeO(α(n)) amortized
SpaceO(n)
Disjoint SetsPath CompressionGraph Connectivity
Explore Visualizer
Data Structures

Trie (Prefix Tree)

InteractiveEasy

Insert, search, and collect prefix matches character by character. The backbone of autocomplete and spell checkers.

TimeO(L) per op
SpaceO(A·L·n)
Prefix TreeStringsAutocomplete
Explore Visualizer
Data Structures

Segment Tree

InteractiveHard

Range queries and point updates in O(log n) via a binary decomposition of the array. Watch queries split, recurse, and merge.

TimeO(log n) per op
SpaceO(n)
Range QueryPoint UpdateDivide & Conquer
Explore Visualizer
Backtracking

N-Queens

InteractiveMedium

Place N queens on an N×N board so none attack each other. The canonical backtracking example — try, conflict, undo, retry.

TimeO(N!)
SpaceO(N)
BacktrackingConstraint SatisfactionRecursion
Explore Visualizer

Complexity Cheat Sheet

Big-O time & space for every algorithm in this catalog

Colour key:ExcellentGoodFairPoor
Graph(10)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Dijkstra's Shortest PathMediumO((V+E) log V)O(V+E)Greedy · Shortest Path
Breadth-First SearchEasyO(V+E)O(V)Traversal · Shortest Path
Depth-First SearchEasyO(V+E)O(V)Traversal · Recursion
Bellman-FordMediumO(V·E)O(V)Shortest Path · Dynamic Programming
Floyd-WarshallMediumO(V³)O(V²)All-Pairs · Dynamic Programming
A* SearchHardO(E log V)O(V)Heuristic · Shortest Path
Kruskal's MSTMediumO(E log E)O(V)MST · Greedy
Prim's MSTMediumO(E log V)O(V)MST · Greedy
Topological SortMediumO(V+E)O(V)DAG · Ordering
Cycle Detection (Directed)MediumO(V+E)O(V)DFS · Colored DFS
Sorting(5)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Merge SortMediumO(n log n)O(n)Divide & Conquer · Stable
Quick SortMediumO(n log n) avgO(log n)Divide & Conquer · In-Place
Heap SortMediumO(n log n)O(1)Heap · In-Place
Bubble SortEasyO(n²)O(1)Comparison · Stable
Radix SortMediumO(d·(n+k))O(n+k)Non-Comparison · Linear Time
Searching(3)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Binary SearchEasyO(log n)O(1)Divide & Conquer · Sorted Array
Linear SearchEasyO(n)O(1)Brute Force · Unsorted
KMP String MatchingMediumO(n+m)O(m)Strings · LPS Table
Dynamic Programming(5)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Fibonacci (Memoization)EasyO(n)O(n)Memoization · Overlapping Subproblems
0/1 KnapsackHardO(n·W)O(n·W)Optimization · Bottom-Up
Longest Common SubsequenceMediumO(m·n)O(m·n)Strings · 2D DP
Coin ChangeMediumO(n·amount)O(amount)Optimization · Bottom-Up
Edit Distance (Levenshtein)MediumO(m·n)O(m·n)Strings · 2D DP
Tree(3)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Binary Search TreeMediumO(log n) avgO(n)BST · Ordered
AVL TreeHardO(log n)O(n)Self-Balancing · Rotations
Huffman CodingMediumO(n log n)O(n)Greedy · Prefix Code
Data Structures(3)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
Union-Find (DSU)MediumO(α(n)) amortizedO(n)Disjoint Sets · Path Compression
Trie (Prefix Tree)EasyO(L) per opO(A·L·n)Prefix Tree · Strings
Segment TreeHardO(log n) per opO(n)Range Query · Point Update
Backtracking(1)
AlgorithmDifficultyTime ComplexitySpace ComplexityNotes
N-QueensMediumO(N!)O(N)Backtracking · Constraint Satisfaction

© 2026 SOURAV ROY · Built with 💖