Algorithm Design and Analysis (H) Final Exam Paper
Published:
This final exam paper has been reconstructed from memory, and as a result, some details may be missing. I hope it serves as a useful reference and aid for future students.
Problem 1: Greedy
You have suspicious transactions, each occurring at time with an error tolerance . A new account also has transactions occurring at times . The -th transaction from the new account can be linked to the -th transaction from the old account if the time difference is within the error tolerance, i.e., . Each transaction can only be linked once.
Design an algorithm to determine if all transactions from the old account can be linked to transactions from the new account. An time complexity is acceptable. Explain why your algorithm is correct.
Problem 2: Divide and Conquer
A node in a complete binary tree is considered a local minimum if its value is less than or equal to the values of all its neighbors (not just its children).
Design an algorithm to find a local minimum in a complete binary tree with time complexity, starting from the root node ( is the number of nodes in the tree). You only know the value of a node when you visit it. Explain why your algorithm is correct.
Problem 3: Dynamic Programming
As the manager of a computer shop, you can buy new computers at a fixed price at the start of each month (no matter how many computers you buy, the price will always be ). Each month , computers will be sold immediately. Unsold computers are stored in a warehouse with capacity and a monthly storage fee per computer. Given the number of computers sold over months, design an algorithm to minimize the total cost of buying and storing computers. The time complexity of your algorithm should be a polynomial in and .
Problem 4: Polynomial Time Reduction
Two algorithms are defined as follows:
- •
VERTEX-COVER: Determines in polynomial time if a graph has a vertex cover of size .
- •
FIND-VERTEX-COVER: Finds a vertex cover of size for a graph in polynomial time.
Prove that VERTEX-COVER and FIND-VERTEX-COVER are polynomial-time equivalent, i.e., VERTEX-COVER FIND-VERTEX-COVER.
Problem 5: Network Flow
You have a computer with operating system A and software programs. A new operating system B is installed on the same computer. Transplanting software from A to B gives a performance improvement of . Some software program pairs and work closely together: if only one of them is transplanted, there’s a performance degradation of . Software 1 cannot be transplanted to B.
Design an algorithm to maximize the net performance improvement after transplanting the software programs. Explain the correctness of your algorithm (excluding the network flow algorithm’s correctness).
Problem 6: Randomized Algorithm
To find a four-coloring of a graph , an edge is considered satisfied if its two endpoints have different colors. Design a randomized algorithm to color such that at least of the edges are satisfied. Explain why your algorithm is correct.
Solutions
The solutions are from myself and may not be the best solutions.
Problem 1: Greedy
Initialize an empty bipartite graph with vertices on each side. If the -th transaction from the new account can be linked to the -th transaction from the old account, add an edge between the -th on the left side and the -th on the right side. Run the extended Gale-Shapley algorithm to find a maximum matching. If the matching is perfect, all transactions can be linked.
Problem 2: Divide and Conquer
To achieve time complexity, obviously we go through the tree in a binary search manner.
Problem 3: Dynamic Programming
Let be the minimum cost of buying and storing computers for the first months with computers in the warehouse. The recurrence relation is as follows:
Problem 4: Polynomial Time Reduction
Omitted since it’s presented in the lecture slides.
Problem 5: Network Flow
Similar to image segmentation problem, we can construct a graph with nodes representing the software programs and extra nodes and . For each software program , add an edge from to with capacity and an edge from to with capacity . For each software program pair and , add edges from to and from to with capacity . Run a maximum flow algorithm to find the maximum net performance improvement.
Problem 6: Randomized Algorithm
Same as the -approximation algorithm for SAT, which is presented in the lecture slides.