Data Structures and Algorithms Concepts: No Coding Needed
How stacks, trees, hash tables, sorting and graphs really work, step by step, with pictures. Each post below stands on its own and is free to read, in the order the course teaches it.
Start with step 1: What a Data Structure Is, and How Memory WorksPosts in course order
- Step 1: What a Data Structure Is, and How Memory Works
Memory is a long row of numbered boxes, and opening any box is equally quick. A data structure is an agreed way of arranging things in those boxes, plus a few small notes. See with six songs on a phone why every structure is quick at some things and slow at others.
- Step 2: Big-O: Reading Cost From Code, With Handshakes and a Guest Book
Big-O asks one question: how do the steps grow when the list grows? Check a school trip sheet for duplicates two ways, handshakes and a guest book, count every step in Python, then grow the list to ten thousand ids and watch 10,000 steps turn into almost 50 million.
- Step 3: Arrays and Dynamic Arrays: Full? Get a Box Twice the Size
A fixed array never gets longer. A dynamic array fills its box, then copies everything into a box twice the size. Build one for Emma's playlist in Python, count the copies and shifts, and see why adding at the end stays cheap while inserting at the front costs almost 50 million shifts for 10,000 songs.
- Step 4: Linked Lists: A Chain of Clues, Built in Python
In a linked list every node holds a value and the address of the next node. Build a treasure hunt chain in Python: a new first clue is two moves at any size, slipping a clue in or out is just changing next, but reaching clue number i is a walk of i hops.
- Step 5: Stacks: Last In, First Out, With the Undo Button
A stack is last in, first out: the newest thing you put on is the first thing you take off. Build Emma's undo button in Python from a list and one top index, push, pop and peek in one step each, undo after a million edits, and see what happens when you pop an empty stack.
- Step 6: Queues: First In, First Out, With a Ring of Cells
A queue is first in, first out: whoever joins the line first is served first. Build Kate's cinema ticket line in Python as a ring of four cells, where nobody steps forward and only head and tail move, serve a million people with the same four cells, then break it with a line that is already full.
- Step 7: Hash Tables: The Name Tells You Where to Look
A hash table turns a name into a bucket number, so you jump straight to the right place. Build Emma's phone book in Python with 26 letter tabs, watch Jack and Jane collide on tab 9, see why piling names onto one tab is the slow case, and meet Python's dict, which does it properly.
- Step 8: Recursion: Russian Dolls, the Base Case and the Call Stack
Recursion means doing the same job on a smaller piece of the problem, and stopping at a base case. Count Emma's Russian dolls with a Python function that calls itself, watch each call wait on the call stack so the answers come back in reverse, then take the base case out and meet RecursionError.
- Step 9: Binary Search Trees: Smaller Left, Bigger Right, Half Gone at Every Look
Emma's seven number cards stored as a binary search tree: smaller goes left, bigger goes right, so 60 is found in 3 looks instead of 6. Insert and search step by step, a million cards answered in 15 looks, and the sorted input that turns the tree into a stick.
- Step 10: Tree Traversals: In-Order, Pre-Order and Post-Order as a Tour of the House
A traversal is a tour that visits every node once. Left side, this room, right side gives Emma's seven cards sorted, 20 to 80. Pre-order and post-order just move the moment you print, and one missing None check crashes the tour.
- Step 11: Heaps and Priority Queues: Most Urgent First, Without Searching the Room
A hospital waiting room where urgency 1 goes first. King of the hill shows how a min-heap works, a row of seats shows how it lives in an array, then add climbs up, poll sinks down, and Python's heapq does it for you.
- Step 12: Linear vs Binary Search: Page by Page, or Open in the Middle
Is kite a real word? Page by page takes 11 checks; opening in the middle takes 4. Trace binary search step by step, see a million words answered in 20 checks, and watch it give the wrong answer on an unsorted list.
- Step 13: Insertion Sort: Take the Next Card and Slide It Left Until It Fits
Emma's hand 7, 3, 9, 2, 5 sorted one card at a time in 6 shifts. Trace each card, see why a backwards hand costs the most, why 5,000 shuffled cards need over 6 million shifts, and why a sorted hand needs zero.
- Step 14: Merge Sort: Split the Pile, Then Merge Two Sorted Piles
Ms Kate's eight exam papers sorted in 24 steps: split in half until each pile is one paper, then merge sorted piles by taking the lower top. A million papers take about 20 million steps, and the price is extra room.
- Step 15: Quick Sort: Line Up Around One Friend, Then Repeat on Each Side
Seven kids line up for the class photo. Tom steps out, shorter kids go left, taller go right, and Tom's spot is final. Ten compares for seven kids, about 24 million for a million, and 124,750 for 500 kids already in order.
- Step 16: Graphs and Breadth-First Search (BFS): Fewest Hops, Level by Level
A graph is people plus friendships. Breadth-first search spreads from one person like ripples in a pond, using a queue, and gives the fewest hops to everyone. Emma's friend network, step by step, then a million users with the same code.
- Step 17: Depth-First Search (DFS): Go Deep, Back Up, Mark Where You've Been
Depth-first search walks a graph like a maze: follow one corridor as far as it goes, step back at a dead end, and chalk a tick in every room. Emma's friend network step by step, the recursive Python walk, and why a row of ten thousand people crashes it.
- Step 18: The Two Pointers Technique: Find a Pair in One Pass Instead of Every Pair
Emma wants two gifts that add up to her 36 dollar card. Trying every pair takes 20 checks; two pointers, walking in from both ends of the sorted prices, takes 6. Why it's safe, how it scales to 10,000 gifts, and how an unsorted list breaks it.
- Step 19: The Sliding Window Technique: One In, One Out
Emma wants her best three days in a row at the lemonade stand. Instead of adding every group of days again, a sliding window adds the day that comes in and takes away the day that leaves: two steps per slide, however wide the window.
- Step 20: Greedy Algorithms: The Best-Looking Choice, Right Now
Kate owes Tom 28 cents from a till of 10, 5, 2 and 1. Like any cashier she grabs the biggest coin that fits, again and again: that's a greedy algorithm. Fast and right for normal coins, but with coins of 4, 3 and 1 it hands out three coins where two would do.
- Step 21: Dynamic Programming: Work It Out Once, Write It Down, Read It Back
How many ways can Emma climb five stairs, one or two at a time? Plain recursion asks the same small questions again and again; a memo works each one out once. For 30 stairs that is 1,664,079 calls against 57.
