SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Module 4 topic 3
Module 4 topic 3Module 4 topic 3
Module 4 topic 3
Annie cox
 
Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20Determining Equations Of Lines Nov 20
Determining Equations Of Lines Nov 20
DMCI
 
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
Jean 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 segment
Jean Leano
 
January 21, 2015
January 21, 2015January 21, 2015
January 21, 2015
khyps13
 
8th alg -l3.6
8th alg -l3.68th alg -l3.6
8th alg -l3.6
jdurst65
 
Writing linear equations
Writing linear equationsWriting linear equations
Writing linear equations
hisema01
 
Writing Equations of a Line
Writing Equations of a LineWriting Equations of a Line
Writing Equations of a Line
swartzje
 

Was ist angesagt? (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
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 

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