Вы находитесь на странице: 1из 11

Demonstration of

heap & quick


sorting techniques
Presented by:
Group No-22, Section-3C
Roll no.s-57,16
Contents
Quick sort

• Algorithm for Quick sort


• Visualization of Quick sort

Heap sort

• Algorithm for Heap sort


• Visualization of Heap sort

References
Quick Sort

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.
Algorithm for Quick Sort

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
Visualisation of Quick Sort
10,90,40,30,5
0

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

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


Heap Sort

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.
Algorithm for Heap Sort

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.
How to construct a heap
tree?
Given elements:9,10,12,4,7,6 9

10 12

4 7 6
Visualization of Heap Sort
References

 http://www.geeksforgeeks.org/sort
ing-algorithm
 https://www.programiz.com/dsa/h
eap-sort
 www.algolist.net/Algorithms/Sortin
g/Quicksort
Thank You

Вам также может понравиться