You are on page 1of 5

Effect of Pivot position on Quick Sort speed

Adi Wirya
Informatics Study Program, Faculty of Engineering and Informatics
Universitas Multimedia Nusantara
Jl. Scientia Boulevard, Gading Serpong, Tangerang, Banten Indonesia
Email: adi.wirya@student.umn.ac.id

Abstract- There are many ways to sort the data. However, there is a fairly famous sorting technique, with the speed of Quick
Sort. This journal will discuss whether the pivot position on quick sort affects the performance of the quick sortalgorithm. We will
compare the 4 types of quick sort algorithms (1) Quick sort Median element pivot, (2) Quick sort First element Pivot, (3) Quick
sort Last element Pivot, and (4) Quick sort Random pivot With Lomuto Partition

Keywords : Algorithm, Quick Sort, Pivot, Lomuto

1. Background in the center, (2) at the beginning, (3) at the end


, and (4) random with Lomuto
Quicksort is a sorting algorithm developed by Tony
Hoare. O (n log n) sorting average performance to
sort n items. This algorithm is also known as
Partition-Exchange Sort. In its worst case, this
algorithm is making a comparison of 2o (n), if such
an event is very rare. Quicksort is often faster in
practice than other algorithms.

2. Research methods

A. Data Preparation
Now we need enough data to be able to see
the speed comparison of the Quick Sort
algorithm based on the pivot position then we
will use an array containing 100 random
Number data. By using the JavaScript
programming language to generate and test
the sorting algorithm that we discussed.
The contents of the array
[22,1,84,2,6,52,45,25,16,8,26,14,68,61,28,
87,77,19,78,39,48,63,60,47,77,93,19,65,30,28,
84,69,6,69,48,32,53,8,22,70,40,66,41,67,99,3,
95,44,30,62,97,9,5,84,43,44,33,91,48,39,46,89
,88,97,34,25,71,55,51,81,71,49,73,15,28,98,68
,65,63,83,6,84,64,18,99,68,21,71,78,83,86,41,
50,72,57,44,58,32,57,81]
B. Quick Sort algorithm
This quicksort algorithm i created with the
recursive method and there are 4 Pivot (1)
Figure 2. 1 Quick Sort Median Element Pivot

‘Picture 2. 4 Quick Sort Random Pivot With lomuto Partition

There are also some function performance. now();


Figure 2. 2 Quick Sort First Element Pivot we use as the speed reference material from the
working process algorithm that we are going to
analyze , There are some documents. write(); we
use to make it easier for us to see the working
process of the algorithm.

C. Tool
Experimen in THIS journal was made using MSI
GL62m 7rdx laptop with the following
specifications :
Prosessor = Intel i7-7700HQ
Memory = 8 GB Dual Channel
Code Editor = Visual Studio Code
Browser = Opera GX
3. Testing
the 4 Types of Quick sort will be 10 times for
each type of quick sort. For each type of Quick
sort will be created a graph of 10 times the
experiment to see its performance level and look
for the average value of each type of Quick Sort
to .

Picture 2. 3 Quick Sort Last Element Pivot


yyResults and discussion 6 20.75
After the first test i will show the Output results 7 14.92
of each program already created
8 23.57
9 23.96
10 25.72
Average 19.96
Table 3.1 table of the Quick Sort Median Element Pivot
Results
In the table above , we know that with the pivot in the
3.1 image Quick Sort Median Element Pivot Middle of the fastest time recorded 14.37 in the Green
part, the late time noted 25.72 on the red part and the time
Average 19.96 in the Yellow part

50 Quick Sort Median


Element Pivot

Waktu
Output Results
3.2 Images of Quick Sort First Element Pivot 0
Output 1 2 3 4 5 6 7 8 9 10
Waktu
Percobaan

3.3 Images of Quick Sort Last Element Pivot Output 3.5 image Quick Sort Random Pivot With Lomuto
Partition performance graph
Experiment Time
1 13.76
2 15.49
3 13.78
4 23.43
5 14.65
6 21.16
3.4
7 19.53
8 20.21
Images Quick Sort Random Pivot With lomuto Partition 9 17.12
Output Result
10 21.23
After the output result of each program, This is a
table of results 10 times the experiment of each Average 18.04
type of Quick Sort
Table 3.2 Quick Sort First Element Pivot table results
Experiment Time
In the table above , we know that with the pivot in the
1 19.49 Middle of the fastest time recorded 13.78 in the Green
part, the late time noted 23.43 on the red part and the time
2 18.78 Average 18.04 in the Yellow part
3 16.44
4 14.37
5 21.56
3.7 Image Quick Sort Last Element Pivot Performance
30 Quick Sort First Element chart

Pivot Experiment Time


20
Waktu

1 15.36
10 2 16.06
3 21.34
0
1 2 3 4 5 6 7 8 9 10 4 15.67
Percobaan
Waktu 5 18.31
6 18.59
3.6 Image Quick Sort First Element Pivot Performance
7 20.87
chart
8 13.11

Experiment Time 9 14.82

1 19.04 10 28.38

2 23.08 Average 18.25

3 19.62 3.4 Table of Quick Sort Random Pivot With lomuto


Partition result table
4 17.17
In the table above , we know that with the pivot in the
5 19.28 Middle of the fastest time recorded 13.11 in the Green
part, the late time noted 28.38 on the red part and the time
6 18.92 Average 18.25 in the Yellow part
7 17.84
8 27.55 Quick Sort Random Pivot With
30
9 21.82 Lomuto Partition
25
10 19.79
20
Waktu

Average 20.41
15
Table 3.3 table result of Quick Sort Last Element Pivot
10
In the table above , we know that with the pivot in the
5
Middle of the fastest time recorded 18.92 in the Green
part, the late time noted 27.55 on the red part and the time 0
Average 2.41 in the Yellow part 1 2 3 4 5 6 7 8 9 10
Percobaan
Waktu
30 Quick Sort Last Element
Gambar 3.8 Grafik Performa Quick Sort Random Pivot With
Pivot Lomuto Partition
20
From the image above we can see
Waktu

4. Conclusion
10
In this journal it can be concluded that each type
of Quick Sort has its own return . If you need a
0 Sorting algorithm that is choused then is Choose
1 2 3 4 5 6 7 8 9 10 Quick Sort First Element pivot, but if the level of
Percobaan Reliability then use the quick sort Median element
Waktu
pivot, and from for the Sorting algorithm that has
performance the worst is the Quick Sort random
Pivot With lomuti Partition because it corresponds
to its name the pivotal position is random , so it is
less effective to sort The data quite a lot.
5. Bibliography
freeCodeCamp. (n.d.). Quick Sort. Retrieved from
https://guide.freecodecamp.org/algorithms/sorting-
algorithms/quick-sort/.
MahapatraIntern, S., & Mahapatra, S. (2019,
September 25). QuickSort using Random Pivoting.
Retrieved from
https://www.geeksforgeeks.org/quicksort-using-
random-pivoting/.
Paul, R. (2018, January 11). Quick-Sort Algorithm
in JavaScript. Retrieved from https://rohan-
paul.github.io/javascript/2018/01/11/Quick-
Sort_Algorithm-in-JavaScript/.
QuickSort. (2019, August 23). Retrieved from
https://www.geeksforgeeks.org/quick-sort/. 1
Jensen, K. (2018, February 20). Javascript
Algorithms - Quicksort. Retrieved from
https://medium.com/javascript-
algorithms/javascript-algorithms-quicksort-
beb3169c4d4.

You might also like