SlideShare a Scribd company logo
CS 321. Algorithm Analysis & Design
Lecture 5
The Sorting Wrap-Up
19 1 2 13 8 5 6 3 12 11 7 16
19 1 2 13 8 5 6 3 12 11 7 16
19
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8 5 6
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8 5 6
3 12 11 7 16
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8 5 6
3 12 11 7 16
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8 5 6
3 12 11 7 16
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8 5 6
3 12 11 7 16
19 1 2 13 8 5 6 3 12 11 7 16
19
1 2
13 8
5
6
3 12 11 7
16
19 1 2 13 8 56 3 12 11 716
19
1 2
13 8
5
6
3 12 11 7
16
19 1 2 13 8 56 3 12 11 716
19
1 2
13 8
5
6
3 12 11 7
16
19 1 2 13 8 56 3 1211 716
19
1 2
13
8 5
6
3 12
11
7
16
19 1 2 13 8 56 3 1211 716
19
1 2
13
8 5
6
3 12
11
7
16
19 1 2 13 8 56 3 1211 716
19
1 2
13
8 5
6
3 12
11
7
16
19 1 213 8 56 3 1211 716
19
1
213
8 5
6
3 12
11
7
16
19 1 213 85 6 3 1211 716
19
1
2
13
8
5 6
3 12
11
7
16
19 1 213 85 6 3 1211 716
19
1
2
13
8
5 6
3 12
11
7
16
19 1 213 85 6 3 1211 716
19
1
2
13
8
5 6
3 12
11
7
16
19 1 213 85 6 312 11 716
19
1 2
13
8
5 6
3
12 11
7
16
19 1 213 85 6 312 11 716
19
1 2
13
8
5 6
3
12 11
7
16
Node at height h has to move
at most h steps to find its place.
Node at height h has to move
at most h steps to find its place.
Number of nodes at height h?
Node at height h has to move
at most h steps to find its place.
Number of nodes at height h?
2(log n - h)
Node at height h has to move
at most h steps to find its place.
Number of nodes at height h?
2(log n - h)
Overall running time (summed over h):
Node at height h has to move
at most h steps to find its place.
Number of nodes at height h?
2(log n - h)
n(h/2(h))
Overall running time (summed over h):
Node at height h has to move
at most h steps to find its place.
Number of nodes at height h?
2(log n - h)
n(h/2(h))
Overall running time (summed over h):
Heapify: Turns out to be a linear effort overall.
19 1 2 13 8 5 6 3 12 11 7 16
19
13 16
12 11 5 6
3 1 8 7 2
19 1 2 13 8 5 6 3 12 11 7 16
19
13 16
12 11 5 6
3 1 8 7 2
To sort,
repeatedly extract the
maximum element
to the end of the array.
An O(n log n) effort.
Finding Medians
Finding Medians
using heaps
19
13 16
12 11 5 6
3 1 8 7 2
19 13 16 12 11 5 6 3 1 8 7 2
Store the first (n/2)
elements in a max-heap.
Store the last (n/2)
elements in a min-heap.

More Related Content

Viewers also liked

10 - 29 Jan - Recursion Part 2
10 - 29 Jan - Recursion Part 210 - 29 Jan - Recursion Part 2
10 - 29 Jan - Recursion Part 2
Neeldhara Misra
 
Heaps
HeapsHeaps
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
05 Analysis of Algorithms: Heap and Quick Sort - Corrected05 Analysis of Algorithms: Heap and Quick Sort - Corrected
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
Andres Mendez-Vazquez
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
Deepak John
 
lecture 5
lecture 5lecture 5
lecture 5
sajinsc
 
Heap sort
Heap sortHeap sort
Heap sort
Jose Solorzano
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Traian Rebedea
 
Heap sort
Heap sort Heap sort
Heapsort
HeapsortHeapsort
Heapsort
mmoylan
 

Viewers also liked (9)

