Workspace Burning Tree
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Burning Tree visualizer

Learn Burning Tree with a step-by-step Binary Trees visualizer, JavaScript source code and a worked example. Practice structure and paths.

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 / 5Execution step
Reference example · JavaScript
Inspect reference input
{
  "a": [
    1,
    2,
    3,
    4,
    5,
    null,
    6
  ],
  "start": 1
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
a,start
},s)=>{
let q=[start],seen=new Set(q),d=0;
while(q.length){
s("Spread fire one edge per second",{
Tree:a,Frontier:q,Burned:[...seen],Time:[d]
});
let next=[];
for(let i of q)for(let j of [Math.floor((i-1)/2),2*i+1,2*i+2])if(j>=0&&a[j]!=null&&!seen.has(j)){
seen.add(j);
next.push(j)
}
q=next;
d++
}
return d-1
};

Execution canvas

Active Changed
STEP 1

Spread fire one edge per second

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

Tree7 items
Frontier1 items
Burned1 items
Time1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Binary Trees · Structure and paths

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": [
    1,
    2,
    3,
    4,
    5,
    null,
    6
  ],
  "start": 1
}

Execution steps

  1. Spread fire one edge per second

Computed output

3
JavaScript reference implementation
const solve = ({
  a,start
},s)=>{
  let q=[start],seen=new Set(q),d=0;
  while(q.length){
    s("Spread fire one edge per second",{
      Tree:a,Frontier:q,Burned:[...seen],Time:[d]
    });
    let next=[];
    for(let i of q)for(let j of [Math.floor((i-1)/2),2*i+1,2*i+2])if(j>=0&&a[j]!=null&&!seen.has(j)){
      seen.add(j);
      next.push(j)
    }
    q=next;
    d++
  }
  return d-1
};

Continue learning

Practice related DSA questions in the same topic.