AlgoPrecision

Documentation

Algorithm Roadmap

This standalone workbench will grow from deterministic DSA visualizers into custom code visualization with step-by-step state, time complexity, and space complexity updates. Backend sync is intentionally deferred until the local profile and visualizer model are stable.

Supported Languages

JavaScript / Node.jsTypeScriptPythonJavaC++CC#
72 docs

Sorting

Bubble Sort

Repeatedly compares adjacent values and swaps inverted pairs until the largest unsettled value bubbles to the end.

Open

O(n^2) time / O(1) space

Adjacent comparisonSwapping
  1. Scan neighboring pairs.
  2. Swap when the left value is larger.
  3. Shrink the unsorted suffix after each pass.

Insertion Sort

Builds a sorted prefix by shifting larger values right and inserting the current value into its correct place.

Open

O(n^2) time / O(1) space

Sorted prefixShifting
  1. Pick the next unsorted value.
  2. Shift larger prefix values right.
  3. Insert the value into the gap.

Selection Sort

Selects the minimum value from the unsorted suffix and places it at the next sorted position.

Open

O(n^2) time / O(1) space

Minimum selection
  1. Track the smallest value.
  2. Scan the remaining suffix.
  3. Swap the minimum into place.

Merge Sort

Splits the array into halves, sorts each half recursively, and merges sorted runs back together.

Open

O(n log n) time / O(n) space

Divide and conquerMerging
  1. Split into halves.
  2. Sort each half.
  3. Merge the smaller front values first.

Quick Sort

Partitions values around a pivot so smaller values move left and larger values move right.

Open

Average O(n log n), worst O(n^2) time / O(log n) space

PartitioningRecursion
  1. Choose a pivot.
  2. Partition around it.
  3. Sort the left and right partitions.

Heap Sort

Turns the array into a max heap, repeatedly extracts the maximum, and restores heap order.

Open

O(n log n) time / O(1) space

HeapSelection
  1. Build a max heap.
  2. Swap root with the end.
  3. Heapify the reduced heap.

Shell Sort

Runs insertion-style passes over shrinking gaps so distant disorder is reduced early.

Open

Depends on gap sequence / O(1) space

Gap insertion
  1. Pick a gap.
  2. Insertion-sort by that gap.
  3. Shrink the gap until it reaches one.

Counting Sort

Counts occurrences of each value and rebuilds the array from frequencies.

Open

O(n + k) time / O(k) space

Frequency table
  1. Count each value.
  2. Walk the frequency table.
  3. Write values back in order.

Radix Sort

Sorts integers digit by digit using stable buckets from least significant to most significant digit.

Open

O(d(n + b)) time / O(n + b) space

Digit buckets
  1. Bucket by current digit.
  2. Collect buckets in order.
  3. Move to the next digit.

Searching

Linear Search

Checks values from left to right until the target is found or the array ends.

Open

O(n) time / O(1) space

Single scan
  1. Inspect one index.
  2. Compare it with target.
  3. Stop on match or continue.

Binary Search

Keeps halving a sorted search range by comparing the middle value with the target.

Open

O(log n) time / O(1) space

HalvingSorted array
  1. Check the middle.
  2. Discard the impossible half.
  3. Repeat until found or empty.

Lower / Upper Bound

Finds the first position where the target can be inserted while maintaining sorted order, then reports the first greater position.

Open

O(log n) time / O(1) space

Boundary search
  1. Check the middle.
  2. Keep possible lower-bound answers.
  3. Move left or right until the boundary is fixed.

Search in Rotated Array

Uses binary search logic on a rotated sorted array by identifying which half is sorted at every step.

Open

O(log n) time / O(1) space

Modified binary search
  1. Check the middle.
  2. Detect the sorted half.
  3. Discard the half where the target cannot fit.

Binary Search on Answer

Searches a numeric answer range and uses a feasibility check to find the smallest working value.

Open

O(n log S) time / O(S) visual answer-space view

Predicate monotonicity
  1. Try a candidate answer.
  2. Run the feasibility check.
  3. Keep smaller working answers or larger failing answers.

Hashing

Hash Insert

Hashes each key into a bucket and appends it using separate chaining.

Open

Average O(1) time / O(n) space