10 - 29 Jan - Recursion Part 2
10 - 29 Jan - Recursion Part 210 - 29 Jan - Recursion Part 2
10 - 29 Jan - Recursion Part 2
 
Heaps
HeapsHeaps
Heaps
 
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
05 Analysis of Algorithms: Heap and Quick Sort - Corrected05 Analysis of Algorithms: Heap and Quick Sort - Corrected
05 Analysis of Algorithms: Heap and Quick Sort - Corrected
 
Analysis and design of algorithms part2
Analysis and design of algorithms part2Analysis and design of algorithms part2
Analysis and design of algorithms part2
 
lecture 5
lecture 5lecture 5
lecture 5
 
Heap sort
Heap sortHeap sort
Heap sort
 
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic ProgammingAlgorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
Algorithm Design and Complexity - Course 4 - Heaps and Dynamic Progamming
 
Heap sort
Heap sort Heap sort
Heap sort
 
Heapsort
HeapsortHeapsort
Heapsort
 

Similar to 05 - 18 Jan - The Sorting Wrap-Up

UCSD NANO106 - 06 - Plane and Space Groups
UCSD NANO106 - 06 - Plane and Space GroupsUCSD NANO106 - 06 - Plane and Space Groups
UCSD NANO106 - 06 - Plane and Space Groups
University of California, San Diego
 
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
AIST
 
Analisis dinamico de un portico
Analisis dinamico de un porticoAnalisis dinamico de un portico
Analisis dinamico de un portico
ARTHUR ANTONY ALBA ROSALES
 
Hardware Description Languages .pptx
Hardware Description Languages .pptxHardware Description Languages .pptx
Hardware Description Languages .pptx
wafawafa52
 
Self-managed and automatically reconfigurable stream processing
Self-managed and automatically reconfigurable stream processingSelf-managed and automatically reconfigurable stream processing
Self-managed and automatically reconfigurable stream processing
Vasia Kalavri
 
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
Flink Forward
 
Fast updating GG.pptx
Fast updating GG.pptxFast updating GG.pptx
Fast updating GG.pptx
VarshithVarma2
 
Identification of unknown parameters and prediction of missing values. Compar...
Identification of unknown parameters and prediction of missing values. Compar...Identification of unknown parameters and prediction of missing values. Compar...
Identification of unknown parameters and prediction of missing values. Compar...
Alexander Litvinenko
 
LEC 8-DS ALGO(heaps).pdf
LEC 8-DS  ALGO(heaps).pdfLEC 8-DS  ALGO(heaps).pdf
LEC 8-DS ALGO(heaps).pdf
MuhammadUmerIhtisham
 

Similar to 05 - 18 Jan - The Sorting Wrap-Up (9)

UCSD NANO106 - 06 - Plane and Space Groups
UCSD NANO106 - 06 - Plane and Space GroupsUCSD NANO106 - 06 - Plane and Space Groups
UCSD NANO106 - 06 - Plane and Space Groups
 
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
Valeri Labunets - Fast multiparametric wavelet transforms and packets for ima...
 
Analisis dinamico de un portico
Analisis dinamico de un porticoAnalisis dinamico de un portico
Analisis dinamico de un portico
 
Hardware Description Languages .pptx
Hardware Description Languages .pptxHardware Description Languages .pptx
Hardware Description Languages .pptx
 
Self-managed and automatically reconfigurable stream processing
Self-managed and automatically reconfigurable stream processingSelf-managed and automatically reconfigurable stream processing
Self-managed and automatically reconfigurable stream processing
 
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
Self Managed and Automatically Reconfigurable Stream Processing - Vasiliki Ka...
 
Fast updating GG.pptx
Fast updating GG.pptxFast updating GG.pptx
Fast updating GG.pptx
 
