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 grass and house?

the answer, and why

the answer is A

5 rows of 5 cells, a row for each letter of grass. 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 house.

new numbersthe test page's numbers

question 2

How many letters do prose and pores share in the same order, at most?

the answer, and why

the answer is D

Such as p, r, s, 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 p, the longest run side by side. The letters may have gaps, such as p, r, s.
  • 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

stone, blanket fills 35 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 15 cells, fewer than 35.
  • That pair fills 16 cells, fewer than 35.
  • That pair fills 24 cells, fewer than 35.

new numbersthe test page's numbers