Workspace Nth Root Of An Integer
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Nth Root of an Integer visualizer

Learn Nth Root of an Integer with a step-by-step Binary Search visualizer, JavaScript source code and a worked example. Practice search on answer.

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 / 4Execution step
Reference example · JavaScript
Inspect reference input
{
  "n": 3,
  "m": 27
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
n,m
},s)=>{
let l=1,r=m;
while(l<=r){
let x=(l+r)>>1,v=x**n;
s("Compare power",{
Bounds:[l,x,r],Power:[v],Target:[m]
});
if(v===m)return x;
if(v<m)l=x+1;
else r=x-1
}
return -1
};

Execution canvas

Active Changed
STEP 1

Compare power

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

Bounds3 items
Power1 items
Target1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Binary Search · Search on answer

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

{
  "n": 3,
  "m": 27
}

Execution steps

  1. Compare power

Computed output

3
JavaScript reference implementation
const solve = ({
  n,m
},s)=>{
  let l=1,r=m;
  while(l<=r){
    let x=(l+r)>>1,v=x**n;
    s("Compare power",{
      Bounds:[l,x,r],Power:[v],Target:[m]
    });
    if(v===m)return x;
    if(v<m)l=x+1;
    else r=x-1
  }
  return -1
};

Continue learning

Practice related DSA questions in the same topic.