Identification of unknown parameters and prediction of missing values. Compar...
Identification of unknown parameters and prediction of missing values. Compar...Identification of unknown parameters and prediction of missing values. Compar...
Identification of unknown parameters and prediction of missing values. Compar...
 
LEC 8-DS ALGO(heaps).pdf
LEC 8-DS  ALGO(heaps).pdfLEC 8-DS  ALGO(heaps).pdf
LEC 8-DS ALGO(heaps).pdf
 

More from Neeldhara Misra

Erdos Posa Theorem
Erdos Posa TheoremErdos Posa Theorem
Erdos Posa Theorem
Neeldhara Misra
 
15 - 12 Feb - Stable Matchings
15 - 12 Feb - Stable Matchings15 - 12 Feb - Stable Matchings
15 - 12 Feb - Stable Matchings
Neeldhara Misra
 
07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer
Neeldhara Misra
 
02 - 04 Jan - Sorting (Continued)
02 - 04 Jan - Sorting (Continued)02 - 04 Jan - Sorting (Continued)
02 - 04 Jan - Sorting (Continued)
Neeldhara Misra
 
04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort
Neeldhara Misra
 
08 - 25 Jan - Divide and Conquer
08 - 25 Jan - Divide and Conquer08 - 25 Jan - Divide and Conquer
08 - 25 Jan - Divide and Conquer
Neeldhara Misra
 
06 - 20 Jan - Divide and Conquer
06 - 20 Jan - Divide and Conquer06 - 20 Jan - Divide and Conquer
06 - 20 Jan - Divide and Conquer
Neeldhara Misra
 
13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming
Neeldhara Misra
 
00 - 30 Dec - Introduction
00 - 30 Dec - Introduction00 - 30 Dec - Introduction
00 - 30 Dec - Introduction
Neeldhara Misra
 
01 - 01 January - Sorting
01 - 01 January - Sorting01 - 01 January - Sorting
01 - 01 January - Sorting
Neeldhara Misra
 
14 - 08 Feb - Dynamic Programming
14 - 08 Feb - Dynamic Programming14 - 08 Feb - Dynamic Programming
14 - 08 Feb - Dynamic Programming
Neeldhara Misra
 
11 - 03 Feb - From Recursion to Dynamic Programming
11 - 03 Feb - From Recursion to Dynamic Programming11 - 03 Feb - From Recursion to Dynamic Programming
11 - 03 Feb - From Recursion to Dynamic Programming
Neeldhara Misra
 
09 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 109 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 1
Neeldhara Misra
 
04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort
Neeldhara Misra
 
12 - 05 Feb - Dynamic Programming
12 - 05 Feb - Dynamic Programming12 - 05 Feb - Dynamic Programming
12 - 05 Feb - Dynamic Programming
Neeldhara Misra
 

More from Neeldhara Misra (15)

Erdos Posa Theorem
Erdos Posa TheoremErdos Posa Theorem
Erdos Posa Theorem
 
15 - 12 Feb - Stable Matchings
15 - 12 Feb - Stable Matchings15 - 12 Feb - Stable Matchings
15 - 12 Feb - Stable Matchings
 
07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer07- 22 Jan - Divide and Conquer
07- 22 Jan - Divide and Conquer
 
02 - 04 Jan - Sorting (Continued)
02 - 04 Jan - Sorting (Continued)02 - 04 Jan - Sorting (Continued)
02 - 04 Jan - Sorting (Continued)
 
04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort
 
08 - 25 Jan - Divide and Conquer
08 - 25 Jan - Divide and Conquer08 - 25 Jan - Divide and Conquer
08 - 25 Jan - Divide and Conquer
 
06 - 20 Jan - Divide and Conquer
06 - 20 Jan - Divide and Conquer06 - 20 Jan - Divide and Conquer
06 - 20 Jan - Divide and Conquer
 
13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming13 - 06 Feb - Dynamic Programming
13 - 06 Feb - Dynamic Programming
 
