Workspace Sort List
0d
Back to questionsDSA Visualizers: 388 Coding Questions

Sort List visualizer

Learn Sort List with a step-by-step Linked Lists visualizer, JavaScript source code and a worked example. Practice rewiring and advanced.

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 / 9Execution step
Reference example · JavaScript
Inspect reference input
[
  4,
  2,
  1,
  3
]

Algorithm source

JavaScript reference implementation · highlighted trace statement
const solve = (a,s)=>{
function f(a){
if(a.length<2)return a;
let m=a.length>>1,l=f(a.slice(0,m)),r=f(a.slice(m)),o=[];
while(l.length||r.length){
o.push(!r.length||l.length&&l[0]<=r[0]?l.shift():r.shift());
s("Merge ordered chains",{
Left:l,Right:r,Merged:o
})
}
return o
}
return f(a)
};

Execution canvas

Active Changed
STEP 1

Merge ordered chains

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

Left1 items
Right0 items

Empty at this step.

Merged1 items
Keyboard: Space to play · Left / Right to stepExplore next problem

Worked example and algorithm walkthrough

Topic: Linked Lists · Rewiring and advanced

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

[
  4,
  2,
  1,
  3
]

Execution steps

  1. Merge ordered chains

Computed output

[
  1,
  2,
  3,
  4
]
JavaScript reference implementation
const solve = (a,s)=>{
  function f(a){
    if(a.length<2)return a;
    let m=a.length>>1,l=f(a.slice(0,m)),r=f(a.slice(m)),o=[];
    while(l.length||r.length){
      o.push(!r.length||l.length&&l[0]<=r[0]?l.shift():r.shift());
      s("Merge ordered chains",{
        Left:l,Right:r,Merged:o
      })
    }
    return o
  }
  return f(a)
};

Continue learning

Practice related DSA questions in the same topic.