Sequence Alignment: Algorithm Tracing
Consider two sequences of characters “opt” and “cope” and the misalignment penalty specification shown below.
Penalties:
- Gap penalty
- Mismatch penalty if aligning the same vowels or consonants
- Mismatch penalty if aligning different vowels or consonants
- Mismatch penalty if aligning a vowel and a consonant
The pseudocode of the sequence alignment algorithm is shown below. (For the two sequences above, m = 3 for “opt” and n = 4 for “cope”.)

Trace the sequence alignment algorithm as we did in class. Specifically,
- Create an fill in a two-dimensional memorization array shown below (3 and 4 are the numbers of characters in “opt” and “cope”, respectively).

In your answer, each array cell should contain the minimum alignment cost and the immediate predecessor array cell. Show the immediate predecessor array cell using an arrow as shown in the example below (left). If there is a tie among the three cases, show both arrows.
- Show the optimal alignment (i.e., with the minimum misalignment penalty) with red color arrows in the memoization table (see the example below (left)) and also in a box-sequence diagram (see the example below (right)). If there are more than one optimal alignment (i.e., with the same minimum alignment cost), write all of them in the answer.

Building Memoization Table
We know and , gap penalty , and mismatch penalties yields 0 for same vowels/consonants, 1 for different vowels/consonants, and 3 for vowel vs consonant.
We initialize for first col, and for the first row. Then we fill rest with:
Yielding: see figure 4

Optimal Alignments
Minimum cost = 5, therefore tracing from with red path yields:
Yielding Optimal algorithm: see figure 5

Cost: gap + + + + + + + = 5, meaning optimal alignment.
Bellman-Ford Shortest Paths: Algorithm Tracing
Consider the directed graph shown below (left). Run the Bellman-Ford shortest path algorithm we studied in class to find the shortest path from each node to the node t. Specifically,
- Fill in the two-dimensional memorization array shown below (right) (n: the number of nodes, V: the set of nodes), where each array entry contains the shortest path length and the immediate successor node. Show the completed memorization table with “shortest path length/immediate successor” in each array entry, e.g., “8/d”
- For each node in the graph, show the shortest path and its path length in the following format: “Shortest path from x to t: x – y – z – t (path length = 8)”. Note path length is the sum of the weights of edges in the path. Showing the intermediate steps of computing the shortest path length is not required but is recommended for partial credit in case of an incorrect answer.

Memoization Table
We know this table shows us the shortest path from node to with at most edges, along immediately after the successor node.
We can use Bellman Ford Recurrence here:
Yielding:
See figure 7

Shortest Paths
Using the previous final row at we can trace: