SlideShare a Scribd company logo
CS 321. Algorithm Analysis & Design
Lecture 4
Heap Sort
4 9 2 1 8 5 6
4 9 2 1 8 5 6
4 9 2
1
8 5 6
4 9 2
1
8 5 6
4 9
21
8 5 6
4 9
21
8 5 6
4
9
21
8 5 6
4
9
21
8 5 6
4
9
21
8
5
6
4
9
21
8
5
6
4
9
21
8
5 6
4
9
21
8
5 6
4
9
21 85 6
4
9
21 85 6
4 921 85 6
4 921 85 6
Can we speed up the find-min operations?
4
9
21
8
5
6
Organize the elements so that finding minimum is “easy”.
4
9
21
8
5
6
Organize the elements so that deleting the minimum
element is “easy”.
Store a set of n distinct numbers.
Inserting a new element and deleting the minimum
element can be done in time proportional to (log n).
GOAL
All jumbled up
4 9 2 1 8
All jumbled up
4 9 2 1 8 3
All jumbled up
4 9 2 1 8 3 6
All jumbled up
4 9 2 1 8 3
Insert: O(1)
6
All jumbled up
4 9 2 1 8 3
Insert: O(1) Delete-Min: O(n)
6
All sorted
9 8 6 3 1
All sorted
9 8 6 3
All sorted
9 8 6 3
Delete-Min: O(1)
All sorted
9 8 6 3
Delete-Min: O(1)
4
All sorted
9 8 6 3
Delete-Min: O(1)
47
All sorted
9 8 6 3
Insert: O(n) Delete-Min: O(1)
47
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
In-between?
Invariant: The first element of
the array is the minimum.
4
9
21
8
5
6
6
1
59
24
8
x is a child of y: x is larger than y.
6
1
59
24
8
6
1
59
24
8
6
1
59
24
8
61 5924 8
61 5924 8
6
1
59
24
8
61 5924 8
6
1
59
24
8
1
2 3
4 5 6 7
1 2 3 4 5 6 7
61 5924 8
6
1
59
24
8
1
2 3
4 5 6 7
1 2 3 4 5 6 7
left-child(i) = 2i
61 5924 8
6
1
4
1
2
4
1 2 3 4 5 6 7
61 5924 8
6
1
4
1
2
4
1 2 3 4 5 6 7
left-child(i) = 2i
left-child(i) = 2i
left-child(i) = 2i
i
2i
left-child(i) = 2i
i+k
2i + 2k
i
2i
6
1
59
24
8
Delete Min
6 1
5
9
24
8
Delete Min
6 1
5
9
24
8
Delete Min
6 1
5
9
24
8
Delete Min
6 1
5
9
24
8
Delete Min
6 1
5
9
24
8
Delete Min
6 1
5
9
2
4
8
Delete Min
6 1
2
9
54
8
Delete Min
6
2
9
54
8
Insert
6
3
2
9
54
8
Insert
6 3
2
9
54
8
Insert
6 3
2
9
54
8
Insert
6
3
2
9 5
4
8
Insert
6
3
2
9 5
4
8
Insert
Heapify

More Related Content

PPT
PDF
LEC 8-DS ALGO(heaps).pdf
PPTX
Kruskal & Prim's Algorithm
PPT
PPT
PPTX
sorting algorithm graphical method
PPT
Minimum Spanning Tree
PDF
one main advantage of bubble sort as compared to others
LEC 8-DS ALGO(heaps).pdf
Kruskal & Prim's Algorithm
sorting algorithm graphical method
Minimum Spanning Tree
one main advantage of bubble sort as compared to others

What's hot (20)

PDF
Sorting
PPT
2.4 mst prim’s algorithm
PPTX
A presentation on prim's and kruskal's algorithm
PDF
05 - 18 Jan - The Sorting Wrap-Up
PPTX
Sorting ppt
PDF
PPTX
Radix sorting
PDF
Work-stealing Tree Data Structure
PDF
Smalltalk
PPT
Searching algorithms
PPTX
Merge sort
PPT
Stacks overview with its applications
PPTX
Sorting2
PDF
Ctrie Data Structure
PPTX
Sign Sign 2
Sorting
2.4 mst prim’s algorithm
A presentation on prim's and kruskal's algorithm
05 - 18 Jan - The Sorting Wrap-Up
Sorting ppt
Radix sorting
Work-stealing Tree Data Structure
Smalltalk
Searching algorithms
Merge sort
Stacks overview with its applications
Sorting2
Ctrie Data Structure
Sign Sign 2
Ad

