an adventure into sorting

Post on 02-Jan-2016

29 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

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

TRANSCRIPT

An Adventure into Sorting

By Mauktik Gandhi

Date: 12th May 2002

Some Sorting Algorithms

Bubble Sort Insertion Sort Selection Sort Merge Sort Heap Sort Quick Sort (avg.)

)( 2nTime

)log( nn Time

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.

Solution - Snip Snip

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

So avoid comparison….

Possible, but need help

ASCII characters are already sorted for us

Why not use them as helpers ??

So I did, I cheated

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

!

Step 1.

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

Step 2. Adding Words

Lets add “Car”

Adding “Car”

Lets add “Car”

C

Adding “Car”

Lets add “Car”

C

A

Completing “Car”

Lets add “Lot”

C

A

R

Adding “Lot”

Lets add “Lot”

C L

A

R

Adding “Lot”

Lets add “Lot”

C L

OA

R

Completing “Lot”

Lets add “Lot”

C L

OA

R T

Adding “Cat” ??

Now add “Cat”

C L

OA

R T

Adding “Cat” ??

Now add “a”

C L

OA

R T

Adding “Cat” ??

That’s confusing

C L

OA

R TT

Now add “Go”

Where does “Go” go ??

C L

OA

R TT

G

Now add “Go”

Where does “Go” go ??

C L

OA

R TT

G

O

Now to Remove_First

No end in sight

C L

OA

R TT

G

O

Removing First

C L

OA

R TT

G

O

C

A

My head is bursting

Removing First

C L

OA

TT

G

O

Next

Removing First

L

O

T

G

O

Next

Removing First

L

O

T

G

O

Continue

Removing First

L

O

T

I cant take it any longer

Well, its done

Is it done ??

Testing

That showed how to sort four items Similarly, a large number of words can be

sorted Question: Is it efficient ?

End Of Abstract Description

WOW!!I survived the tortureHey, but what about

efficiency??

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

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

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

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

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

The End

top related