00 - 30 Dec - Introduction
00 - 30 Dec - Introduction00 - 30 Dec - Introduction
00 - 30 Dec - Introduction
 
01 - 01 January - Sorting
01 - 01 January - Sorting01 - 01 January - Sorting
01 - 01 January - Sorting
 
14 - 08 Feb - Dynamic Programming
14 - 08 Feb - Dynamic Programming14 - 08 Feb - Dynamic Programming
14 - 08 Feb - Dynamic Programming
 
11 - 03 Feb - From Recursion to Dynamic Programming
11 - 03 Feb - From Recursion to Dynamic Programming11 - 03 Feb - From Recursion to Dynamic Programming
11 - 03 Feb - From Recursion to Dynamic Programming
 
09 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 109 - 27 Jan - Recursion Part 1
09 - 27 Jan - Recursion Part 1
 
04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort04 - 15 Jan - Heap Sort
04 - 15 Jan - Heap Sort
 
12 - 05 Feb - Dynamic Programming
12 - 05 Feb - Dynamic Programming12 - 05 Feb - Dynamic Programming
12 - 05 Feb - Dynamic Programming
 

Recently uploaded

A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 

Recently uploaded (20)

A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 

05 - 18 Jan - The Sorting Wrap-Up

  • 1. CS 321. Algorithm Analysis & Design Lecture 5 The Sorting Wrap-Up
  • 2. 19 1 2 13 8 5 6 3 12 11 7 16
  • 3. 19 1 2 13 8 5 6 3 12 11 7 16 19
  • 4. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2
  • 5. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6
  • 6. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6 3 12 11 7 16
  • 7. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6 3 12 11 7 16
  • 8. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6 3 12 11 7 16
  • 9. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6 3 12 11 7 16
  • 10. 19 1 2 13 8 5 6 3 12 11 7 16 19 1 2 13 8 5 6 3 12 11 7 16
  • 11. 19 1 2 13 8 56 3 12 11 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 12. 19 1 2 13 8 56 3 12 11 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 13. 19 1 2 13 8 56 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 14. 19 1 2 13 8 56 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 15. 19 1 2 13 8 56 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 16. 19 1 213 8 56 3 1211 716 19 1 213 8 5 6 3 12 11 7 16
  • 17. 19 1 213 85 6 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 18. 19 1 213 85 6 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 19. 19 1 213 85 6 3 1211 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 20. 19 1 213 85 6 312 11 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 21. 19 1 213 85 6 312 11 716 19 1 2 13 8 5 6 3 12 11 7 16
  • 22.
  • 23. Node at height h has to move at most h steps to find its place.
  • 24. Node at height h has to move at most h steps to find its place. Number of nodes at height h?
  • 25. Node at height h has to move at most h steps to find its place. Number of nodes at height h? 2(log n - h)
  • 26. Node at height h has to move at most h steps to find its place. Number of nodes at height h? 2(log n - h) Overall running time (summed over h):
  • 27. Node at height h has to move at most h steps to find its place. Number of nodes at height h? 2(log n - h) n(h/2(h)) Overall running time (summed over h):
  • 28. Node at height h has to move at most h steps to find its place. Number of nodes at height h? 2(log n - h) n(h/2(h)) Overall running time (summed over h): Heapify: Turns out to be a linear effort overall.
  • 29. 19 1 2 13 8 5 6 3 12 11 7 16 19 13 16 12 11 5 6 3 1 8 7 2
  • 30. 19 1 2 13 8 5 6 3 12 11 7 16 19 13 16 12 11 5 6 3 1 8 7 2 To sort, repeatedly extract the maximum element to the end of the array. An O(n log n) effort.
  • 33. 19 13 16 12 11 5 6 3 1 8 7 2 19 13 16 12 11 5 6 3 1 8 7 2
  • 34.
  • 35. Store the first (n/2) elements in a max-heap. Store the last (n/2) elements in a min-heap.