Data Structures & AlgorithmsHardGATE CS · ICPC regional
Strings a = "baabbc" and b = "accca". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein distance). What is the edit distance between a and b?
- A. 7
- B. 1
- C. 6
- D. 5
Correct answer: D. 5
The DP table gives 5. The insertion–deletion distance (no substitution) gives 7, which overcounts substitutions.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Points A(5,7), B(2,4), C(3,8), D(5,0), E(1,1), F(9,8) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| +…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: B→C (-3); D→A (-1); D→E (-2); A→E (6); B→A (-2)…
- Distinct words ['ba', 'c', 'b', 'ca', 'bc', 'aac'] are inserted into an empty trie (one node per character, shared prefixes share nodes…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), B–C (1), B–E (1), C–D (1), C–E (1), D–E (1), D–G (1), E–G (1)…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→C (4), A→F (1), B→D (2)…
- Directed graph on vertices A, B, C, D, E, F with edges F→D, C→F, A→D, A→C, F→E, F→C, B→E (no weights). What is the number of vertices in…