+ All Categories
Home > Engineering > Quick Sort

Quick Sort

Date post: 06-Apr-2017
Category:
Upload: shweta-sahu
View: 85 times
Download: 1 times
Share this document with a friend
14
QUICK SORT BY RANDOMIZE ALGORITM MADE BY : SHWETA SAHU 4 th Semester
Transcript
Page 1: Quick Sort

QUICK SORT BYRANDOMIZE ALGORITM

MADE BY : SHWETA SAHU 4th Semester

0176CS131066

Page 2: Quick Sort

Sorting is any process of arranging items according to a certain sequence or in different sets, and therefore, it has two common, yet distinct meanings:

Ordering: arranging items of the same kind, class or nature, in some ordered sequence,

Categorizing: grouping and labeling items with similar properties together (by sorts).

SORTING

Page 3: Quick Sort

Quick sort is an algorithm for sorting a list or array.

It is an efficient sorting algorithm serving as a systematic method for placing the elements of an array in order.

It was developed by Tony Hoare in 1960.

It is sometimes called partition exchange sort.

It is a divide and conquer algorithm.

QUICK SORT

Page 4: Quick Sort

Pick an element, called a pivot, from the array.

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 . After this partitioning, the pivot is in its final position. This is called the partition operation.

Recursively apply the above steps to the sub-array of elements with smaller values and separately to the sub-array of elements with greater values.

QUICK SORT ALGORITHM

Page 5: Quick Sort

For eg. the array is :- 25 11 43 67 91 55 15

25 11 43 67 91 55 15

PIVOT

25 11 15 43 67 91 55

No. smallerthan pivot

No. greaterthan pivotPivot

Page 6: Quick Sort

25 11 15 43 67 91 55

11 15 25 43 67 91 55

11 15 25 43 67 91 55

Page 7: Quick Sort

11 15 25 43 67 91 55

11 15 25 43 55 67 91

11 15 25 43 55 67 91

Sorted list

Page 8: Quick Sort

Algorithm

RANDOMIZED ALGORITHM

Input Output

Random number

• In addition to the input, the algorithm uses a source of random numbers. During execution, it takes random choices depending on those random numbers.

• The behavior (output) can vary if the algorithm is run multiple times on the same input

Page 9: Quick Sort

Randomized algorithm can be categorized into two classes:-1. Las Vegas algorithms: These type of

algorithms always produce the same(correct) output for same input.

2. Monte Carlo algorithms: The output of such algorithms might differ from run to run for same input.

CONTINUE…..

Page 10: Quick Sort

Exchange A[r] with an element chosen at random from A[p…r] in Partition.

The pivot element is equally likely to be any of input elements.

For any given input, the behavior of Randomized Quick Sort is determined not only by the input but also by the random choices of the pivot.

We add randomization to Quick Sort to obtain for any input the expected performance of the algorithm to be good.

RANDOMIZED QUICK SORT

Page 11: Quick Sort

A[p..r]

5

Partition

A[p..q – 1] A[q+1..r]

5

5 5

Page 12: Quick Sort

The algorithm is usually simple and easy to implement,

The algorithm is fast with very high probability, and/or

It produces optimum output with very high probability.

ADVANTAGES

Page 13: Quick Sort

There is a finite probability of getting incorrect answer..

Getting truly random numbers is impossible. One needs to depend on pseudo random numbers. So, the result highly depends on the quality of the random numbers.

DISADVANTAGES

Page 14: Quick Sort

Recommended