SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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
 

What's hot (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
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
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 WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
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 WoodJuan lago vázquez
 
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 Processorsdebabhi2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.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
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

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