Modulo hashingChaining
  1. Compute the bucket.
  2. Check the chain.
  3. Insert the entry.

Two Sum

Looks up the complement before storing the current value so each pair can be found in one pass.

Open

O(n) time / O(n) space

Hash map lookup
  1. Compute complement.
  2. Check whether complement was seen.
  3. Store current value for future pairs.

Frequency Counter

Counts occurrences by mapping each distinct value to its running frequency.

Open

O(n) time / O(n) space

Counting
  1. Read value.
  2. Insert first count or increment existing count.
  3. Return the completed frequency map.

Group Anagrams

Uses a canonical sorted-letter signature as the hash key for each anagram group.

Open

O(n * k log k) time / O(nk) space

Canonical keys
  1. Sort letters to build a signature.
  2. Find the group for that signature.
  3. Append the word to the group.

Longest Consecutive Sequence

Stores values in a set and expands only from numbers that do not have a predecessor.

Open

O(n) time / O(n) space

Hash set expansion
  1. Insert distinct values into a set.
  2. Skip values with predecessors.
  3. Expand forward from true sequence starts.

Subarray Sum Equals K

Tracks prefix-sum counts so each index can find earlier prefixes that form a target-sum subarray.

Open

O(n) time / O(n) space

Prefix sumHash map
  1. Update running prefix.
  2. Look for prefix - k.
  3. Store the current prefix count.

Stacks And Queues

Stack Push

Places each new item at the top of a last-in first-out stack.

Open

O(1) time / O(n) space

LIFOTop pointer
  1. Read value.
  2. Create stack item.
  3. Move top to the new item.

Stack Pop

Removes the current top item so the next item becomes visible.

Open

O(1) time / O(n) space

LIFO
  1. Read the top.
  2. Remove it.
  3. Expose the next top.

Stack Peek

Reads the top item without changing the stack.

Open

O(1) time / O(n) space

LIFO
  1. Point at top.
  2. Return its value.
  3. Keep stack unchanged.

Valid Parentheses

Parses bracket pairs by pushing openings and matching each closing bracket with the current stack top.

Open

O(n) time / O(n) space

Stack parsing
  1. Push opening brackets.
  2. Match closing brackets against the top.
  3. Valid only when all matches succeed and the stack is empty.

Next Greater Element

Uses a decreasing monotonic stack of indexes to answer the next greater value for each position.

Open

O(n) time / O(n) space

Monotonic stack
  1. Keep unresolved indexes.
  2. Pop smaller values when a greater value appears.
  3. Store -1 for unresolved indexes.

Daily Temperatures

Tracks days waiting for a warmer future temperature with a decreasing stack of day indexes.

Open

O(n) time / O(n) space

Monotonic stack
  1. Push cooler unresolved days.
  2. Pop when a warmer day arrives.
  3. Write the distance between days.

Queue Enqueue

Adds values at the rear of a first-in first-out queue.

Open

O(1) time / O(n) space

FIFORear pointer
  1. Read value.
  2. Attach at rear.
  3. Advance rear.

Queue Dequeue

Removes values from the front in arrival order.

Open

O(1) time / O(n) space

FIFOFront pointer
  1. Read front.
  2. Remove it.
  3. Advance front.

Queue Peek

Reads the front value without removing it.

Open

O(1) time / O(n) space

FIFO
  1. Point at front.
  2. Return its value.
  3. Keep queue unchanged.

Sliding Window Maximum

Maintains a decreasing deque of indexes so the front always gives the current window maximum.

Open

O(n) time / O(n) space

Deque
  1. Remove indexes outside the window.
  2. Remove smaller indexes from the back.
  3. Read maximum from the front.

Queue Using Stacks

Implements FIFO behavior with one input stack and one output stack.

Open

Amortized O(1) time / O(n) space

Amortized operations
  1. Push enqueues into input stack.
  2. Move input to output only when needed.
  3. Pop output stack to dequeue oldest values.

Linked Lists

Reverse Linked List

Rewires node next pointers so the list points in the opposite direction.

Open

O(n) time / O(1) space

Pointer rewiring
  1. Save next.
  2. Point current to previous.
  3. Advance previous and current.

Middle of Linked List

Uses slow and fast pointers so the slow pointer lands on the middle when fast reaches the end.

Open

