[{"data":1,"prerenderedAt":100},["ShallowReactive",2],{"tool-content-en-sorting-visualizer":3},{"id":4,"title":5,"body":6,"description":90,"extension":91,"locale":92,"meta":93,"navigation":94,"path":95,"seo":96,"stem":97,"toolId":98,"__hash__":99},"tools\u002Ftools\u002Fen\u002Fsorting-visualizer.md","Sorting Algorithm Visualizer",{"type":7,"value":8,"toc":81},"minimark",[9,13,22,26,57,61,64,68,71,74,78],[10,11,5],"h2",{"id":12},"sorting-algorithm-visualizer",[14,15,16,17,21],"p",{},"Sorting is the one algorithm every programmer learns and almost nobody can picture. Pick an algorithm, choose a starting order, and press ",[18,19,20],"strong",{},"Sort",": each comparison, swap and write is replayed on the bars one step at a time.",[10,23,25],{"id":24},"what-you-get","What you get",[27,28,29,36,42,48,54],"ul",{},[30,31,32,35],"li",{},[18,33,34],{},"Nine algorithms",": bubble, selection, insertion, shell, merge, quick, heap, counting and radix (LSD).",[30,37,38,41],{},[18,39,40],{},"Five starting orders",": random, already sorted, reversed, nearly sorted, and few unique values. Each one exposes a different corner of the complexity story — nearly sorted input flatters insertion sort, reversed input hurts bubble sort, and a small value range lets the non-comparison sorts run in linear time.",[30,43,44,47],{},[18,45,46],{},"Live counters"," for comparisons, swaps and writes. These are exact and delay-free, which makes them the honest way to compare two algorithms on the same array. Elapsed time would only measure your speed slider.",[30,49,50,53],{},[18,51,52],{},"Single step"," through the run, plus a reset that returns to the original order.",[30,55,56],{},"A short explanation and the best \u002F average \u002F worst complexity, extra space and stability of the selected algorithm.",[10,58,60],{"id":59},"how-the-animation-works","How the animation works",[14,62,63],{},"Each algorithm is written as a generator that emits an event for every comparison, swap and write. The run is recorded first, then replayed, so the animation always matches the real execution and you can step through it without re-running.",[10,65,67],{"id":66},"why-the-counters-matter","Why the counters matter",[14,69,70],{},"Bubble sort and selection sort both use O(n²) comparisons, but selection sort performs about n swaps while bubble sort can perform n²\u002F2. On hardware where writes are expensive, that difference decides which one you want. Merge sort and quick sort both average O(n log n), but quick sort's constant factor is usually smaller while merge sort stays stable and never degrades.",[14,72,73],{},"Counting sort and radix sort do not compare two elements at all, which is why they escape the Ω(n log n) lower bound for comparison sorts — at the price of extra memory and a restricted value range.",[10,75,77],{"id":76},"nothing-leaves-your-browser","Nothing leaves your browser",[14,79,80],{},"Every array is generated locally with a seeded PRNG, so results are reproducible and your data never leaves the page.",{"title":82,"searchDepth":83,"depth":83,"links":84},"",2,[85,86,87,88,89],{"id":12,"depth":83,"text":5},{"id":24,"depth":83,"text":25},{"id":59,"depth":83,"text":60},{"id":66,"depth":83,"text":67},{"id":76,"depth":83,"text":77},"Watch nine sorting algorithms run step by step with live comparison and swap counters, starting from random, sorted, or reversed data.","md","en",{},true,"\u002Ftools\u002Fen\u002Fsorting-visualizer",{"title":5,"description":90},"tools\u002Fen\u002Fsorting-visualizer","sorting-visualizer","992eqjXU0XF3Vcp4s6weDj-yTEiUg89VFuzGr8bN6Ck",1792391420599]