You are on page 1of 15

SCHOOL OF COMPUTING SCEINCE

Course Code: BTCS9211 Course Name: Analysis And Design Algorithm

TOPIC:- How to improve QUICK SORT Algorithm

PRESENATATION FOR
CAT-3

PRESENTED BY –

JYOTI BHIST : 21SCSE1010461


LOKENDERA SINGH : 21SCSE1011516
KM CHANDNI SINGH : 21SCSE1010721

Faculty Name: Mr. S. Ramesh


SCHOOL OF COMPUTING
Name of the School SCEINCE
Course Code:
Course Code: : BTCS9211
BTCS9211 Course
Course Name And Design Algorithm
Name: Analysis

INTRODUCTION
Course Code: BTCS9211 Course Name: Analysis And Design
ItAlgorithm
is used on the principle of divide-and-conquer. Quick sort is an algorithm of choice in
many situations as it is not difficult to implement. It is a good general purpose sort and it
consumes relatively fewer resources during execution.
A large array is partitioned into two arrays one of which holds values smaller than the specified value,
say pivot, based on which the partition is made and another array holds values greater than the pivot
value. Quicksort partitions an array and then calls itself recursively twice to sort the two resulting
subarrays.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design Algorithm

Working
The variable you want to predict is called the dependent variable. The variable you are
using to predict the other variable's value is called the independent variable.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Quick Sort Algorithm
Analysis-
To find the location of an element that splits the array into two parts, O(n) operations are required.
This is because every element in the array is compared to the partitioning element.
After the division, each section is examined separately.
If the array is split approximately in half (which is not usually), then there will be log(n) splits.
Therefore, total comparisons required are f(n) = n x log(n) = O(nlog(n)).

Order of Quick Sort = O(nlog(n))


SCHOOL OF COMPUTING SCEINCE

Course Code: BTCS9211 Course Name: Analysis And Design


Algorithm

Worst Case-
Quick Sort is sensitive to the order of input data.It gives the worst performance when
elements are already in the ascending order.
It then divides the array into sections of 1 and (n-1) elements in each call.
Then, there are (n-1) divisions in all.
Therefore, here total comparisons required are f(n) = n x (n-1) = O(n2).

Order of Quick Sort in worst case = O(n2)


SCHOOL OF COMPUTING SCEINCE

Course Code: BTCS9211 Course Name: Analysis And Design Algorithm

Advantages :
• It is in-place since it uses only a small auxiliary stack.

• It requires only n (log n) time to sort n items.


• It has an extremely short inner loop.
• This algorithm has been subjected to a thorough mathematical analysis, a very precise
statement can be made about performance issues.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
Disadvantage :
• It is recursive. Especially, if recursion is not available, the implementation is extremely
complicated.
• It requires quadratic (i.e., n2) time in the worst-case.
• It is fragile, i.e. a simple mistake in the implementation can go unnoticed and cause it to

perform badly.
• It is not stable sort i.e the order of equal elements may not be preserved.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

The problem is discussed of how the use of a new data structure,


the codeword structure, can help improve the performance of
quicksort when the records to be sorted are long and the keys are
alphanumeric sequences of bytes.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

1) Architecture-Independent Features:
The codewordbased routines require a slightly smaller number of
comparisons, the comparisons are on shorter entities, and the
number of swaps is also reduced. Moreover, the elements
to be compared, the codewords, can be accessed directly
rather than indirectly, as in the case of keys accessed
through pointers to records.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

1) Architecture-Independent Features:
The codewordbased routines require a slightly smaller number of
comparisons, the comparisons are on shorter entities, and the
number of swaps is also reduced. Moreover, the elements
to be compared, the codewords, can be accessed directly
rather than indirectly, as in the case of keys accessed
through pointers to records.
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

2) Architecture-Dependent Features:
The codewordbased routines increase the spatial locality of the
program and thus take better advantage cf caches and TLB’s. The
improvement increases with the sophistication of the architecture
(copy-back cache and large block size).
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

2) Architecture-Dependent Features:
The codewordbased routines increase the spatial locality of the
program and thus take better advantage cf caches and TLB’s. The
improvement increases with the sophistication of the architecture
(copy-back cache and large block size).
SCHOOL OF COMPUTING SCEINCE
Course Code: BTCS9211 Course Name: Analysis And Design
Algorithm
CodeWord Data Structure :

3) Compiler Optimization:
In-line expansion of short procedures and hints for register allocation
have a beneficial effect (although this benefit is also present for
pointer-based routines).
SCHOOL OF COMPUTING SCEINCE

Course Code: BTCS9211 Course Name: Analysis And Design


Algorithm

Conclusion:

Quick Sort method sorts the elements using the Divide and Conquer approach and has an average
O(nLogn) complexity.
It can be implemented in both recursive and iterative way. It is in-place, cache-friendly and also a tail-
recursive algorithm.
SCHOOL OF COMPUTING SCEINCE

Course Code: BTCS9211 Course Name: Analysis And Design


Algorithm

THANK YOU

You might also like