O(n) time / O(1) space

Fast and slow pointers
  1. Place both pointers at head.
  2. Move slow once and fast twice.
  3. Return slow when fast reaches the end.

Detect Cycle

Uses Floyd cycle detection: if slow and fast pointers meet, the list contains a cycle.

Open

O(n) time / O(1) space

Floyd cycle detection
  1. Move slow one step.
  2. Move fast two steps.
  3. Report a cycle when they meet.

Merge Two Sorted Lists

Builds one sorted chain by repeatedly attaching the smaller current node from two sorted lists.

Open

O(n + m) time / O(1) extra space

Two pointers
  1. Compare current nodes.
  2. Attach the smaller node.
  3. Append the remaining tail.

Remove Nth Node From End

Keeps a fixed pointer gap so the slow pointer stops just before the node to remove.

Open

O(n) time / O(1) space

Two pointers
  1. Advance fast by n.
  2. Move slow and fast together.
  3. Bypass the target node.

Trees

BST Insert

Places values in a binary search tree by moving left for smaller values and right for larger values.

Open

Average O(log n), worst O(n) time / O(n) space

Binary search tree
  1. Compare with node.
  2. Move left or right.
  3. Attach at an empty child.

Inorder Traversal

Visits left subtree, node, then right subtree so BST values appear sorted.

Open

O(n) time / O(h) space

DFS
  1. Traverse left.
  2. Visit node.
  3. Traverse right.

Preorder Traversal

Visits each node before its children, useful for copying or serializing tree structure.

Open

O(n) time / O(h) space

DFS
  1. Visit node.
  2. Traverse left subtree.
  3. Traverse right subtree.

Postorder Traversal

Visits children before their parent, useful for cleanup and bottom-up evaluation.

Open

O(n) time / O(h) space

DFS
  1. Traverse left subtree.
  2. Traverse right subtree.
  3. Visit node last.

Level Order Traversal

Explores tree nodes breadth-first by queueing children level by level.

Open

O(n) time / O(w) space

BFSQueue
  1. Queue root.
  2. Visit the front node.
  3. Enqueue its children.

Lowest Common Ancestor

Uses BST ordering to find the first node where two target paths split.

Open

O(h) time / O(1) space

Tree recursionBST property
  1. Compare both targets with current node.
  2. Move left or right if both targets are on one side.
  3. Return the split point.

Trie Insert / Search

Stores words character by character so prefix lookup follows one edge per letter.

Open

O(w * k) build / O(k) search space O(total characters)

Prefix tree
  1. Insert each word character by character.
  2. Share common prefixes.
  3. Search by following target letters.

Graphs

BFS

Explores graph nodes by distance layers using a queue.

Open

O(V + E) time / O(V) space

QueueVisited set
  1. Start with a queue.
  2. Visit one layer.
  3. Add unseen neighbors.

DFS

Explores deeply along each branch before backtracking.

Open

O(V + E) time / O(V) space

RecursionStack
  1. Visit node.
  2. Go to an unseen neighbor.
  3. Backtrack when blocked.

Dijkstra

Finds shortest paths from one source in a weighted graph with non-negative edges.

Open

O((V + E) log V) time / O(V) space

Priority queue
  1. Set source distance.
  2. Pick the nearest unsettled node.
  3. Relax outgoing edges.

Topological Sort

Orders a DAG by repeatedly removing nodes with zero incoming edges.

Open

O(V + E) time / O(V) space

DAG ordering
  1. Count indegrees.
  2. Queue zero-indegree nodes.
  3. Emit nodes and reduce neighbor indegrees.

Union Find

Tracks connected components with find and union operations.

Open

Almost O(1) amortized per operation / O(V) space

Disjoint set
  1. Start each node as its own parent.
  2. Find roots for each edge.
  3. Union different roots and reject same-root edges.

Minimum Spanning Tree

Builds a minimum spanning tree with Kruskal by accepting the lightest edges that do not create cycles.

Open

O(E log E) time / O(V) space

KruskalUnion Find
  1. Sort edges by weight.
  2. Accept edges joining different components.
  3. Stop when the tree spans all nodes.

Dynamic Programming

Fibonacci

Stores smaller Fibonacci values so each state is solved once.

Open

O(n) time / O(n) space

