Data Structures & Algorithms
Learn to code and to think: from your first loop to segment trees and dynamic programming, with every algorithm animated.
56 lessons, 37 of them free.
Getting Started: First Steps
- Coding from Zero: Write and read your very first Python: print, variables, numbers vs text, if/else, loops, a tiny function, and how to read an error message without panic.
- Think Like a Programmer: Variables, loops and a 5-step recipe to solve ANY coding problem.
- Python Crash Course for DSA: Learn the slice of Python you need for interviews: types, the four containers, slicing, loops, comprehensions, functions, and the 'two names, one list' trap.
- Functions, Lists & Strings: Reusable recipes (functions) and the two data types you'll use in every interview.
- Classes & Objects: Write your own classes: __init__, self, methods, encapsulation and inheritance, and understand the abstract data type idea behind every 'design a ...' interview question.
- Big-O: How Fast Is My Code?: Measure code speed by counting steps as the input grows.
- Recursion: A function that calls itself on a smaller version of the problem.
Part 1 · Data Structures: Arrays & Strings
- Arrays, Memory & Dynamic Arrays: Understand what an array really is in memory: why a[i] is instant, why inserting in the middle is slow, and how a growing list stays fast by doubling its capacity.
- Strings, Characters & Anagrams: Treat strings like arrays of characters: count letters with a frequency map, spot anagrams and palindromes, and build strings without hidden O(n²) costs.
- 2D Grids & Matrix Traversal: Move around a grid with confidence: row/column indexing, neighbours with a direction array, spiral order with four shrinking walls, rotation, and flood fill.
Part 1 · Data Structures: Linked Lists, Stacks & Queues
- Linked Lists: A chain of nodes where each one points to the next.
- Stacks & Queues: Last-in-first-out vs first-in-first-out, and when each saves you.
- Deques & Monotonic Stacks: Use a deque and a monotonic stack to answer 'next greater' and 'maximum of every window' questions in a single O(n) pass.
Part 1 · Data Structures: Hash Maps & Sets
- Hash Maps (Dictionaries): The most useful interview tool: instant lookup by key.
- Inside a Hash Table: Open up dict and set: how a hash function picks a slot, what happens on a collision (chaining vs linear probing), and why the table resizes when the load factor gets high.
Part 1 · Data Structures: Trees & Heaps
- Trees, DFS & BFS: Hierarchies like family trees and folders, and two ways to explore them.
- Binary Search Trees: Search, insert and delete in a binary search tree, get sorted order from an inorder walk, and validate a BST with min/max bounds.
- Balanced Trees: AVL & Red-Black: See why a plain BST can collapse into a list, measure balance with heights, repair it with AVL rotations (LL, RR, LR, RL), and know why red-black trees power TreeMap and std::map.
- Heaps & Priority Queues: Always grab the smallest (or biggest) item fast: top-k, scheduling, Dijkstra.
- Tries (Prefix Trees): The data structure behind autocomplete and spell-check.
Part 1 · Data Structures: Graphs & Disjoint Sets
- Graphs & Grids: Cities connected by roads: explore them with BFS/DFS.
- Union-Find (Disjoint Sets) (Pro): Track groups that merge: friend circles, network connections, Kruskal's MST.
Part 1 · Data Structures: Advanced Structures
- Segment Trees & Fenwick Trees (Pro): Answer range-sum (or min / max) queries while values keep changing, both in O(log n), with a segment tree and with the tiny Fenwick tree built on lowbit.
- B-Trees & Skip Lists: How Databases Index (Pro): Understand why databases index with wide B-trees and B+trees (disk pages), how inserts split nodes, and how skip lists give O(log n) search with coin flips, as in Redis sorted sets.
Part 2 · Algorithms: Array Techniques
- Arrays & Two Pointers: Walk from both ends of a list at once to solve problems in one pass.
- Fast & Slow Pointers: Detect a loop, find the middle and find where a loop begins in a linked list with two pointers and O(1) extra memory.
- Sliding Window: Look at a moving 'window' of the data instead of re-checking everything.
- Prefix Sums: Pre-compute running totals once, answer any range-sum question instantly.
Part 2 · Algorithms: Searching & Sorting
- Binary Search: Find anything in a sorted list by cutting it in half again and again.
- Sorting: Bubble, Merge & Quick: Put things in order, and learn divide & conquer on the way.
- Beyond Comparison Sorts: Know why comparison sorts are stuck at O(n log n), beat it with counting and radix sort, keep sorts stable, and find the k-th largest in O(n) average with quickselect.
Part 2 · Algorithms: Backtracking
- Backtracking: Explore every choice, undo, try the next: subsets, permutations, puzzles.
Part 2 · Algorithms: Graph Algorithms
- Topological Sort & DAGs: Put tasks in an order where every prerequisite comes first, and spot impossible (cyclic) plans, using Kahn's algorithm or DFS.
- Shortest Paths (Dijkstra): How Google Maps finds the fastest route when roads have different lengths.
- Minimum Spanning Trees: Connect every node at the lowest total cost with two greedy algorithms: Kruskal (sort edges + union-find) and Prim (grow a tree with a heap).
Part 2 · Algorithms: Greedy & Dynamic Programming
- Greedy & Intervals: Make the best local choice each step, and master meeting-room style problems.
- Dynamic Programming: Remember answers to small problems so you never solve them twice.
- 2D Dynamic Programming: Solve grid and two-string problems (unique paths, minimum path sum, LCS, edit distance) by defining dp[i][j] in one sentence and filling a table.
- Knapsack, Subset Sum & Coin Change (Pro): Master the take-or-skip decision behind 0/1 knapsack, subset sum and coin change, tell 0/1 from unbounded, and shrink the table to a single row.
Part 2 · Algorithms: Strings, Bits & Patterns
- Bit Manipulation: Read numbers as rows of switches and use AND, OR, XOR, NOT and shifts to test, set and clear bits, count ones with x & (x - 1), find the single number with XOR, and list subsets with bitmasks.
- Pattern Matching: KMP & Rabin-Karp: Find every place a pattern appears in a text in linear time, using KMP's border table (LPS) or Rabin-Karp's rolling hash.
- Which Pattern When? The Interview Pattern Map (Pro): Read a problem, spot its signal words and constraints, map them to the right technique, and walk from brute force to the optimal solution.
Part 3 · Advanced: Advanced Graphs
- Bellman-Ford & Floyd-Warshall (Pro): Find shortest paths when some edges are negative, catch negative cycles, and get the distance between every pair of nodes at once.
- 0-1 BFS & Multi-Source BFS (Pro): Find cheapest paths when every move costs 0 or 1 using a deque instead of a heap, and run one search from many starting points at once.
- Strongly Connected Components (Pro): Split a directed graph into groups where everyone can reach everyone (Kosaraju or Tarjan, both O(V + E)), then shrink each group to a dot to get a DAG.
- Bridges & Articulation Points (Pro): Find every road (bridge) and every town (articulation point) whose loss splits a network, in a single DFS using discovery times and low-links.
- Max Flow, Min Cut & Bipartite Matching (Pro): Push the most "stuff" through a network of limited pipes with Edmonds-Karp, read the bottleneck off as a minimum cut, and solve matching problems by turning them into flow.
Part 3 · Advanced: Advanced Trees & Queries
- LCA & Binary Lifting (Pro): Find the lowest common ancestor of two tree nodes in O(log n) per query with a jump table, and reuse the same table for k-th ancestors and distances.
- Sparse Tables: O(1) Range Minimum (Pro): Precompute the minimum of every power-of-two block in O(n log n), then answer any range minimum (or maximum, or gcd) query in O(1) with two overlapping blocks.
- Offline Queries & Mo's Algorithm (Pro): When every query is known up front, answer them in a clever order: Mo's algorithm slides one window across the array so range questions like 'how many distinct values?' cost O((n + q)·√n) in total.
Part 3 · Advanced: Advanced Dynamic Programming
- Bitmask DP: DP Over Subsets (Pro): Store a set of up to about 20 items in one integer, run DP over all 2^n sets (assignment, travelling salesman), and loop over the submasks of a mask.
- Interval DP: Ranges, Splits and the Last Move (Pro): Solve problems on a row by computing dp[i][j] for every range, filling shorter ranges first, and pick the right split: a cut point k or the item handled last (burst balloons, matrix chain, merging piles).
- Tree DP: Answers That Flow Up (Pro): Solve a tree problem by letting every node combine its children's answers in post-order: return a pair when one number is not enough (house robber III), keep the returned value apart from the recorded answer (max path sum), and reroot to answer for every node.
- Digit DP: Counting Numbers Up to N (Pro): Count the numbers up to N (or in a range) that have a digit property by building them digit by digit, tracking whether you are still "tight" against N, and memoising (position, state, tight).
Part 3 · Advanced: Advanced Strings
- Z-Function & Manacher's Algorithm (Pro): Reuse what you already matched: the Z-function finds pattern matches and repeats in O(n), and Manacher's algorithm finds the longest palindromic substring in O(n).
- Rolling Hash & Suffix Arrays (Pro): Compare any two substrings in O(1) with prefix hashes (and know when collisions bite), then sort every suffix into a suffix array with an LCP array to find the longest repeated substring.