34
An Adventure into Sorting By Mauktik Gandhi Date: 12 th May 2002

An Adventure into Sorting

Embed Size (px)

DESCRIPTION

An Adventure into Sorting. By Mauktik Gandhi Date: 12 th May 2002. Some Sorting Algorithms. Bubble Sort Insertion Sort Selection Sort Merge Sort Heap Sort Quick Sort (avg.). Well Established fact. Using comparison based sorting the fastest we can go is n*log (n) - PowerPoint PPT Presentation

Citation preview

Page 1: An Adventure into Sorting

An Adventure into Sorting

By Mauktik Gandhi

Date: 12th May 2002

Page 2: An Adventure into Sorting

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

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

Solution - Snip Snip

Well if it is not possible then whats the point trying.

So avoid comparison….

Page 5: An Adventure into Sorting

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

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

Step 1.

That’s all, the first step is done. One node, the root of the amazing tree.

Page 8: An Adventure into Sorting

Step 2. Adding Words

Lets add “Car”

Page 9: An Adventure into Sorting

Adding “Car”

Lets add “Car”

C

Page 10: An Adventure into Sorting

Adding “Car”

Lets add “Car”

C

A

Page 11: An Adventure into Sorting

Completing “Car”

Lets add “Lot”

C

A

R

Page 12: An Adventure into Sorting

Adding “Lot”

Lets add “Lot”

C L

A

R

Page 13: An Adventure into Sorting

Adding “Lot”

Lets add “Lot”

C L

OA

R

Page 14: An Adventure into Sorting

Completing “Lot”

Lets add “Lot”

C L

OA

R T

Page 15: An Adventure into Sorting

Adding “Cat” ??

Now add “Cat”

C L

OA

R T

Page 16: An Adventure into Sorting

Adding “Cat” ??

Now add “a”

C L

OA

R T

Page 17: An Adventure into Sorting

Adding “Cat” ??

That’s confusing

C L

OA

R TT

Page 18: An Adventure into Sorting

Now add “Go”

Where does “Go” go ??

C L

OA

R TT

G

Page 19: An Adventure into Sorting

Now add “Go”

Where does “Go” go ??

C L

OA

R TT

G

O

Page 20: An Adventure into Sorting

Now to Remove_First

No end in sight

C L

OA

R TT

G

O

Page 21: An Adventure into Sorting

Removing First

C L

OA

R TT

G

O

C

A

My head is bursting

Page 22: An Adventure into Sorting

Removing First

C L

OA

TT

G

O

Next

Page 23: An Adventure into Sorting

Removing First

L

O

T

G

O

Next

Page 24: An Adventure into Sorting

Removing First

L

O

T

G

O

Continue

Page 25: An Adventure into Sorting

Removing First

L

O

T

I cant take it any longer

Page 26: An Adventure into Sorting

Well, its done

Is it done ??

Page 27: An Adventure into Sorting

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

End Of Abstract Description

WOW!!I survived the tortureHey, but what about

efficiency??

Page 29: An Adventure into Sorting

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

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

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

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

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

The End