MemoizationTabulation
  1. Seed base cases.
  2. Combine previous states.
  3. Return requested state.

Climbing Stairs

Counts ways to reach each step from the two previous steps.

Open

O(n) time / O(n) space

1D DP
  1. Seed step counts.
  2. Add previous two states.
  3. Read final step.

Coin Change

Builds minimum coin counts for each amount by trying every coin.

Open

O(amount * coins) time / O(amount) space

Unbounded knapsack
  1. Initialize amount states.
  2. Try each coin.
  3. Keep the smaller count.

0/1 Knapsack

Builds a table of best values by item index and capacity, choosing between skipping or taking each item.

Open

O(items * capacity) time / O(items * capacity) space

2D DP
  1. Create item/capacity table.
  2. Carry forward skip value.
  3. Compare against taking the current item.

Longest Common Subsequence

Compares two strings in a 2D table and extends matching diagonals.

Open

O(n * m) time / O(n * m) space

2D DP
  1. Compare current characters.
  2. Extend diagonal on match.
  3. Keep max of top and left on mismatch.

Longest Increasing Subsequence

Maintains the smallest possible tail for every increasing subsequence length using binary search.

Open

O(n log n) time / O(n) space

DP with binary search
  1. Binary search tails.
  2. Replace the first tail greater or equal to value.
  3. Tail count is LIS length.

Arrays And Strings

Two Pointers Pair Sum

Moves opposite pointers over a sorted array to find a pair matching the target sum.

Open

O(n) time / O(1) space

Opposite ends
  1. Compare pair sum.
  2. Move left if too small.
  3. Move right if too large.

Sliding Window Max Sum

Maintains a fixed-size window sum by adding the entering value and removing the leaving value.

Open

O(n) time / O(1) space

Window expansion
  1. Add entering value.
  2. Update best sum.
  3. Remove leaving value.

Prefix Sum Range Query

Precomputes running totals so range sums can be answered by subtracting two prefix values.

Open

O(n) build + O(1) query / O(n) space

Range query
  1. Build prefix totals.
  2. Select left and right.
  3. Subtract prefix[left] from prefix[right + 1].

Kadane Algorithm

Keeps the best subarray ending at the current index and updates the global maximum when that running sum improves.

Open

O(n) time / O(1) space

Running optimum
  1. Compare extending with starting fresh.
  2. Update current subarray sum.
  3. Keep the best sum and range seen so far.

Matrix Traversal

Visits each matrix cell row by row and updates a running total while showing the active flattened cell.

Open

O(rows * cols) time / O(1) space

Grid movement
  1. Enter one row.
  2. Visit each column.
  3. Continue until every cell is processed.

Backtracking

Subsets

Builds every include/exclude decision path and records each subset at the leaf.

Open

O(2^n) time / O(n) space

Decision tree
  1. Include the current value.
  2. Explore deeper.
  3. Backtrack and exclude it.

Permutations

Chooses unused values into a path until one full ordering is formed.

Open

O(n!) time / O(n) space

Used set
  1. Skip used values.
  2. Choose one unused value.
  3. Undo the choice after exploring.

Combinations

Uses a start index so combinations grow without repeating earlier choices.

Open

O(C(n,k)) time / O(k) space

Start index
  1. Choose a value.
  2. Recurse from the next index.
  3. Backtrack to try the next choice.

N-Queens

Places one queen per row and rejects columns or diagonals already attacked.

Open

O(n!) time / O(n) space

Constraint pruning
  1. Try a square.
  2. Reject attacked positions.
  3. Place and later remove the queen.

Sudoku Solver

Fills empty cells by trying legal digits and backtracking when a later cell cannot be solved.

Open

O(4^empty) time / O(empty) space

Constraint search
  1. Find an empty cell.
  2. Try safe digits.
  3. Undo a digit when the branch fails.

Greedy

Activity Selection

Selects the activity that finishes earliest whenever it does not overlap the last selected activity.

Open

O(n log n) time / O(1) space

Interval sorting
  1. Sort by finish time.
  2. Accept compatible intervals.
  3. Reject overlaps.

Merge Intervals

Sorts intervals by start and merges each overlap into the current interval.

Open

O(n log n) time / O(n) space

