Data Structures & Algorithms

The Logic Ledger

Interactive visualizations, code in three languages, complexity breakdowns. Built for engineers who want to see it, not just read about it.

Featured

O(n²)

Bubble Sort

Repeatedly walks through the array, compares adjacent elements, and swaps them. Each pass bubbles the largest unsorted element to its final position.

Open visualizer

Time Complexity

010203040 010203040 elements (n) operations
O(1)
O(log n)
O(n)
O(n log n)
O(n²)
O(2ⁿ)

Sorting

6 algorithms

Bubble Sort

Repeatedly swaps adjacent elements. Simple but slow. Good for learning.

O(n²) O(1) Stable

Selection Sort

Soon

Finds the minimum element each pass and places it at the front.

O(n²) O(1) Unstable

Insertion Sort

Soon

Builds sorted array one element at a time. Great for small or nearly sorted data.

O(n²) O(1) Stable

Merge Sort

Soon

Divide and conquer. Splits, sorts halves, merges back. Guaranteed fast.

O(n log n) O(n) Stable

Quick Sort

Soon

Picks a pivot, partitions around it. Fastest in practice. *O(n²) worst case.

O(n log n)* O(log n) Unstable

Heap Sort

Soon

Builds a max-heap, extracts elements one by one. In-place, guaranteed O(n log n).

O(n log n) O(1) Unstable

Searching

4 algorithms

Linear Search

O(n) Soon

Check every element until found. Works on unsorted data.

Binary Search

O(log n) Soon

Requires sorted data. Halves the search space each step.

Depth-First Search

O(V+E) Soon

Goes deep before going wide. Uses stack or recursion.

Breadth-First Search

O(V+E) Soon

Explores level by level. Finds shortest path in unweighted graphs.

Trees

5 structures

Binary Tree

O(n) Soon

Each node has at most two children. Foundation for BST, heaps, and more.

AVL Tree

O(log n) Soon

Self-balancing BST. Guarantees O(log n) by keeping height difference at most 1.

Red-Black Tree

O(log n) Soon

Self-balancing BST used in most standard library maps. Less strict than AVL.

B-Tree

O(log n) Soon

Multi-way tree optimized for disk access. Used in databases and filesystems.

Trie

O(k) Soon

Prefix tree. Fast string lookups. Used in autocomplete and spell checkers.

Graph Algorithms

5 algorithms

Dijkstra's

O(V² / V+E log V) Soon

Shortest path from one source. Non-negative weights only.

A*

O(E) Soon

Dijkstra's with a heuristic. Faster in practice for pathfinding.

Kruskal's

O(E log E) Soon

Minimum spanning tree. Sort edges, add smallest that doesn't form a cycle.

Prim's

O(V²) Soon

Minimum spanning tree. Grow tree from a vertex, always add cheapest edge.

Topological Sort

O(V+E) Soon

Linear ordering of DAG vertices. Used for build systems and task scheduling.

Dynamic Programming

4 problems

Fibonacci

O(n) Soon

Classic DP intro. Memoize overlapping subproblems.

Knapsack

O(nW) Soon

Maximize value within weight limit. 0/1 and unbounded variants.

Longest Common Subsequence

O(nm) Soon

Find longest shared subsequence between two strings. Used in diffs.

Coin Change

O(nS) Soon

Minimum coins to make a target sum. Classic bottom-up DP.

Data Structures

Structure Access Search Insert Delete
Array O(1) O(n) O(n) O(n)
Linked List O(n) O(n) O(1) O(1)
Stack O(n) O(n) O(1) O(1)
Queue O(n) O(n) O(1) O(1)
Hash Table N/A O(1)* O(1)* O(1)*
BST O(log n) O(log n) O(log n) O(log n)
Heap O(1) O(n) O(log n) O(log n)
Graph N/A O(V+E) O(1) O(V+E)

Share this site

QR Code for cardasac.com

cardasac.com

Scan with your phone camera