Data Structures final exam review
The topics, worked on a live board with an AI tutor.
Units
Analysis of algorithms
Practice
How many steps does sum_list take on a list of 6 numbers?Answer
Find c and n₀ that show 2n + 10 is O(n).Answer
c = 3 and n₀ = 10, since 2n + 10 ≤ 3n means n ≥ 10
Hint: Choose c = 3 and solve for n
Big-O, Big-Omega and Big-ThetaLinked lists
Practice
Build, in the same way, the chain 2, 7 with head referring to the node holding 2. Which Node calls do you write?Answer
Starting from 2 → 4 → 9 → None, run insert_after on the node holding 9 with x = 1. What is the list, and what is the next of the new node?Answer
2 → 4 → 9 → 1 → None; the next of the new node is None
Hint: Line 3 copies the next of the node 9
Linked list insertion and deletionStacks and queues
Practice
A stack gets push(6), push(1), push(4), then pop(), then push(5). What does peek return, and what is the whole stack from bottom to top?Answer
A queue gets enqueue(p), enqueue(q), dequeue(), enqueue(r), dequeue(). What does the second dequeue return, and what is left in the queue?Answer
Recursion
What exams ask
Search problems such as filling a sudoku, finding a route that visits every town or checking every way to schedule exams are solved by trying a choice, going on, and undoing it when it fails, and the same pattern also shows when a search is too big to finish.
Practice
For the list 5, 1, what does total return, how many calls are made, and how deep does the stack get?Answer
The same search on a list of 32 numbers. Using the recurrence, what are T(32) and the sizes of what is left after each probe?Answer
T(32) = 6; the sizes go 32, 16, 8, 4, 2, 1
Hint: Build up from T(1) = 1 by adding 1
Recurrences and divide and conquerSorting
Practice
Selection sort on 4, 7, 1, 9, 3. What is the list after the first two passes, and how many comparisons in all?Answer
1, 3, 4, 9, 7; 10 comparisons
Hint: Pass 0 swaps the 4 and the 1, and the total is 4 + 3 + 2 + 1
Selection and insertion sortMerge 2, 9, 10 with 4, 5, 11, 12. What is the output, and how many comparisons were made?Answer
2, 4, 5, 9, 10, 11, 12; 5 comparisons
Hint: After the 10 is taken the first list is empty, and the rest is copied
Merge sortTrees
- Trees and binary trees
- Tree traversals
- Binary search trees: search and insert
- Binary search trees: deletion
- Balanced trees: AVL rotations
Practice
In the same tree, what are the depth and the height of the node 14?Answer
Depth 2 and height 1
Hint: 14 is below 10, which is below 8, and 13 is one line below 14
Trees and binary treesWhat is the preorder of the tree with root 6, whose left child 3 has the children 2 and 5, and whose right child is 8?Answer
Heaps and priority queues
Practice
In the array 2, 5, 3, 8, 6, 4, 9, which indices are the children of index 1, and which index is the parent of index 6?Answer
The children are at 3 and 4, holding 8 and 6, and the parent of index 6 is at 2, holding 3
Hint: 2i + 1, 2i + 2 and (i − 1)//2
Binary heaps and insertionPop from the min-heap 1, 3, 2, 7, 4. What does the pop return, and what is the array afterwards?Answer
1, and the array is 2, 3, 4, 7
Hint: 4 goes to the root and swaps with the smaller child, 2
Removing the minimumHash tables
What exams ask
Hash tables give Python's dict and set, database indexes and caches their average constant-time lookups, and choosing a hash and a table size that spread keys evenly is what keeps them fast; computing bucket indexes by hand is a standard exam question.
Separate chaining is the simplest working hash table and the model behind Java's HashMap; the load factor argument, a successful search about 1 + α/2 and a failed one about α, and doubling to keep α bounded are what exams and interviews ask when they ask why hash tables are O(1).
Practice
With m = 7, place 14, 21 and 9. Which of them collide?Answer
14 % 7 = 0 and 21 % 7 = 0 collide in bucket 0; 9 goes to bucket 2
Hint: Multiples of 7 give 0
Hash functions and hash tablesSuppose the table never grew. Insert 15 and 20 into the table above. Which chain do they join, and what does a search for 20 cost?Answer
Bucket 0, making the chain 25, 40, 15, 20; a search for 20 takes 4 comparisons
Hint: Both are multiples of 5
Collisions: separate chainingGraphs
What exams ask
BFS finds the fewest hops in an unweighted network, such as degrees of separation, the fewest moves in a puzzle or the shortest route in a grid maze, and it is the skeleton of many graph algorithms; tracing its queue is a standard exam question.
DFS is the other basic graph walk; it explores mazes, finds what is reachable, splits a network into connected pieces, detects cycles such as circular dependencies, and underlies topological sort, all in O(V + E); tracing its order is a staple exam question next to BFS.
- Graphs and their representations
- Breadth-first search
- Depth-first search
- Topological sort
- Shortest paths: Dijkstra's algorithm
Practice
A graph has degrees 1, 2, 2, 3 and 4. How many edges does it have?Answer
Run BFS from F. What are the distances of E, C and A?Answer
Questions
What does the Data Structures review cover?
Every unit of the course, 9 in all. Pick one and Helio teaches it on the board, then asks you questions. Analysis of algorithms; Linked lists; Stacks and queues; Recursion; Sorting; Trees; Heaps and priority queues; Hash tables; Graphs.
Can it help the week before my final?
Yes. Pick a topic, and Helio explains it, checks you and goes over what you miss.
Is it the same as my class?
It follows the usual topics of Data Structures. For anything else on your syllabus, type the topic and Helio teaches that too.
How much is free?
30 minutes a month for one learner, with no card. Starter is free for 7 days with a card: cancel in time and pay nothing.



