Certainly! Here’s an improved and polished version of the exam questions for a university course on algorithms and data structures. The improvements focus on clarity, balance of difficulty, coverage of key topics, and better scaffolding for multi-part questions. I also added some hints and refined wording to help students understand what is expected.
Algorithms and Data Structures — Final Exam
Instructions:
- Show all your work clearly to receive partial credit.
- Justify your answers where applicable.
- Time allowed: 3 hours.
- Closed book, one page of handwritten notes allowed.
Question 1: Sorting and Time Complexity (15 points)
Consider the following pseudocode:
function insertionSort(A[1...n])
for i = 2 to n
key = A[i]
j = i - 1
while j > 0 and A[j] > key
A[j + 1] = A[j]
j = j - 1
A[j + 1] = key
a) Identify the sorting algorithm implemented by this code. (2 points)
b) Analyze the worst-case time complexity of this algorithm. Provide a detailed explanation. (6 points)
c) Analyze the best-case time complexity and explain under what input conditions this occurs. (4 points)
d) Suggest one modification or alternative sorting algorithm that improves the worst-case time complexity and briefly explain why. (3 points)
Question 2: Binary Search Trees and AVL Trees (20 points)
a) Insert the following keys into an initially empty Binary Search Tree (BST) in the given order:
50, 30, 70, 20, 40, 60, 80, 10, 25, 35
Draw the resulting BST. (5 points)
b) Delete the node with key 30 from the BST you constructed. Show the resulting tree and explain the deletion strategy you used (e.g., predecessor, successor). (5 points)
c) What is the height of the BST after all insertions? Explain how the height relates to the number of nodes in the worst and average cases. (4 points)
d) Convert the BST into a balanced AVL tree by performing the necessary rotations after each insertion. Show the tree after each rotation step. (6 points)
Question 3: Graph Algorithms (25 points)
Given the weighted directed graph below:
| Edge | Weight |
|---|
| 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’s algorithm starting from vertex A. Show the shortest path estimates and predecessor for each vertex after each iteration. (10 points)
b) Run Bellman-Ford algorithm starting from vertex A. Show the distance estimates after each of the |V| - 1 iterations. (10 points)
c) Explain one scenario where Bellman-Ford is preferred over Dijkstra’s algorithm. Provide an example graph or edge case. (5 points)
Question 4: Dynamic Programming (20 points)
The "House Robber" problem: You are a robber planning to rob houses along a street. Each house has a certain amount of money. Adjacent houses have security systems connected, so you cannot rob two adjacent houses. Given an array nums of non-negative integers representing the amount of money in each house, determine the maximum amount you can rob.
a) Define the recurrence relation for this problem. Clearly explain what each term represents. (8 points)
b) Write clear pseudocode for a dynamic programming solution based on your recurrence. (7 points)
c) Analyze the time and space complexity of your solution. Suggest a way to optimize space usage if possible. (5 points)
Question 5: Hash Tables and Collision Resolution (20 points)
a) Compare and contrast separate chaining and open addressing as collision resolution techniques in hash tables. Discuss their advantages and disadvantages in terms of time complexity, memory usage, and implementation complexity. (8 points)
b) Given the hash function h(k) = k mod 13, insert the keys {18, 41, 22, 44, 59, 32, 31, 73} into a hash table of size 13 using:
- Separate chaining (show the resulting table with chains) (6 points)
- Linear probing (show the resulting table after all insertions) (6 points)
Question 6: Heaps and Priority Queues (15 points)
Starting with an empty min-heap, perform the following operations in order:
- Insert: 15, 10, 20, 8, 21, 23, 12
- Extract-min
- Insert: 5
- Extract-min
- Extract-min
For each operation:
- Draw the heap as a binary tree.
- Show the array representation of the heap.
(15 points)
Question 7: Algorithm Design — Selection Problem (15 points)
Design an efficient algorithm to find the k-th largest element in an unsorted array of n elements.
a) Describe your algorithm in detail, including any data structures used. (8 points)
b) Analyze the average-case and worst-case time complexity of your algorithm. (5 points)
c) Discuss the space complexity of your solution. (2 points)
Bonus Question: Graph Theory Proof (10 points)
Prove the following statements for any connected, undirected graph ( G = (V, E) ):
a) The number of edges satisfies ( |E| \geq |V| - 1 ). (5 points)
b) If ( |E| = |V| - 1 ), then ( G ) is a tree. (5 points)
End of Exam
Additional Notes on Improvements:
- Balanced coverage: The questions cover sorting, trees, graphs, dynamic programming, hashing, heaps, and algorithm design, reflecting a comprehensive course.
- Clear expectations: Each question explicitly states what is expected (e.g., show intermediate steps, explain reasoning).
- Scaffolding: Multi-part questions build logically, helping students organize their answers.
- Realistic complexity: The problems are challenging but fair for a 3-hour exam.
- Hints and clarifications: Where appropriate, hints or clarifications are embedded to guide students without giving away answers.
If you want, I can also generate a detailed marking rubric or sample solutions for these questions! Would you like that?