Here's the enhanced exam with warm-up questions and more mathematical challenges:
Algorithms & Data Structures Final Exam
Total: 100 points
Time: 3 hours
Section A: Warm-Up Questions (15 points)
These questions help you get started and build confidence.
1. Basic Concepts (8 points)
a) What is the time complexity of accessing the i-th element in:
- An array: _____ (1 point)
- A singly linked list: _____ (1 point)
- A balanced BST: _____ (1 point)
b) True/False with brief justification (2 points each):
- A complete binary tree with n nodes has height ⌊log₂ n⌋
- Every AVL tree is a Red-Black tree
- BFS can be implemented using a stack
c) Write the result of an in-order traversal of this BST: (1 point)
5
/ \
3 8
/ \ \
1 4 9
2. Simple Complexity (7 points)
a) Rank these functions by growth rate (smallest to largest): (3 points)
n², 2ⁿ, n log n, n!, √n, n³
b) Simplify: O(n² + 5n log n + 100n) = _____ (2 points)
c) If an algorithm takes 1 second for n=1000, how long for n=10,000 if it's O(n²)? (2 points)
Section B: Core Questions (70 points)
3. Algorithm Analysis & Mathematics (15 points)
a) Solve the recurrence using substitution method: (7 points)
T(n) = 3T(n/3) + n
T(1) = 1
Prove your answer using mathematical induction.
b) Given f(n) = n^(log₄ n), prove or disprove: (8 points)
- f(n) = O(n²)
- f(n) = Ω(n^1.5)
Use limits and L'Hôpital's rule if needed.
4. Data Structure Design (12 points)
Design an efficient data structure for a ride-sharing app that supports:
insert(driverID, rating)
get_worst_driver()
update_rating(driverID, newRating)
a) Specify your ADT and invariants. (3 points)
b) Justify choice of underlying structures with complexity analysis. (5 points)
c) Pseudocode for update_rating. (4 points)
5. Graph Theory & Algorithms (15 points)
Graph: Cities A-F connected by roads with travel times:
A-B(4), A-C(2), B-C(1), B-D(5), C-D(8), C-E(10), D-E(2), D-F(6), E-F(3)
a) Run Dijkstra from A. Show priority queue at each step. (6 points)
b) Prove that in any MST of this graph, edge C-E cannot be included. (4 points)
c) How many distinct shortest paths exist from A to F? Justify. (5 points)
6. Dynamic Programming (13 points)
Problem: Maximize profit from stock prices [p₁, p₂, ..., pₙ] with at most two transactions.
a) Define recurrence relation. Let buy₁[i], sell₁[i], buy₂[i], sell₂[i] represent states. (5 points)
b) Prove optimal substructure property formally. (4 points)
c) Apply to [3, 5, 1, 4, 6, 2]. Show state transitions. (4 points)
7. Advanced Trees & Probability (15 points)
a) Insert [25, 30, 20, 28, 23, 10] into an AVL tree. Show rotations. (5 points)
b) Mathematical Challenge: In a randomly built BST with n distinct keys: (10 points)
- Prove the expected height is O(log n)
- Calculate the exact probability that a tree with 3 nodes forms a chain
- What is E[number of leaves] in terms of n?
Section C: Advanced Problems (15 points)
8. Amortized Analysis (7 points)
Consider a dynamic array that doubles in size when full.
a) Prove that n insertions take O(n) total time using the accounting method. (4 points)
b) What is the amortized cost per operation? Show your calculation. (3 points)
9. Number Theory in Hashing (8 points)
a) Prove that if m = 2ᵏ and h(k) = k mod m, then h only uses the k lowest-order bits. (3 points)
b) Why is choosing m as a prime number beneficial? Provide mathematical justification. (3 points)
c) Design a hash function for strings that minimizes collisions. Analyze its properties. (2 points)
Bonus: Theoretical Computer Science (10 points)
B1. Lower Bounds (5 points)
Using an adversary argument, prove that finding the minimum and maximum of n elements requires at least ⌈3n/2⌉ - 2 comparisons.
B2. Graph Isomorphism (5 points)
Given two graphs G₁ and G₂ with n vertices each:
a) Prove that if G₁ and G₂ are isomorphic, they must have the same degree sequence. (2 points)
b) Give a counterexample showing the converse is false. (1 point)
c) Describe a polynomial-time algorithm for trees. (2 points)
Key Enhancements:
-
Gentle Start: Section A provides confidence-building warm-up questions covering basic concepts and simple calculations.
-
Mathematical Rigor:
- Induction proof for recurrence (Q3a)
- Limits and growth rate analysis (Q3b)
- Probability in BSTs (Q7b)
- Number theory in hashing (Q9)
- Adversary arguments (B1)
-
Progressive Difficulty:
- Section A: Basic recall and application
- Section B: Core algorithmic concepts
- Section C: Advanced mathematical analysis
- Bonus: Research-level thinking
-
Varied Mathematical Topics:
- Discrete mathematics (counting paths)
- Probability theory (random BSTs)
- Number theory (hash functions)
- Proof techniques (induction, contradiction, adversary)
-
Time Management:
- Quick wins in Section A (15 min suggested)
- Core work in Section B (90 min suggested)
- Challenge yourself in Section C (45 min suggested)
- Bonus if time permits (30 min suggested)