Viewers also liked (7)

PPT
Computer notes - Maze Generator
PDF
06 - 20 Jan - Divide and Conquer
PPTX
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
PDF
PPT
Notes DATA STRUCTURE - queue
PPT
Queue Data Structure
PPT
Queue data structure
Computer notes - Maze Generator
06 - 20 Jan - Divide and Conquer
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Notes DATA STRUCTURE - queue
Queue Data Structure
Queue data structure
Ad

Similar to 04 - 15 Jan - Heap Sort (20)

PPTX
2.Problem Solving Techniques and Data Structures.pptx
PPT
PDF
Sorting
PPTX
data structures and algorithms Unit 3
PDF
01 - 01 January - Sorting
PPTX
Data analysis and algorithms - UNIT 2.pptx
PPT
Chapter three data structure and algorithms qaybta quee
PPTX
Heaps and tries power point this is an educational material
PDF
Skiena algorithm 2007 lecture07 heapsort priority queues
PPTX
Algorithm & data structures lec4&5
PDF
Elementary algorithms
PPTX
data_structure_Chapter two_computer.pptx
PPTX
L2_DatabAlgorithm Basics with Design & Analysis.pptx
PPTX
chapter-4,5.pptxalgorithmalgorithmalgorithm
PDF
Sorting (introduction)
PDF
Basics in algorithms and data structure
PPTX
Sorting Algorithm
2.Problem Solving Techniques and Data Structures.pptx
Sorting
data structures and algorithms Unit 3
01 - 01 January - Sorting
Data analysis and algorithms - UNIT 2.pptx
Chapter three data structure and algorithms qaybta quee
Heaps and tries power point this is an educational material
Skiena algorithm 2007 lecture07 heapsort priority queues
Algorithm & data structures lec4&5
Elementary algorithms
data_structure_Chapter two_computer.pptx
L2_DatabAlgorithm Basics with Design & Analysis.pptx
chapter-4,5.pptxalgorithmalgorithmalgorithm
Sorting (introduction)
Basics in algorithms and data structure
Sorting Algorithm

More from Neeldhara Misra (13)

PDF
Erdos Posa Theorem
PDF
15 - 12 Feb - Stable Matchings
PDF
07- 22 Jan - Divide and Conquer
PDF
10 - 29 Jan - Recursion Part 2
PDF
02 - 04 Jan - Sorting (Continued)
PDF
08 - 25 Jan - Divide and Conquer
PDF
13 - 06 Feb - Dynamic Programming
PDF
00 - 30 Dec - Introduction
PDF
14 - 08 Feb - Dynamic Programming
PDF
11 - 03 Feb - From Recursion to Dynamic Programming
PDF
09 - 27 Jan - Recursion Part 1
PDF
04 - 15 Jan - Heap Sort
PDF
12 - 05 Feb - Dynamic Programming
Erdos Posa Theorem
15 - 12 Feb - Stable Matchings
07- 22 Jan - Divide and Conquer
10 - 29 Jan - Recursion Part 2
02 - 04 Jan - Sorting (Continued)
08 - 25 Jan - Divide and Conquer
13 - 06 Feb - Dynamic Programming
00 - 30 Dec - Introduction
14 - 08 Feb - Dynamic Programming
11 - 03 Feb - From Recursion to Dynamic Programming
09 - 27 Jan - Recursion Part 1
04 - 15 Jan - Heap Sort
12 - 05 Feb - Dynamic Programming

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
master seminar digital applications in india
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Cell Structure & Organelles in detailed.
PDF
Complications of Minimal Access Surgery at WLH
PDF
Basic Mud Logging Guide for educational purpose
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Microbial disease of the cardiovascular and lymphatic systems
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
master seminar digital applications in india
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
TR - Agricultural Crops Production NC III.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
RMMM.pdf make it easy to upload and study
Renaissance Architecture: A Journey from Faith to Humanism
Module 4: Burden of Disease Tutorial Slides S2 2025
Cell Structure & Organelles in detailed.
Complications of Minimal Access Surgery at WLH
Basic Mud Logging Guide for educational purpose
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Final Presentation General Medicine 03-08-2024.pptx

04 - 15 Jan - Heap Sort