The Lumenary · Early undergraduate
Algorithm design and analysis
Name: ______________________
Date: ______________________
You will learn to
- Design divide-and-conquer algorithms and analyse them with recurrences, proving that mergesort is correct and makes at most comparisons
- Prove that every comparison sort needs at least comparisons in the worst case
- Prove the correctness of greedy algorithms by exchange arguments — Kruskal's algorithm via the cut property, and Dijkstra's algorithm when all edge weights are non-negative — and recognise when greedy choice fails
- Design dynamic-programming algorithms from an optimal-substructure recurrence, as for the longest common subsequence, and analyse their cost
- Use breadth-first search for unweighted distances and choose an appropriate algorithm for a graph problem
- 1.
Two sorted lists have lengths and . What is the largest number of comparisons the merging procedure can need to merge them?
- 2.
What is the decision-tree lower bound on the worst-case number of comparisons needed to sort distinct items?
- 3.
Mergesort's worst-case comparison count satisfies and for a power of two. Compute .
- 4.
The network of towns in the Explore section has these cable costs: , , , , , , . Run Kruskal's algorithm. What is the total cost of the minimum spanning tree?
- 5.
Run Dijkstra's algorithm from on the directed graph with edges (weight ), (weight ) and (weight ). What does it report for ?
- A. — which is wrong, since the path has weight .
- B., the correct distance.
- C.
- D.It detects the negative edge and stops with an error.
- 6.
In the proof of Theorem 5 (Dijkstra), which step uses the hypothesis that all edge weights are non-negative?
- A., because lies on a shortest path to .
- B..
- C..
- D..
- 7.
Suppose a currency has coins worth , and . For which amount does the greedy method (always use the largest coin that fits) not use the fewest coins?
- A.
- B.
- C.
- D.
- 8.
What is the length of a longest common subsequence of
AGGTABandGXTXAYB? - 9.
Which specification correctly says that a Lean function
sort : List ℕ → List ℕis a sorting function? (Sorted lmeans each entry is≤the later ones;l₁ ~ l₂meansl₁is a permutation ofl₂.)- A.
∀ l, Sorted (sort l) ∧ sort l ~ l - B.
∀ l, Sorted (sort l) - C.
∀ l, sort l ~ l - D.
∀ l, Sorted (sort l) ∧ (sort l).length = l.length
- A.
- 10.
Write
lcs_length(x, y)that returns the length of a longest common subsequence of the stringsxandy, by filling the dynamic-programming table of Theorem 6 in time.Computational — Practice