SlideShare una empresa de Scribd logo
1 de 25
G R Lockwood, 2006 1
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sort the sequence 6, 5, 8, 3, 2, 7, 1Sort the sequence 6, 5, 8, 3, 2, 7, 1
using merge sortusing merge sort
G R Lockwood, 2006 2
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Split the sequenceSplit the sequence
atat mm==((ii++jj)/2)/2
 ii=1,=1, jj=7,=7, mm=4=4
66
55
88
33
22
77
11
G R Lockwood, 2006 3
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Make a recursiveMake a recursive
call to merge sortcall to merge sort
 mm :=:= ((ii++jj)/2)/2==
2.52.5=2=2
66
55
88
33
22
77
11
G R Lockwood, 2006 4
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Now sorting thisNow sorting this
partpart
 ii=1,=1, jj=2,=2, mm=1 and=1 and
make a recursivemake a recursive
callcall
66
55
88
33
22
77
11
G R Lockwood, 2006 5
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is already sorted,1 is already sorted,
so returnso return
66
55
88
33
22
77
11
G R Lockwood, 2006 6
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is sorted1 is sorted
66
55
88
33
22
77
11
G R Lockwood, 2006 7
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Return control andReturn control and
merge these 2 sub-merge these 2 sub-
sequences intosequences into
correct ordercorrect order
66
55
88
33
22
77
11
G R Lockwood, 2006 8
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Now sort theNow sort the
second part of thissecond part of this
subsequencesubsequence
55
66
88
33
22
77
11
G R Lockwood, 2006 9
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is sorted1 is sorted
55
66
88
33
22
77
11
G R Lockwood, 2006 10
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is sorted1 is sorted
55
66
88
33
22
77
11
G R Lockwood, 2006 11
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Merge these twoMerge these two
into correct orderinto correct order
55
66
88
33
22
77
11
G R Lockwood, 2006 12
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Return control toReturn control to
previous call.previous call.
 Now merge theseNow merge these
two sub-sequencestwo sub-sequences
into correct orderinto correct order
55
66
33
88
22
77
11
G R Lockwood, 2006 13
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 The recursive callThe recursive call
at line 7 is nowat line 7 is now
completedcompleted
 First part ofFirst part of
sequence is nowsequence is now
fully sortedfully sorted
33
55
66
88
22
77
11
G R Lockwood, 2006 14
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Control nowControl now
returns to the veryreturns to the very
first call of mergefirst call of merge
sortsort
 A recursive call isA recursive call is
now made on thenow made on the
second part of thesecond part of the
sequencesequence
33
55
66
88
22
77
11
G R Lockwood, 2006 15
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 ii=5,=5, jj=7,=7, mm=6=6
 Split sequence atSplit sequence at
item 6item 6
33
55
66
88
22
77
11
G R Lockwood, 2006 16
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Make a recursiveMake a recursive
call to sort thesecall to sort these
two itemstwo items
 Split sequence atSplit sequence at
item 5item 5
33
55
66
88
22
77
11
G R Lockwood, 2006 17
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Make anotherMake another
recursive call onrecursive call on
the first part of thisthe first part of this
subsequencesubsequence
33
55
66
88
22
77
11
G R Lockwood, 2006 18
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is sorted1 is sorted
33
55
66
88
22
77
11
G R Lockwood, 2006 19
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Make a recursiveMake a recursive
call on second partcall on second part
of sequenceof sequence
 Sequence of lengthSequence of length
1 is sorted1 is sorted
33
55
66
88
22
77
11
G R Lockwood, 2006 20
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Now merge these 2Now merge these 2
sub-sequencessub-sequences
into correct orderinto correct order
33
55
66
88
22
77
11
G R Lockwood, 2006 21
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Make a recursiveMake a recursive
call with thecall with the
remaining elementremaining element
33
55
66
88
22
77
11
G R Lockwood, 2006 22
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Sequence of lengthSequence of length
1 is sorted1 is sorted
33
55
66
88
22
77
11
G R Lockwood, 2006 23
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Now merge these 2Now merge these 2
sub-sequences intosub-sequences into
correct ordercorrect order
33
55
66
88
22
77
11
G R Lockwood, 2006 24
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Return to the firstReturn to the first
callcall
 Now merge these 2Now merge these 2
sub-sequences intosub-sequences into
correct ordercorrect order
33
55
66
88
11
22
77
G R Lockwood, 2006 25
Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort
 Merge sort isMerge sort is
completedcompleted
11
22
33
55
66
77
88

Más contenido relacionado

Destacado

