M Pivot Sort – Faster Than Quick Sort! - Google Sites

2 downloads 35 Views 335KB Size Report
Nov 27, 2011 - Study funded by MTSU Ronald E McNair Program .... International Conference on Algorithmic Mathematics and
M Pivot Sort – Faster Than Quick Sort! Presenter: James Edmondson Mentor: Dr. Judy Hankins Study funded by MTSU Ronald E McNair Program

M Pivot Sort – Faster than Quick Sort!

Table of Contents

Introduction ……………………………………………. Introduction to M Pivot Sort………………………….. Testing: System Specifications……………………… Testing: Ascending Lists……………………………… Testing: Descending Lists……………………………. Testing: Random Integer Lists………………………. Testing: Random String Lists………………………… Testing: Random Class Lists………………………… Conclusion……………………………………………... References…………………………………………….. 11/27/2011

3 5 7

8 10 12

15 17 19

20 2

M Pivot Sort – Faster than Quick Sort!

Introduction

Sorting Algorithms – Sorting algorithms constitute the core of most algorithm textbooks. – Most computer programmers still use sorting algorithms that were developed in the late 1950s and early 1960s. – O(n log n) is the theoretical lower bound for comparison based sorting algorithms. – New O(n log n) algorithms have been developed as late as Multikey Quick Sort in 1997 but are usually specialized sorts for certain types of data. 11/27/2011

3

M Pivot Sort – Faster than Quick Sort!

Introduction

Sorting Algorithms (continued) – To be accepted into common practice, new sorting algorithms have to compete with Quick Sort in speed and usability. – Two other algorithms, Merge Sort and Heap Sort, are also used widely and should be included in empirical comparisons.

11/27/2011

4

M Pivot Sort – Faster than Quick Sort!

Introduction: M Pivot Sort

M Pivot Sort – Based on partitioning principle in Quick Sort. – Applies the Strong Law of Large Numbers to produce better sampling than Quick Sort. – Handles duplicates in linear time (Quick Sort goes into polynomial time without three way partitioning.) – Performs on average in O(n log n) time. – Has a better worst case scenario (roughly half) than Quick Sort.

11/27/2011

5

M Pivot Sort – Faster than Quick Sort!

Introduction: M Pivot Sort

M Pivot Sort (continued) – Performs more targeted moves than Quick Sort (results in less moves) – Performs slightly more data comparisons than Quick Sort but far less than Heap Sort. – Performs less recursion than Quick Sort or Merge Sort. – May perform runtime changes to correct polynomial time [O(n2)] performance by changing the number of pivots (3-7). 11/27/2011

6

M Pivot Sort – Faster than Quick Sort!

Testing: System Specifications

System Specifications for Testing – – – – –

Quad Xeon, 2 GBs of RAM, Intel Architecture. Windows 2003 Server Standard Edition. Visual C++ command prompt based. Random Integer Generator designed by Andy Thomas. Random string generator produces 4-19 character random ANSI C++ strings. – Random class generator produces 4 7-17 character random ANSI C++ strings, one of which is the sorting key. – Ascending and descending lists are integer based. – Ten different sets of data ran for each algorithm for each type of test. Mean average taken for stats generated here. 11/27/2011

7

M Pivot Sort – Faster than Quick Sort!

Testing: Ascending Lists

* Tests on list of 100 million ascending integers

Asce nding List - Total Ope rations in N Units

Quick Sort (CM)

65.08

Quick Sort (MOT)

64.09

Pivot Sort

40.73

Merge Sort

66.83

Heap Sort 0.00

130.77 20.00

40.00

60.00

80.00

100.00

120.00

140.00

Units expressed in 100 million operations, ie Merge Sort performed 66.83 100 million operations, or 6,683,000,000 total operations. 11/27/2011

8

M Pivot Sort – Faster than Quick Sort!

Testing: Ascending Lists

* Tests on list of 100 million ascending integers

Ascending List - Sorting Time in Seconds Quick Sort (CM)

18

Quick Sort (MOT)

15

Pivot Sort

16

Merge Sort

34

Heap Sort

33 0

11/27/2011

5

10

15

20

25

30

35

40

9

M Pivot Sort – Faster than Quick Sort!

Testing: Descending Lists

* Tests on list of 100 million descending integers

Descending List - Total Operations in N Units Quick Sort (CM)

68.10

Quick Sort (MOT)

65.45

Pivot Sort

56.06

Merge Sort

66.46

Heap Sort 0.00

124.25 20.00

40.00

60.00

80.00

100.00

120.00

140.00

Units expressed in 100 million operations, ie Merge Sort performed 66.83 100 million operations, or 6,683,000,000 total operations. 11/27/2011

10

M Pivot Sort – Faster than Quick Sort!

Testing: Descending Lists

* Tests on list of 100 million descending integers

Descending List - Sorting Time in Seconds 20

Quick Sort (CM) 17

Quick Sort (MOT) Pivot Sort

18

Merge Sort

32

Heap Sort

35 0

11/27/2011

5

10

15

20

25

30

35

40

11

