Workspace Word Search
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Word Search visualizer

Learn Word Search with a step-by-step Recursion & Backtracking visualizer, JavaScript source code and a worked example. Practice constraint search.

INTERACTIVE EXECUTION STUDIO
LEARN BY DOING

Predict. Execute. Understand.

Follow the source code, inspect live state changes, and predict the next operation before revealing it.

1 / 7Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": [
    [
      "A",
      "B",
      "C"
    ],
    [
      "S",
      "F",
      "C"
    ],
    [
      "A",
      "D",
      "E"
    ]
  ],
  "w": "ABCCED"
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,w
},s)=>{
let seen=new Set;
function f(i,j,k){
if(k===w.length)return true;
if(a[i]?.[j]!==w[k]||seen.has(i+","+j))return false;
let p=i+","+j;
seen.add(p);
s("Match letter "+w[k],{
Grid:a,Path:[...seen]
});
let yes=[[1,0],[-1,0],[0,1],[0,-1]].some(([x,y])=>f(i+x,j+y,k+1));
seen.delete(p);
return yes
}
return a.some((r,i)=>r.some((_,j)=>f(i,j,0)))
};

Execution canvas

Active Changed
STEP 1

Match letter A

Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.

Grid3 rows
Path1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Recursion & Backtracking · Constraint search

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": [
    [
      "A",
      "B",
      "C"
    ],
    [
      "S",
      "F",
      "C"
    ],
    [
      "A",
      "D",
      "E"
    ]
  ],
  "w": "ABCCED"
}

Execution steps

  1. Match letter A
  2. Match letter B
  3. Match letter C
  4. Match letter E
  5. Match letter D

Computed output

true
JavaScript reference implementation
const solve = ({
  a,w
},s)=>{
  let seen=new Set;
  function f(i,j,k){
    if(k===w.length)return true;
    if(a[i]?.[j]!==w[k]||seen.has(i+","+j))return false;
    let p=i+","+j;
    seen.add(p);
    s("Match letter "+w[k],{
      Grid:a,Path:[...seen]
    });
    let yes=[[1,0],[-1,0],[0,1],[0,-1]].some(([x,y])=>f(i+x,j+y,k+1));
    seen.delete(p);
    return yes
  }
  return a.some((r,i)=>r.some((_,j)=>f(i,j,0)))
};

Continue learning

Practice related DSA questions in the same topic.