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 stone and notes?

the answer, and why

the answer is C

5 rows of 5 cells, a row for each letter of stone. 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, such as t and e.
  • That adds the letters, but each row fills a cell for each letter of notes.

new numbers

question 2

How many letters do lemon and melon share in the same order, at most?

the answer, and why

the answer is A

Such as l, o and n, or e, o and n. Could they share 4? Leave one letter out of each word: lemon gives emon, lmon, leon, lemn and lemo, and melon gives elon, mlon, meon, meln and melo. None match.

if you chose another

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

new numbers

question 3

Which pair makes the method fill the most cells?

the answer, and why

the answer is D

5 times 5, which is 25.

if you chose another

  • 3 times 4, which is 12.
  • Equal words still fill every cell, but 4 times 4 is 16.
  • 1 times 6, which is 6.

new numbers