The Stack Sorting Algorithm Visualizer

Report
christian berrer
tyron madlener




Architektur
How-To: Stooge Sort in PostScript
Vergleich & Metriken
Eine „kleine“ Vorführung
Integer
Array
swap
get
PostScript
Canvas
(put)
markPoints
?
Sorting
Algorithms
unmarkPoints
Vergleich
Canvas
Array
Punkte im
Array
tauschen
Punkte
markieren
Algorithmus
Punkte am
Spielfeld
tauschen
Vergleich
durchführen
Swap
Punkte demarkieren

Einfach, rekursiv, total ineffizient
algorithm stoogeSort (i = 0, j = length(L) - 1)
if L[j] < L[i] then
L[i] ↔ L[j]
if (j - i + 1) >= 3 then
t = (j - i + 1) / 3
stoogeSort (i, j - t)
stoogeSort (i + t, j )
stoogeSort (i, j-t)

Erster Schritt: Skelett festlegen
/stoogeSort
{
/ss
{
{
} if
{
ss
ss
ss
} if
} bind def
0 fsize % Stack: i j
ss
% Stack:
} bind def

Code und Debug-Operationen einfügen
L[j] L[i] ........
< .............
if
then ...
L[i] ↔ L[j] .........
(ss, out, 0, Stack: i j) pp
2dup
(ss, out, 1, Stack: i j i j) pp
ppop % Mark
(ss, out, 2, Stack: i j) pp
2dup 2 { exch field exch get+ } repeat
(ss, out, 3, Stack: i j f[i] f[j]) pp
gt 3 1 roll 2dup ppop rot % Unmark
(ss, out, 4, Stack: i j res) pp
{
(ss, if1, 0, Stack: i j) pp
2dup swap
(ss, if1, 1, Stack: i j) pp
} if
...

Die Funktion pp:
/pp { print (\n) print field pstack pop flush pause } def
/pp { pop } def

Wie sieht das live aus?
200
180
173
160
140
120
100
80
65
60
40
20
0
Operationen
Bubble
Selection
Insertion
Shell
Merge
Heap
Quick
Comb
Shear
Shaker
Slow
Gnome
Stooge
20000
15000
10000
5000
0
-5000
R1
R2
R3
R4
R5
R6
R7
R8
R9
-10000
-15000
-20000
-25000
Durchschnittliche Abweichungen
Bubble
Selection
Insertion
Shell
Merge
Heap
Quick
Comb
Shear
Shaker
Gnome
Stooge
30000
Bubble
Selection
Insertion
Shell
Merge
Heap
Quick
Comb
Shear
Shaker
Gnome
Stooge
25000
20000
15000
10000
5000
0
Get Operations
Put Operations
450000
Bubble
Selection
Insertion
Shell
Merge
Heap
Quick
Comb
Shear
Shaker
Gnome
Stooge
400000
350000
300000
250000
200000
150000
100000
50000
0
Get Operations
Put Operations
50000000
Bubble
Selection
Insertion
Shell
Merge
Heap
Quick
Comb
Shear
Shaker
Gnome
Stooge
45000000
40000000
35000000
30000000
25000000
20000000
15000000
10000000
5000000
0
Get Operations
Put Operations
1.6E+11
1.4E+11
1.33406E+11
1.2E+11
1E+11
Stooge
Slow
8E+10
6E+10
4E+10
2E+10
0
43165714.2
Get Operations
118994.2 124908
Put Operations

similar documents