Course Overview
Data Structures with Python
A queue keeps waiting jobs in order. A heap chooses the next urgent job. A graph describes which places are connected, while a trie finds words that share a prefix. Each structure makes some operations convenient and others expensive. This course helps you see those trade-offs and implement the operations yourself.
You will work through 210 coding lessons. The explanations introduce the idea beside the editor, and the starter leaves the new behavior for you to write. Diagrams show the values, links, boundaries, and intermediate states that code alone can hide. Most exercises add one operation; later exercises combine the operations into a useful program.
Before you begin
You should be comfortable with Python functions, loops, lists, dictionaries, classes, constructors, instance methods, and basic exception handling. The object-oriented Python course is suitable preparation. You do not need prior knowledge of algorithms or complexity analysis.
Code uses type hints to describe expected inputs, outputs, and stored values. Early lessons explain the notation, and later lessons explain unfamiliar types where they appear. Type hints help you read a contract; they do not automatically validate values at runtime.
How practice works
Read the explanation and visual trace, then work through the short numbered tasks in main.py. Each task has its own check, so you can submit after a small change rather than finish the whole lesson at once. Run uses the supplied probe to show what your code does. Submit checks additional inputs and edge cases. Each lesson has a reference solution for comparison after you have tried your own approach.
The starter is intentionally incomplete but runnable. You do not need to copy code from a previous lesson: a continuing build includes the earlier completed operations. The next method is left unfinished. All examples use small in-memory inputs and run in the lesson workspace, without installation, external services, or a blocking keyboard prompt.
A quiz follows each section. These questions ask you to explain behavior and choose between structures, while coding tasks test whether your implementation works.
The route through the course
Start with object references, copying, and counting work. Learn recursion before using it to traverse a tree or divide a sorting problem. Arrays and prefix sums introduce index boundaries; linked lists replace those indices with explicit links.
Build singly linked, doubly linked, circular, and skip lists. Then use stacks, queues, ring buffers, and deques to manage order. Construct hash tables with collision handling before studying search and sort algorithms in detail.
Trees introduce recursive structure, and binary search trees make the cost of tree height visible. Heaps and priority queues support scheduling. Graphs then combine adjacency representations with breadth-first search, depth-first search, cycle detection, and shortest paths.
The later sections cover bit masks, sets, tries, Fenwick trees, segment trees, and disjoint-set union. Combinatorial search gives you practice managing choices, repetition, and backtracking. The final dispatch workbench brings several structures together in a scripted console application.
What the tests check
Tasks define behavior for cases such as empty structures, missing keys, duplicate values, boundary indices, and disconnected graphs. Tests use more than the visible example. When a lesson asks you to implement a specific algorithm, its checks may also inspect the requested technique or operation trace rather than accept a built-in shortcut.
Complexity claims describe a stated input model and implementation. You will distinguish worst-case, expected, and amortized costs, count auxiliary space, and see why a short Python expression is not automatically a constant-time operation. Small traces make these costs observable without unreliable stopwatch tests.
Syllabus
- Base and recursive cases
- Trace calls entering and leaving
- Recursive sum without slicing
- Iterative factorial and its invariant
- Recursive factorial and waiting frames
- Fibonacci as a branching call tree
- Memoize completed Fibonacci subproblems
- Iterative Fibonacci with two live values
- Tail recursion still uses stack frames
- Recursive binary search from sorted halves
- ✦Module Quiz
- Create a node and its link
- Walk a chain without changing it
- Give the list a consistent empty state
- Prepend without losing the old head
- Append through the tail reference
- Find the first matching node
- Insert after a known predecessor
- Remove and detach the head
- Find the predecessor before removing the tail
- Remove only the first matching value
- Reverse the links in place
- Play and consume the next recording
- ✦Module Quiz
- Store a backward link as well as a forward link
- Prepend and repair the reverse link
- Append with a link back to the old tail
- Remove a known node in both directions
- Start a new history branch after going back
- Close a circular list after append
- Traverse exactly one lap
- Remove a participant and keep the ring closed
- Represent skip-list towers with forward links
- Search top-down for every predecessor
- Check the successor after a skip search
- Insert one tower at its supplied height
- Remove a tower from every participating level
- Measure skip-list work without a stopwatch
- ✦Module Quiz
- Turn a key into a bucket index
- Keep colliding keys together
- Initialize a chained hash table
- Insert or update one key
- Look up a colliding key
- Delete from a collision bucket
- List the stored pairs
- Measure the load factor
- Rehash stored key/value pairs
- Search a linear-probing table
- Delete with a tombstone
- Build a frequency index
- ✦Module Quiz
- Represent isolated vertices with adjacency lists
- Add a vertex without erasing its neighbors
- Add both halves of an undirected edge
- Remove an edge without removing its vertices
- Remove a vertex and its incident edges
- Store directed edges in only one list
- Convert adjacency lists to a matrix
- Count incoming and outgoing edges
- ✦Module Quiz
- Discover neighbors before adding them to the BFS queue
- Process the BFS queue in layers
- Count the fewest edges with BFS
- Recover a shortest-hop path from parents
- Restart BFS to find undirected components
- Follow one branch with recursive DFS
- Simulate recursive DFS with iterator frames
- Ignore the parent edge in undirected cycle checks
- Distinguish active and finished vertices in directed DFS
- Schedule directed dependencies with topological order
- ✦Module Quiz
- Store directed edges with nonnegative integer costs
- Add the weights along a proposed path
- Relax one edge when it improves a distance
- Settle cheapest distances with scan-based Dijkstra
- Use a lazy min-heap for Dijkstra priorities
- Read a weighted shortest route from its parents
- Keep zero-cost routes distinct from unreachable targets
- Build a route planner that reuses one weighted search
- ✦Module Quiz
- Find the lowest set bit
- Allocate one-based Fenwick storage
- Propagate a Fenwick point addition
- Sum a Fenwick prefix
- Subtract prefixes for a range sum
- Build a Fenwick tree from values
- Lay out a padded segment tree
- Build parent summaries from the leaves
- Query a half-open segment interval
- Replace a value and repair its ancestors
- Use minimum as the segment summary
- Report changing ranges
- ✦Module Quiz