An Adventure into Sorting
-
Upload
howard-delaney -
Category
Documents
-
view
29 -
download
1
description
Transcript of An Adventure into Sorting
![Page 1: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/1.jpg)
An Adventure into Sorting
By Mauktik Gandhi
Date: 12th May 2002
![Page 2: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/2.jpg)
Some Sorting Algorithms
Bubble Sort Insertion Sort Selection Sort Merge Sort Heap Sort Quick Sort (avg.)
)( 2nTime
)log( nn Time
![Page 3: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/3.jpg)
Well Established fact
Using comparison based sorting the fastest we can go is n*log (n)
So we are bound by a theorem established long ago.
![Page 4: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/4.jpg)
Solution - Snip Snip
Well if it is not possible then whats the point trying.
So avoid comparison….
![Page 5: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/5.jpg)
Possible, but need help
ASCII characters are already sorted for us
Why not use them as helpers ??
So I did, I cheated
![Page 6: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/6.jpg)
Steps taken to sort
Prepare the internal representation for taking the items to be sorted
Continue building representation as items are added one at a time.
Remove the items, one by one, amazingly they are sorted
All take constant time
!
![Page 7: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/7.jpg)
Step 1.
That’s all, the first step is done. One node, the root of the amazing tree.
![Page 8: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/8.jpg)
Step 2. Adding Words
Lets add “Car”
![Page 9: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/9.jpg)
Adding “Car”
Lets add “Car”
C
![Page 10: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/10.jpg)
Adding “Car”
Lets add “Car”
C
A
![Page 11: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/11.jpg)
Completing “Car”
Lets add “Lot”
C
A
R
![Page 12: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/12.jpg)
Adding “Lot”
Lets add “Lot”
C L
A
R
![Page 13: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/13.jpg)
Adding “Lot”
Lets add “Lot”
C L
OA
R
![Page 14: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/14.jpg)
Completing “Lot”
Lets add “Lot”
C L
OA
R T
![Page 15: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/15.jpg)
Adding “Cat” ??
Now add “Cat”
C L
OA
R T
![Page 16: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/16.jpg)
Adding “Cat” ??
Now add “a”
C L
OA
R T
![Page 17: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/17.jpg)
Adding “Cat” ??
That’s confusing
C L
OA
R TT
![Page 18: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/18.jpg)
Now add “Go”
Where does “Go” go ??
C L
OA
R TT
G
![Page 19: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/19.jpg)
Now add “Go”
Where does “Go” go ??
C L
OA
R TT
G
O
![Page 20: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/20.jpg)
Now to Remove_First
No end in sight
C L
OA
R TT
G
O
![Page 21: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/21.jpg)
Removing First
C L
OA
R TT
G
O
C
A
My head is bursting
![Page 22: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/22.jpg)
Removing First
C L
OA
TT
G
O
Next
![Page 23: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/23.jpg)
Removing First
L
O
T
G
O
Next
![Page 24: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/24.jpg)
Removing First
L
O
T
G
O
Continue
![Page 25: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/25.jpg)
Removing First
L
O
T
I cant take it any longer
![Page 26: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/26.jpg)
Well, its done
Is it done ??
![Page 27: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/27.jpg)
Testing
That showed how to sort four items Similarly, a large number of words can be
sorted Question: Is it efficient ?
![Page 28: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/28.jpg)
End Of Abstract Description
WOW!!I survived the tortureHey, but what about
efficiency??
![Page 29: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/29.jpg)
Now lets talk Concrete
Completed first implementation for RESOLVE/C++
The working class is Sorting_Machine_Kernel_X
Sorting_Machine/Kernel_X.hSorting_Machine/Kernel_X_Body.h
![Page 30: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/30.jpg)
Timing Comparison Table
MySort QuickSort1000 6.1100 4.35002000 13.2600 8.97005000 37.0000 25.1200
10000 69.1400 56.560015000 105.2300 99.630030000 234.5100 287.4300
Number of words Time in Seconds
![Page 31: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/31.jpg)
Quick Sort vs MySort
Sorting Algorithms
0.0000
50.0000
100.0000
150.0000
200.0000
250.0000
300.0000
350.0000
0 10000 20000 30000 40000
Number of words
Tim
e (s
ec)
MySort
QuickSort
![Page 32: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/32.jpg)
Processor taxing time !!
Insertion Phase Change Extraction Total Time1000 5.4300 0.0000 0.6800 6.11002000 11.8900 0.0000 1.3700 13.26005000 33.3100 0.0000 3.6900 37.000010000 62.4700 0.0000 6.6700 69.140015000 95.2500 0.0000 9.9800 105.230030000 214.4000 0.0000 20.1100 234.5100
I do a lot of work out here
![Page 33: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/33.jpg)
What’s Next ?
Templates, recursion and lots of procedure calls seem to eat on efficiency
So plan to re-implement it using C/C++– Avoid recursion– More efficient memory management– Minimize procedure calls– Lastly implement and use exploration trees
Help avoid recursion No need to decompose and recompose
![Page 34: An Adventure into Sorting](https://reader036.fdocuments.in/reader036/viewer/2022062422/5681332e550346895d9a2bde/html5/thumbnails/34.jpg)
The End