Sorting techniques Anil Dutt
Sorting techniques Anil DuttSorting techniques Anil Dutt
Sorting techniques Anil DuttAnil Dutt
 
Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)oDesk
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sortKrish_ver2
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languageBilal Amjad
 
Bubble sort
Bubble sort Bubble sort
Bubble sort rmsz786
 
Advanced Sorting Algorithms
Advanced Sorting AlgorithmsAdvanced Sorting Algorithms
Advanced Sorting AlgorithmsDamian T. Gordon
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sortgeeortiz
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Muhammad Hammad Waseem
 

Destacado (16)

Marge Sort
Marge SortMarge Sort
Marge Sort
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
Sorting algorithms
Sorting algorithmsSorting algorithms
Sorting algorithms
 
Sorting techniques Anil Dutt
Sorting techniques Anil DuttSorting techniques Anil Dutt
Sorting techniques Anil Dutt
 
Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)Sorting (Bubble,Merge,Selection sort)
Sorting (Bubble,Merge,Selection sort)
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
3.1 bubble sort
3.1 bubble sort3.1 bubble sort
3.1 bubble sort
 
Sorting
SortingSorting
Sorting
 
bubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly languagebubble sorting of an array in 8086 assembly language
bubble sorting of an array in 8086 assembly language
 
Bubble sort
Bubble sort Bubble sort
Bubble sort
 
Advanced Sorting Algorithms
Advanced Sorting AlgorithmsAdvanced Sorting Algorithms
Advanced Sorting Algorithms
 
Bubble Sort
Bubble SortBubble Sort
Bubble Sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]Data Structures - Lecture 8 [Sorting Algorithms]
Data Structures - Lecture 8 [Sorting Algorithms]
 
Sorting
SortingSorting
Sorting
 

Más de Sumedha

Deutsch famous facts
Deutsch famous factsDeutsch famous facts
Deutsch famous factsSumedha
 
German music
German musicGerman music
German musicSumedha
 
Selab1 slides
Selab1 slidesSelab1 slides
Selab1 slidesSumedha
 
Reading skills
Reading skillsReading skills
Reading skillsSumedha
 
Negotiations
NegotiationsNegotiations
NegotiationsSumedha
 
Group discussions
Group discussionsGroup discussions
Group discussionsSumedha
 
Small talk
Small talkSmall talk
Small talkSumedha
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersSumedha
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-leSumedha
 
An example of bubble sort written in c
An example of bubble sort written in cAn example of bubble sort written in c
An example of bubble sort written in cSumedha
 
Group discussion
Group discussionGroup discussion
Group discussionSumedha
 
Group discussions eng project
Group discussions eng projectGroup discussions eng project
Group discussions eng projectSumedha
 
Eng presentation
Eng presentationEng presentation
Eng presentationSumedha
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwangSumedha
 

Más de Sumedha (20)

Deutsch famous facts
Deutsch famous factsDeutsch famous facts
Deutsch famous facts
 
German music
German musicGerman music
German music
 
Ada scan
Ada scanAda scan
Ada scan
 
Scan2
Scan2Scan2
Scan2
 
Scan1
Scan1Scan1
Scan1
 
998e6 des
998e6 des998e6 des
998e6 des
 
Selab1 slides
Selab1 slidesSelab1 slides
Selab1 slides
 
Reading skills
Reading skillsReading skills
Reading skills
 
Negotiations
NegotiationsNegotiations
Negotiations
 
Rapport
RapportRapport
Rapport
 
Meeetings
MeeetingsMeeetings
Meeetings
 
Group discussions
Group discussionsGroup discussions
Group discussions
 
Small talk
Small talkSmall talk
Small talk
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towers
 
Is sort andy-le
Is sort andy-leIs sort andy-le
Is sort andy-le
 
An example of bubble sort written in c
An example of bubble sort written in cAn example of bubble sort written in c
An example of bubble sort written in c
 
Group discussion
Group discussionGroup discussion
Group discussion
 
Group discussions eng project
Group discussions eng projectGroup discussions eng project
Group discussions eng project
 
Eng presentation
Eng presentationEng presentation
Eng presentation
 
Computer architecture kai hwang
Computer architecture   kai hwangComputer architecture   kai hwang
Computer architecture kai hwang
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
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...Zilliz
 
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 FresherRemote DBA Services
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
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 2024Victor Rentea
 
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.pptxRustici Software
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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...
 
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
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

