You are on page 1of 12

Presented by:

Group No-33., Section-3C


Roll no.s-21,71
Quick sort
• Algorithm for Quick sort
• Visualization of Quick sort

Heap sort
• Algorithm for Heap sort
• Visualization of Heap sort

Comparison between heap and


quick sort

References
The fundamentals of quick sort are:
 Quick Sort is a Divide and Conquer algorithm.
 It picks an element as pivot and partitions the given
array around the picked pivot.
 There are many different versions of quicksort that
pick pivot in different ways. In this presentation we
have chosen the last element as the pivot.
 Continue partitioning the array using the pivot until
there is one element left.
STEP 1. Choosing the pivot
Example : 8, 3, 25, 6,10
Here the last element 10 is the pivot.
STEP 2. Partitioning
 Entries less than the pivot are placed on the left.
 Entries greater than the pivot are placed on the right.
Example : 3,8,6≤10≤25
STEP 3. Recursively quick sort the left and right parts.
Example:3,8,⑥≤10≤25 [ Now 6 is the pivot on the left part ]
3≤6≤8≤10≤25
So the final sorted array:3,6,8,10,25
10,90,40,30,50

10,40,30 90
Pivot
Partition
Partition around 50
around 30
40
10

The sorted list is : 10,30,40,50,90


The fundamentals of heap sort are:
 Heap sort is a comparison based sorting technique
based on Binary Heap data structure.
 It is similar to selection sort where we first find the
maximum element and place the maximum element at
the end.
 We repeat the same process for remaining elements.
Step 1.Create a heap tree from the given elements.
Step 2.Transform the heap tree into a max heap tree.
[In a Max heap , parent node ≥ child node]
Step 3.Swap the first and last node and delete the last
node from heap.
Step 4.Recursively perform heap sort until there is one
element left.
Given elements:9,10,12,4,7,6
9

10 12

4 7 6
• Method : It is an  Method : It is a
efficient version of divide and conquer
selection sort. technique.

 Complexity:  Complexity:
 Best Case:Ω(n log n)  Best Case:θ(n log n)
 Worst Case :O(n log n)  Worst Case :θ (n2)
 http://www.geeksforgeeks.org/sorting-algorithm
 https://www.programiz.com/dsa/heap-sort
 www.algolist.net/Algorithms/Sorting/Quicksort

You might also like