M Pivot Sort – Faster than Quick Sort!

Testing: Random Integers

* Tests on list of 100 million random integers

Random Integer List - Total Operations in N Units Quick Sort (CM)

88.18

Quick Sort (MOT)

75.56

Pivot Sort

66.84 78.65

Merge Sort

127.28

Heap Sort 0.00

20.00

40.00

60.00

80.00

100.00 120.00 140.00

Units expressed in 100 million operations, ie Merge Sort performed 78.65 100 million operations, or 7,650,000,000 total operations. 11/27/2011

12

M Pivot Sort – Faster than Quick Sort!

Testing: Random Integers

* Tests on list of 100 million random integers

Random Integer List - Sorting Time in Seconds Quick Sort (CM)

33

Quick Sort (MOT)

27

Pivot Sort

27

Merge Sort

49 156

Heap Sort 0

11/27/2011

50

100

150

200

13

M Pivot Sort – Faster than Quick Sort!

Testing: Random Integers

* Test on list of 100 million random integers (200,000 possible values – duplicate records present) Time in Seconds - 100 Million Random Integers (0-200,000 possible values) 160

148

140 120

101

100 80 60

48

40 19

20 0 Heap Sort

Merge Sort

Pivot Sort

Quick Sort

Figure 8

Shows Quick Sort’s performance on duplicates vs. Pivot Sort. Source is M Pivot Sort – Replacing Quick Sort. 11/27/2011

14

M Pivot Sort – Faster than Quick Sort!

Testing: Random Strings

* Tests on list of 10 million random strings

Random String List - Total Operations in N Units Quick Sort (CM)

76.72

Quick Sort (MOT)

65.83

Pivot Sort

58.70

Merge Sort

68.65 110.61

Heap Sort 0.00

20.00

40.00

60.00

80.00

100.00

120.00

Units expressed in 10 million operations, ie Merge Sort performed 68.65 10 million operations, or 686,500,000 total operations. 11/27/2011

15

M Pivot Sort – Faster than Quick Sort!

Testing: Random Strings

* Tests on list of 10 million random strings

Random String List - Sorting Time in Seconds Quick Sort (CM)

61

Quick Sort (MOT)

54

Pivot Sort

43

Merge Sort

80 116

Heap Sort 0

11/27/2011

20

40

60

80

100

120

140

16

M Pivot Sort – Faster than Quick Sort!

Testing: Random Classes

* Tests on list of one million random classes

Random Class List - Total Operations in N Units Quick Sort (CM)

65.60

Quick Sort (MOT)

56.39

Pivot Sort

50.15

Merge Sort

58.58 93.94

Heap Sort 0.00

20.00

40.00

60.00

80.00

100.00

Units expressed in 1 million operations, ie Merge Sort performed 58.58 one million operations, or 58,580,000 total operations. 11/27/2011

17

M Pivot Sort – Faster than Quick Sort!

Testing: Random Classes

* Tests on list of one million random classes

Random Class List - Sorting Time in Seconds Quick Sort (CM)

18

Quick Sort (MOT)

17

Pivot Sort

12

Merge Sort

16 28

Heap Sort 0

11/27/2011

5

10

15

20

25

30

18

M Pivot Sort – Faster than Quick Sort!

Conclusion

Conclusion – M Pivot Sort meets or beats the time taken by Quick Sort for sorts on contiguous lists (arrays). – M Pivot Sort performs favorably on sorting presorted and descending lists (common database operations.) – M Pivot Sort performs less moves and less total operations than Quick Sort, Heap Sort, and Merge Sort. – M Pivot Sort is an ideal candidate for general purpose sorting libraries for varied or singular data types. 11/27/2011

19

M Pivot Sort – Faster than Quick Sort!

References

References – [1] Bentley, Jon L. “The trouble with qsort.” UNIX Review. 10.2 (1992): 85-90. – [2] Bentley, Jon L. “Software Exploratorium: history of a Heapsort.” UNIX Review. 10.8 (1992): 71-77. – [3] Cormen, Thomas, et al. Introduction to Algorithms. 2nd ed. Massachusetts: MIT Press, 2001. – [4]Edmondson, James. “M Pivot Sort – Replacing Quick Sort.” Proceedings of the 2005 International Conference on Algorithmic Mathematics and Computer Science (2005): 47-53. – [5] Kruse, Robert, et al. Data Structures & Program Design in C –. 2nd ed. New Jersey: Prentice Hall, 1997. 335. – [6] McClave, James T. and Terry Sincich. A First Course in Statistics – Annotated Instructor’s Edition. 8th ed. New Jersey: Prentice Hall, 2003. 224, 277-308. – [7] Sedgewick, Robert and Jon Bentley. “Quicksort is Optimal.” Knuthfest, Stanford University, Stanford. January 2002. – [8] Sedgewick, Robert. Algorithms in Java. 3rd ed. Boston: Addison-Wesley, 2003. – [9] Thomas, Andy. “Randomal64 Pseudo Random Number Generator.” Generation5.org. 20 April 2001. 6 Feb. 2005 .

11/27/2011

20