Back to questionsDSA Visualizers: 388 Coding Questions Edit Distance visualizer Learn Edit Distance with a step-by-step Dynamic Programming visualizer, JavaScript source code and a worked example. Practice string dp.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 16 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"a": "horse",
"b": "ros"
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 a,b
3 },s)=>{
4 let d=Array.from ({
5 length:a.length+1
6 },(_,i)=>Array.from ({
7 length:b.length+1
8 },(_,j)=>i===0 ?j:j===0 ?i:0 ));
9 for (let i=1 ;
10 i<=a.length;
11 i++)for (let j=1 ;
12 j<=b.length;
13 j++){
14 d[i][j]=a[i-1 ]===b[j-1 ]?d[i-1 ][j-1 ]:1 +Math.min(d[i-1 ][j],d[i][j-1 ],d[i-1 ][j-1 ]);
15 s("Compute edit cost",{
16 DP:d,Cell:[i,j]
17 })
18 }
19 return d[a.length][b.length]
20 };
Execution canvas Active ChangedSTEP 1 Compute edit cost Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Dynamic Programming · String DP
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input {
"a": "horse",
"b": "ros"
} Execution steps Compute edit cost Computed output 3 JavaScript reference implementation const solve = ({
a,b
},s)=>{
let d=Array.from({
length:a.length+1
},(_,i)=>Array.from({
length:b.length+1
},(_,j)=>i===0?j:j===0?i:0));
for(let i=1;
i<=a.length;
i++)for(let j=1;
j<=b.length;
j++){
d[i][j]=a[i-1]===b[j-1]?d[i-1][j-1]:1+Math.min(d[i-1][j],d[i][j-1],d[i-1][j-1]);
s("Compute edit cost",{
DP:d,Cell:[i,j]
})
}
return d[a.length][b.length]
};Continue learning Practice related DSA questions in the same topic.