Add notes on LCS weaknesses

pull/25/head
Wilfred Hughes 2021-03-21 13:34:01 +07:00
parent 5b18257598
commit ccd6ac4d44
1 changed files with 48 additions and 0 deletions

@ -0,0 +1,48 @@
Consider changing:
```
foo();
bar();
```
To:
```
if (true) {
foo();
}
```
What we want:
```
+ if (true) {
foo();
- bar();
+ }
```
A longest-common-subsequence algorithm is wrong here. The longest
subsequence is five tokens:
```
( ) ( ) ;
```
which leads to:
```
+if+ (+true+) +{+
+foo+();
-bar-();
+}+
```
so we claim `foo` is added. We want the following *four* tokens to be
preserved:
```
foo ( ) ;
```
Proposed solution: advance on both sides, keep first match.