Skip to content

Longest common subsequence

planning ahead

Level 2 of 3

Also called LCS and Longest common subsequence, by dynamic programming.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from longest common subsequence's own run on the numbers shown.

choose one

question 1

How many cells does the method fill to compare cream and round?

the answer, and why

the answer is A

5 rows of 5 cells, a row for each letter of cream. The first row and column are written at the start.

if you chose another

  • That counts the first row and column too, which are written at the start, not filled.
  • That is the longest common subsequence, not the cells.
  • That adds the letters, but each row fills a cell for each letter of round.

new numbersthe test page's numbers

question 2

How many letters do pears and spare share in the same order, at most?

the answer, and why

the answer is C

Such as p, a, r, 3 letters in the same order in both. No 4 letters stand in the same order in both.

if you chose another

  • They have the same 5 letters, but not in the same order.
  • That is a, r, the longest run side by side. The letters may have gaps, such as p, a, r.
  • 0 is only for words with no letter in common.

new numbersthe test page's numbers

question 3

Which pair makes the method fill the most cells?

the answer, and why

the answer is C

garden, dream fills 30 cells, a row for each letter of the first word and a cell for each letter of the second, the most of the four.

if you chose another

  • That pair fills 12 cells, fewer than 30.
  • That pair fills 15 cells, fewer than 30.
  • That pair fills 12 cells, fewer than 30.

new numbersthe test page's numbers