18/9/2007 I2A 98 slides 3
1
Richard Bornat Dept of Computer Science
Sorting is removing inversions. In an array sorted by ( ! ) we have [ - - PDF document
Sorting is removing inversions. In an array sorted by ( ! ) we have [ ] ! [ ] ( ) i j , 0 i j n A i A j . If the array isnt " ! < < # completely sorted, it will contain inversions . That is, ( % [ ] > [ ] ) i
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
32
54
76
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
2 2
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
32
54
76
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
k k
&1 0 which ends with
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
32 (Shellsort worst case) grows much more quickly
5000000 10000000 15000000 20000000 25000000 30000000 35000000 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 n lg n n^3/2
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
54 (Shellsort average time,
200000 400000 600000 800000 1000000 1200000 1400000 1600000 1800000 10000 20000 30000 40000 50000 60000 70000 80000 90000 100000 n lg n n^7/6 n^5/4
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
54 grows more quickly than N
5000000 10000000 15000000 20000000 25000000 30000000 35000000 100000 200000 300000 400000 500000 600000 700000 800000 900000 1000000 n lg n n^7/6 n^5/4
76!
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
76 (Shellsort
500000000 1000000000 1500000000 2000000000 2500000000 3000000000 10000000 20000000 30000000 40000000 50000000 60000000 70000000 80000000 90000000 1E+08 n lg n n^7/6
18/9/2007 I2A 98 slides 3
Richard Bornat Dept of Computer Science
5000000000 10000000000 15000000000 20000000000 25000000000 30000000000 35000000000 1E+08 2E+08 3E+08 4E+08 5E+08 6E+08 7E+08 8E+08 9E+08 1E+09 n lg n n^7/6