benchmarking sorting algorithms

Gauthier Cler

anas buyumad

SUMMARY

  • WHAT is sorting

  • Complexity

  • TYPES of algorithms

    • Comparisons

    • Non-comparisons

  • radix sort explanation

  • Benchmarks

what is sorting ?

"The arrangement of data in a prescribed sequence"

complexity

Stability

B

1

B

2

C

3

A

4

A

4

B

1

B

2

C

3

stable

unstable

B

1

B

2

C

3

A

4

A

4

B

2

B

1

C

3

types of algorithms

"TO compare or not to compare ?"

Comparisons sorts

"Comparing values"

A

B

Insertion sort, Merge sort, Bubble sort, Quick sort ...

merge sort

"Divide and conquer"

Stable Algorithm

O(n log n)

O(n log n)

O(n log n)

QUick sort

"partition exchange"

Unstable Algorithm

O(n lOG N)

O(n log n)

O(n^2)

HEAP SORT

"binary heap"

Unstable Algorithm

O(n)

O(n log n)

O(n LOG N)

non-Comparisons sorts

"using internal values"

2

34

tring

S

Bucket sort, Radix sort, Burst sort ...

lsd radix

[56, 7, 123, 2]

Lets take an example

[56, 7, 123, 2]

Starting from less significant digit

2: [2]

3: [123]

6: [56]

7: [7]

[2, 123, 56, 7]

[02, 123, 56, 07]

0: [2, 7]

2: [123]

5: [56]

[2, 7, 123, 56]

Repeat the operation

[002, 007, 123, 056]

0: [2, 7, 56]

1 : [123]

[2, 7, 56, 123]

AGAIN

benchmarks

                      List of 2000 elements                     
-------------------------------------------------------------
|  Rank  |      Name      |      Steps     |    Time (ms)   |
-------------------------------------------------------------
|   1    |      Merge     |      19445     |   0.00926424   |
|   2    |      Quick     |      22815     |   0.00947654   |
|   3    |      Shell     |      30002     |   0.01454226   |
|   4    |      Radix     |        0       |   0.01775204   |
|   5    |      Comb      |      57376     |   0.02294262   |
|   6    |    Patience    |     231498     |   0.05242654   |
|   7    |    Insertion   |     991113     |   0.35133472   |
|   8    |    Selection   |     1999000    |   0.69401822   |
|   9    |      Gnome     |     2021744    |   0.91225514   |
|   10   |    Cocktail    |     2062968    |   0.93562984   |
|   11   |     Bubbles    |     1999000    |   1.02601169   |
|   12   |      Heap      |     2792922    |   1.24046008   |
-------------------------------------------------------------

questions

301

By googo

301

  • 498