Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2012
1
Contents
Figures 2
Tables 2
CERTIFICATE OF ORIGINALITY 3
Acknowledgement 4
Abstract 5
Introduction 5
What is Quicksort 6
Speed Up Ratio 8
Conclusion 10
2
Figures
Tables
CERTIFICATE OF ORIGINALITY
independent and original work. I have duly acknowledged all the sources from which the
ideas and extracts have been taken. The project is free from any plagiarism and has not
E-mail: 201852031@iiitvadodara.ac.in
4
Acknowledgement
The success and final outcome of this project required a lot of guidance and assistance
from many people and I am extremely privileged to have got this all along the completion of
my project. All that I have done is only due to such supervision and assistance and I would
I would like to express my deepest appreciation to all those who provided me the
possibility to complete this report. A special gratitude I give to our Course Instructor ,Mr
Lastly, I thank almighty, my parents, and friends for their constant encouragement
Abstract
partition is carried out dynamically. Quicksort is a comparision sort and is popular because
it is not difficult to implement, works well for a variety of different kinds of input data, and
is substantially faster than any other sorting method in typical applications.The method
compares very favourably with other known methods in speed, in economy of storage, and
in ease of programming.
Introduction
One of the basic areas of the computer science is Data Structure. Sorting is an
important issue in Data Structure which creates the sequence of the list of items. Although
numbers of sorting algorithms are available, it is all the more necessary to select the best
sorting algorithm. Therefore, sorting problem has attracted a great deal of research as sorting
technique is very often used in a large variety of important applications so as to arrange the
data in ascending or descending order. This paper presents that sorting is an important area
of study in computer science. Like searching, the efficiency of a sorting algorithm is related
With the appearance of parallel computing, new possibilities have appeared to remove
this bottleneck and improve the performance of known sorting algorithms [1] by modifying
them for parallel execution. At first, this was achieved using distributed computing, however
with the hardware available today, it is possible to do this even on home computers thanks
to their multicore processors. In this report, we discuss a parallel version of the well know
quicksort algorithm and compare its performance to the performance of its simpler, sequential
6
quicksort algorithm. Comparing their performance, we look for the threshold T, the size
of the array, at which the parallel algorithm becomes actually slower than the sequential
algorithm.
What is Quicksort
The quicksort algorithm was developed in 1960 by Sir Charles A. R. Hoare commonly
known asTony Hoare while in the Soviet Union.Quicksort is a divide and conquer algorithm.
Quicksort first divides a large array into two smaller sub-arrays: the low elements and the
high elements. Quicksort can then recursively sort the sub-arrays. The steps are:
2. Partitioning: reorder the array so that all elements with values less than the pivot
come before the pivot, while all elements with values greater than the pivot come after it
(equal values can go either way). After this partitioning, the pivot is in its final position.
3. Recursively apply the above steps to the sub-array of elements with smaller values
The base case of the recursion is arrays of size zero or one, which are in order by
The pivot selection and partitioning steps can be done in several different ways; the
Mathematical analysis of quicksort shows that, on average, the algorithm takes O(n
log n) comparisons to sort n items. In the worst case, it makes O(n2) comparisons, though
task parallelism[2]. The partitioning step is accomplished through the use of a parallel prefix
sum algorithm to compute an index for each array element in its section of the partitioned
array. Given an array of size n, the partitioning step performs O(n) work in O(log n) time
and requires O(n) additional scratch space. After the array has been partitioned, the two
partitions can be sorted recursively in parallel. Assuming an ideal choice of pivots, parallel
quicksort sorts an array of size n in O(n log n) work in O(log 2 n) time using O(n) additional
space.
like merge sort, which complicate its efficient parallelization[3]. The depth of quicksort’s
divide-and-conquer tree directly impacts the algorithm’s scalability, and this depth is highly
as compared to a sequential algorithm are the overhead caused by the need to create new,
The parallel implementation is only slightly different. First, the size of the array to
be sorted is checked against a threshold. If the size is smaller than the threshold, sequential
quicksort is used as the overhead of creating new tasks would slow the sorting process too
much. If the size of the array is bigger than the threshold, instead of calling the quicksort for
8
each part directly, new Task is created for each of the call and let’s them handle the sorting
With the threshold set at 50000, the parallel algorithm is actually slower, as the
computational cost of creating new tasks increases the total run time, but the parallelism is
not utilized enough to offset this. The use of scratch space simplifies the partitioning step,
Speed Up Ratio
Speedup is defined as the ratio of the worst-case execution time of the fastest known se-
9
quential algorithm for a particular problem to the worst-case execution time of the parallel
algorithm.
Speed up formula:
As can be see here, at low number of elements no speed up is achieved. As the number
of elements increases, the speed of sorting actually decreases. This is caused as stated before
by the overhead needed for creating the parallel tasks and as there is not enough elements
for the parallelism being able to compensate for this. After the number of elements increases
enough, the overall speed and speed gain increases as well by about 20%.
10
Conclusion
a appropriate threshold value to switch from parallel to sequential sorting, we observed the
performance of the algorithm. The results are obviously in favor of the parallel quicksort
circumvent the increased computational cost of creating new tasks for small datasets, while
with the bigger datasets we take advantage of the parallelism possible by today’s hardware.
References
[1] Steven S Skiena. Sorting and searching. In The Algorithm Design Manual, pages 103–144.
Springer, 2012.
[2] Philippas Tsigas and Yi Zhang. A simple, fast parallel implementation of quicksort and
its performance evaluation on sun enterprise 10000. In Eleventh Euromicro Con-
ference on Parallel, Distributed and Network-Based Processing, 2003. Proceedings.,
pages 372–381. IEEE, 2003.