SlideShare uma empresa Scribd logo
1 de 10
Sorting Algorithms
Department of Computer Science
Islamia College University Peshawar

Fall 2012 Semester
BCS course: CS 00 Analysis of Algorithms
Course Instructor: Mr. Zahid
MergeSort - Illustration

2

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
MergeSort – Illustration (contd…)

3

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
MergeSort – Illustration (contd…)

4

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Pseudo code

5

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Pseudo code

6

Lecture #5

Wednesday, March 4, 2009
Recurrence Relation
 Recall for Divide and Conquer algorithms
T(n) = aT(n/b) + D(n) + C(n)
 Here a=2, and if we assume n is a power of 2, then each divide
step leads to sub-arrays of size n/2
 D(n)=θ(1)
 C(n)= θ(n)
 T(n)=2T(n/2)+θ(n)
7

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Worst-case scenario

8

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Worst and Average-case Scenario
 Worst case running time of merge sort is θ(nlgn)
 Average case running time of merge sort is also θ(nlgn)
 Best case?

9

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009
Worst and Average-case Scenario
 Worst case running time of merge sort is θ(nlgn)
 Average case running time of merge sort is also θ(nlgn)
 Best case?

9

Lecture #5
Adapted from slides by Dr A. Sattar

Wednesday, March 4, 2009

Mais conteúdo relacionado

Mais procurados

Module 4 topic 3
Module 4 topic 3Module 4 topic 3
Module 4 topic 3Annie cox
 
Factoring Perfect Square Trinomial
Factoring Perfect Square TrinomialFactoring Perfect Square Trinomial
Factoring Perfect Square TrinomialLorie Jane Letada
 
Mat1000ppt Sess01
Mat1000ppt Sess01Mat1000ppt Sess01
Mat1000ppt Sess01Purch
 
Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20DMCI
 
Lesson 3 angle between two intersecting lines
Lesson 3   angle between two intersecting linesLesson 3   angle between two intersecting lines
Lesson 3 angle between two intersecting linesJean Leano
 
Lesson 4 division of a line segment
Lesson 4   division of a line segmentLesson 4   division of a line segment
Lesson 4 division of a line segmentJean Leano
 
January 21, 2015
January 21, 2015January 21, 2015
January 21, 2015khyps13
 
8th alg -l3.6
8th alg -l3.68th alg -l3.6
8th alg -l3.6jdurst65
 
Bba105 computer fundamentals..
Bba105  computer fundamentals..Bba105  computer fundamentals..
Bba105 computer fundamentals..smumbahelp
 
3.5 write and graph equations of lines
3.5 write and graph equations of lines3.5 write and graph equations of lines
3.5 write and graph equations of linesmasljr
 
Writing linear equations
Writing linear equationsWriting linear equations
Writing linear equationshisema01
 
Writing Equations of a Line
Writing Equations of a LineWriting Equations of a Line
Writing Equations of a Lineswartzje
 

Mais procurados (17)

Module 4 topic 3
Module 4 topic 3Module 4 topic 3
Module 4 topic 3
 
Factoring Perfect Square Trinomial
Factoring Perfect Square TrinomialFactoring Perfect Square Trinomial
Factoring Perfect Square Trinomial
 
Mat1000ppt Sess01
Mat1000ppt Sess01Mat1000ppt Sess01
Mat1000ppt Sess01
 
Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20
 
คาบ2 2
คาบ2 2คาบ2 2
คาบ2 2
 
Lesson 3 angle between two intersecting lines
Lesson 3   angle between two intersecting linesLesson 3   angle between two intersecting lines
Lesson 3 angle between two intersecting lines
 
Lesson 4 division of a line segment
Lesson 4   division of a line segmentLesson 4   division of a line segment
Lesson 4 division of a line segment
 
January 21, 2015
January 21, 2015January 21, 2015
January 21, 2015
 
8th alg -l3.6
8th alg -l3.68th alg -l3.6
8th alg -l3.6
 
H027052054
H027052054H027052054
H027052054
 
Goldbach and Chandra
Goldbach and ChandraGoldbach and Chandra
Goldbach and Chandra
 
Bba105 computer fundamentals..
Bba105  computer fundamentals..Bba105  computer fundamentals..
Bba105 computer fundamentals..
 
Equations of a Line
Equations of a LineEquations of a Line
Equations of a Line
 
3.5 write and graph equations of lines
3.5 write and graph equations of lines3.5 write and graph equations of lines
3.5 write and graph equations of lines
 
Merge sort
Merge sortMerge sort
Merge sort
 
Writing linear equations
Writing linear equationsWriting linear equations
Writing linear equations
 
Writing Equations of a Line
Writing Equations of a LineWriting Equations of a Line
Writing Equations of a Line
 

Último

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Último (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Merge sort

  • 1. Sorting Algorithms Department of Computer Science Islamia College University Peshawar Fall 2012 Semester BCS course: CS 00 Analysis of Algorithms Course Instructor: Mr. Zahid
  • 2. MergeSort - Illustration 2 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 3. MergeSort – Illustration (contd…) 3 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 4. MergeSort – Illustration (contd…) 4 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 5. Pseudo code 5 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 7. Recurrence Relation  Recall for Divide and Conquer algorithms T(n) = aT(n/b) + D(n) + C(n)  Here a=2, and if we assume n is a power of 2, then each divide step leads to sub-arrays of size n/2  D(n)=θ(1)  C(n)= θ(n)  T(n)=2T(n/2)+θ(n) 7 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 8. Worst-case scenario 8 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 9. Worst and Average-case Scenario  Worst case running time of merge sort is θ(nlgn)  Average case running time of merge sort is also θ(nlgn)  Best case? 9 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009
  • 10. Worst and Average-case Scenario  Worst case running time of merge sort is θ(nlgn)  Average case running time of merge sort is also θ(nlgn)  Best case? 9 Lecture #5 Adapted from slides by Dr A. Sattar Wednesday, March 4, 2009