Merge sort

  • 1. G R Lockwood, 2006 1 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sort the sequence 6, 5, 8, 3, 2, 7, 1Sort the sequence 6, 5, 8, 3, 2, 7, 1 using merge sortusing merge sort
  • 2. G R Lockwood, 2006 2 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Split the sequenceSplit the sequence atat mm==((ii++jj)/2)/2  ii=1,=1, jj=7,=7, mm=4=4 66 55 88 33 22 77 11
  • 3. G R Lockwood, 2006 3 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Make a recursiveMake a recursive call to merge sortcall to merge sort  mm :=:= ((ii++jj)/2)/2== 2.52.5=2=2 66 55 88 33 22 77 11
  • 4. G R Lockwood, 2006 4 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Now sorting thisNow sorting this partpart  ii=1,=1, jj=2,=2, mm=1 and=1 and make a recursivemake a recursive callcall 66 55 88 33 22 77 11
  • 5. G R Lockwood, 2006 5 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is already sorted,1 is already sorted, so returnso return 66 55 88 33 22 77 11
  • 6. G R Lockwood, 2006 6 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is sorted1 is sorted 66 55 88 33 22 77 11
  • 7. G R Lockwood, 2006 7 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Return control andReturn control and merge these 2 sub-merge these 2 sub- sequences intosequences into correct ordercorrect order 66 55 88 33 22 77 11
  • 8. G R Lockwood, 2006 8 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Now sort theNow sort the second part of thissecond part of this subsequencesubsequence 55 66 88 33 22 77 11
  • 9. G R Lockwood, 2006 9 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is sorted1 is sorted 55 66 88 33 22 77 11
  • 10. G R Lockwood, 2006 10 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is sorted1 is sorted 55 66 88 33 22 77 11
  • 11. G R Lockwood, 2006 11 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Merge these twoMerge these two into correct orderinto correct order 55 66 88 33 22 77 11
  • 12. G R Lockwood, 2006 12 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Return control toReturn control to previous call.previous call.  Now merge theseNow merge these two sub-sequencestwo sub-sequences into correct orderinto correct order 55 66 33 88 22 77 11
  • 13. G R Lockwood, 2006 13 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  The recursive callThe recursive call at line 7 is nowat line 7 is now completedcompleted  First part ofFirst part of sequence is nowsequence is now fully sortedfully sorted 33 55 66 88 22 77 11
  • 14. G R Lockwood, 2006 14 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Control nowControl now returns to the veryreturns to the very first call of mergefirst call of merge sortsort  A recursive call isA recursive call is now made on thenow made on the second part of thesecond part of the sequencesequence 33 55 66 88 22 77 11
  • 15. G R Lockwood, 2006 15 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  ii=5,=5, jj=7,=7, mm=6=6  Split sequence atSplit sequence at item 6item 6 33 55 66 88 22 77 11
  • 16. G R Lockwood, 2006 16 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Make a recursiveMake a recursive call to sort thesecall to sort these two itemstwo items  Split sequence atSplit sequence at item 5item 5 33 55 66 88 22 77 11
  • 17. G R Lockwood, 2006 17 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Make anotherMake another recursive call onrecursive call on the first part of thisthe first part of this subsequencesubsequence 33 55 66 88 22 77 11
  • 18. G R Lockwood, 2006 18 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is sorted1 is sorted 33 55 66 88 22 77 11
  • 19. G R Lockwood, 2006 19 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Make a recursiveMake a recursive call on second partcall on second part of sequenceof sequence  Sequence of lengthSequence of length 1 is sorted1 is sorted 33 55 66 88 22 77 11
  • 20. G R Lockwood, 2006 20 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Now merge these 2Now merge these 2 sub-sequencessub-sequences into correct orderinto correct order 33 55 66 88 22 77 11
  • 21. G R Lockwood, 2006 21 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Make a recursiveMake a recursive call with thecall with the remaining elementremaining element 33 55 66 88 22 77 11
  • 22. G R Lockwood, 2006 22 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Sequence of lengthSequence of length 1 is sorted1 is sorted 33 55 66 88 22 77 11
  • 23. G R Lockwood, 2006 23 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Now merge these 2Now merge these 2 sub-sequences intosub-sequences into correct ordercorrect order 33 55 66 88 22 77 11
  • 24. G R Lockwood, 2006 24 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Return to the firstReturn to the first callcall  Now merge these 2Now merge these 2 sub-sequences intosub-sequences into correct ordercorrect order 33 55 66 88 11 22 77
  • 25. G R Lockwood, 2006 25 Sorting a Sequence With Merge SortSorting a Sequence With Merge Sort  Merge sort isMerge sort is completedcompleted 11 22 33 55 66 77 88