Workspace Pow X N
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Pow X N visualizer

Learn Pow X N with a step-by-step Recursion & Backtracking visualizer, JavaScript source code and a worked example. Practice subsets and combinations.

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
{
  "x": 2,
  "n": 10
}

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = ({
x,n
},s)=>{
let r=1;
while(n){
if(n%2)r*=x;
x*=x;
n=Math.floor(n/2);
s("Square base and halve exponent",{
Result:[r],Base:[x],Exponent:[n]
})
}
return r
};

Execution canvas

Active Changed
STEP 1

Square base and halve exponent

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

Result1 items
Base1 items
Exponent1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Recursion & Backtracking · Subsets and combinations

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

{
  "x": 2,
  "n": 10
}

Execution steps

  1. Square base and halve exponent

Computed output

1024
JavaScript reference implementation
const solve = ({
  x,n
},s)=>{
  let r=1;
  while(n){
    if(n%2)r*=x;
    x*=x;
    n=Math.floor(n/2);
    s("Square base and halve exponent",{
      Result:[r],Base:[x],Exponent:[n]
    })
  }
  return r
};

Continue learning

Practice related DSA questions in the same topic.