Interval scan
  1. Sort by start.
  2. Start a new interval when separated.
  3. Extend the last interval when overlapping.

Jump Game

Keeps the farthest reachable index and succeeds once that reach covers the end.

Open

O(n) time / O(1) space

Reachability
  1. Scan reachable indexes.
  2. Update farthest reach.
  3. Stop when the end is covered.

Gas Station

Resets the candidate start whenever the running tank becomes negative.

Open

O(n) time / O(1) space

Running balance
  1. Track gas minus cost.
  2. Reset after a negative tank.
  3. Return the surviving start if total balance works.

Huffman Coding

Repeatedly merges the two lowest-frequency nodes to build an optimal prefix tree.

Open

O(n log n) time / O(n) space

Priority queue
  1. Pop two smallest nodes.
  2. Merge their weights.
  3. Push the merged node back.

Sorting

Ordering techniques with comparisons, swaps, partitions, and merge steps.

9 topics

Bubble Sort

ready

Swapping / Nested loops

Insertion Sort

ready

Sorted prefix / Shifting

Selection Sort

ready

Minimum selection

Merge Sort

ready

Divide and conquer / Merging

+ 5 more in this category

Searching

Finding values and boundaries across arrays, answer spaces, and rotated ranges.

5 topics

Linear Search

ready

Single scan

Binary Search

ready

Halving / Sorted array

Lower / Upper Bound

ready

Boundary search

Search in Rotated Array

ready

Modified binary search

+ 1 more in this category

Hashing

Constant-time lookup patterns using maps, sets, counters, and prefix signatures.

7 topics

Hash Insert

ready

Modulo hashing / Chaining

Hash Search

ready

Bucket lookup / Chain scan

Two Sum

ready

Hash map lookup

Frequency Counter

ready

Counting

+ 3 more in this category

Stacks And Queues

LIFO/FIFO structures for monotonic scans, parsing, windows, and scheduling.

7 topics

Stack Push / Pop / Peek

ready

LIFO / Top pointer

Queue Enqueue / Dequeue / Peek

ready

FIFO / Front and rear

Valid Parentheses

ready

Stack parsing

Next Greater Element

ready

Monotonic stack

+ 3 more in this category

Linked Lists

Pointer movement, reversal, cycle detection, and merge-style list workflows.

5 topics

Reverse Linked List

ready

Pointer rewiring

Middle of Linked List

ready

Fast and slow pointers

Detect Cycle

ready

Floyd cycle detection

Merge Two Sorted Lists

ready

Two pointers

+ 1 more in this category

Trees

Hierarchical traversals, search trees, recursion, and level-order state.

7 topics

BST Insert / Search

ready

Binary search tree

Inorder Traversal

ready

DFS

Preorder Traversal

ready

DFS

Postorder Traversal

ready

DFS

+ 3 more in this category

Graphs

Node and edge exploration with visited sets, shortest paths, and ordering.

6 topics

BFS

ready

Queue / Visited set

DFS

ready

Recursion / Stack

Dijkstra

ready

Priority queue

Topological Sort

ready

DAG ordering

+ 2 more in this category

Dynamic Programming

State transitions, memoization, tabulation grids, and optimized recurrence views.

6 topics

Fibonacci

ready

Memoization / Tabulation

Climbing Stairs

ready

1D DP

Coin Change

ready

Unbounded knapsack

0/1 Knapsack

ready

2D DP

+ 2 more in this category

Arrays And Strings

Core interview patterns around windows, prefixes, pointers, and in-place edits.

5 topics

Two Pointers

ready

Opposite ends / Same direction

Sliding Window

ready

Window expansion

Prefix Sum

ready

Range query

Kadane Algorithm

ready

Running optimum

+ 1 more in this category

Backtracking

Decision trees with choose, explore, unchoose steps and pruning signals.

5 topics

Subsets

ready

Decision tree

Permutations

ready

Used set

Combinations

ready

Start index

N-Queens

ready

Constraint pruning

+ 1 more in this category

Greedy

Local-choice strategies with sorted inputs, intervals, and exchange arguments.

5 topics

Activity Selection

ready

Interval sorting

Merge Intervals

ready

Interval scan

Jump Game

ready

Reachability

Gas Station

ready

Running balance

+ 1 more in this category