Solution

ID: past-exam-of-the-year-1-of-the-computer-science-course-of-the-university-of-oxford/2017/functional-programming-design-and-analysis-of-algorithms/8/c/solution

Store one maximizing predecessor together with every table value. For alignment traceback, start at and follow these pointers:
  • emits x[i-1] opposite y[j-1]; the letters are equal because that diagonal candidate was allowed only on a match.
  • emits x[i-1] opposite a gap.
  • emits a gap opposite y[j-1].
Continue to , including boundary moves, then reverse the collected columns. Any deterministic choice among tied predecessors gives an optimal alignment. Each step decreases at least one index, so reconstruction costs additional time and output space. The full score table or predecessor table requires storage for positive lengths.

New to topics? Read the docs here!