wild-inter.net

Peeksort

Top-down mergesort that peeks at the middle and cuts at the nearest run boundary instead. Step by step through the recursion: how i, j and the Δ’s are found in each call, and how the sign of a Δ says whether a run is known. The code is the one from the slides; the highlighted line is the one being executed. Merging is a single step here.

Show
— / — Speed 600ms
Recursive calls
The current call
What happens
Codeas on the slides
Input as text
The elements, separated by spaces, commas or line breaks — the format of the algs4 sorting clients, so e.g. tiny.txt can be pasted as it is. If every element is a number they are compared numerically, otherwise as strings. Lines starting with # are comments.

Instead of the elements, a line @runs 5 3 3 14 1 2 asks for an input with exactly these run lengths (the numbers 1 … n, every run increasing and every run boundary a descent), and @seed 3 picks another such input.

At most 256 elements. The same works in the page address, e.g. #runs=5,3,3,14,1,2 or #in=S,O,R,T,E,X,A,M,P,L,E; add &skip to skip the scans and &present for the presentation view. &grid opens the tab with the global and the local grid (plus &local to start from the local grid, &nogreen, &nopowers).