SlideShare a Scribd company logo
1 of 17
Shubham Dwivedi
 Merge sort is a sorting technique based on
divide and conquer technique. With worst-
case time complexity being Ο(n log n), it is
one of the most respected algorithms.
 Merge sort first divides the array into equal
halves and then combines them in a sorted
manner.
Invented by
John von Neumann
(1903-1957)
 Follows divide and
conquer paradigm.
 Developed merge
sort for EDVAC in
1945
1.Divide: Divide the unsorted list into two sub lists
of about half the size.
2.Conquer: Sort each of the two sub lists
recursively until we have list sizes of length 1,in
which case the list itself is returned.
3.Combine: Merge the two-sorted sub lists back
into one sorted list.
 MERGE SORT (A,p,r) //divide
if p < r
then q= [ (p + r) / 2 ]
MERGE SORT(A,p,q)
MERGER SORT(A,q + 1,r)
MERGE(A,p,q,r)
Merge(array A, int p, int q, int r)
{
array B[p..r] //temp array taken
i = k = p // initialize pointers
j = q+1
while (i <= q and j <= r)
{
if (A[i] <= A[j]) B[k++] = A[i++]
else B[k++] = A[j++]
}
while (i <= q)
B[k++] = A[i++] // copy any leftover to B
while (j <= r)
B[k++] = A[j++]
for i = p to r
A[i] = B[i] // copy B back to A
}
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
86 1599 6 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
86 1599 6 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
99 6 86 15 58 35 86 4 0
86 1599 6 58 35 86 4 0
99 6 86 15 58 35 86 4 0
4 0
99 6 86 15 58 35 86 0 4
4 0Merge
15 866 99 58 35 0 4 86
99 6 86 15 58 35 86 0 4
Merge
6 15 86 99 0 4 35 58 86
15 866 99 58 35 0 4 86
Merge
0 4 6 15 35 58 86 86 99
6 15 86 99 0 4 35 58 86
Merge
Merge sort algorithm
Merge sort algorithm

More Related Content

What's hot

Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentationRatul Hasan
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data StructureJeanie Arnoco
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysissumitbardhan
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 

What's hot (20)

Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Radix sort presentation
Radix sort presentationRadix sort presentation
Radix sort presentation
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Insertion Sorting
Insertion SortingInsertion Sorting
Insertion Sorting
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Quick sort
Quick sortQuick sort
Quick sort
 
Ppt bubble sort
Ppt bubble sortPpt bubble sort
Ppt bubble sort
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Linked list
Linked listLinked list
Linked list
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Sorting
SortingSorting
Sorting
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Big o notation
Big o notationBig o notation
Big o notation
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 

Viewers also liked

Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained Mohit Tare
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughYoshi Watanabe
 
Intersection Study - Algorithm(Sort)
Intersection Study - Algorithm(Sort)Intersection Study - Algorithm(Sort)
Intersection Study - Algorithm(Sort)Jea Hyeun Jung
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applicationsyazad dumasia
 
Algorithms lecture 3
Algorithms lecture 3Algorithms lecture 3
Algorithms lecture 3Mimi Haque
 
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAsA Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAsTakuma Usui
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
Java presentation on insertion sort
Java presentation on insertion sortJava presentation on insertion sort
Java presentation on insertion sort_fahad_shaikh
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortIntro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortNicholas Case
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sortsmita gupta
 
Insertion Sort Demo
Insertion Sort DemoInsertion Sort Demo
Insertion Sort Demorentjen
 
Data Structure Insertion sort
Data Structure Insertion sort Data Structure Insertion sort
Data Structure Insertion sort Mahesh Dheravath
 
Merge sort
Merge sortMerge sort
Merge sortKumar
 
Insertion sort
Insertion sortInsertion sort
Insertion sortaditya raj
 

Viewers also liked (20)

Merge sort code in C explained
Merge sort code in C explained Merge sort code in C explained
Merge sort code in C explained
 
Merge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk throughMerge sort: illustrated step-by-step walk through
Merge sort: illustrated step-by-step walk through
 
Merge sort
Merge sortMerge sort
Merge sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Intersection Study - Algorithm(Sort)
Intersection Study - Algorithm(Sort)Intersection Study - Algorithm(Sort)
Intersection Study - Algorithm(Sort)
 
Merge sort analysis and its real time applications
Merge sort analysis and its real time applicationsMerge sort analysis and its real time applications
Merge sort analysis and its real time applications
 
Algorithms lecture 3
Algorithms lecture 3Algorithms lecture 3
Algorithms lecture 3
 
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAsA Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Java presentation on insertion sort
Java presentation on insertion sortJava presentation on insertion sort
Java presentation on insertion sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortIntro to Sorting + Insertion Sort
Intro to Sorting + Insertion Sort
 
Implementing Merge Sort
Implementing Merge SortImplementing Merge Sort
Implementing Merge Sort
 
Insertion Sort Demo
Insertion Sort DemoInsertion Sort Demo
Insertion Sort Demo
 
Insertion Sort
Insertion SortInsertion Sort
Insertion Sort
 
Data Structure Insertion sort
Data Structure Insertion sort Data Structure Insertion sort
Data Structure Insertion sort
 
Merge sort
Merge sortMerge sort
Merge sort
 
Insertion sort
Insertion sortInsertion sort
Insertion sort
 
Insertion and merge sort
Insertion and merge sortInsertion and merge sort
Insertion and merge sort
 

Similar to Merge sort algorithm

Fourier Series of Music by Robert Fustero
Fourier Series of Music by Robert FusteroFourier Series of Music by Robert Fustero
Fourier Series of Music by Robert FusteroRobertFustero
 
Electronic Spin Orbit Coupling
Electronic Spin Orbit CouplingElectronic Spin Orbit Coupling
Electronic Spin Orbit CouplingIOSRJM
 
Split and list technique for solving hard problems
Split and list technique for solving hard problemsSplit and list technique for solving hard problems
Split and list technique for solving hard problemsRohit Kumar Singh
 
Application of Integration
Application of IntegrationApplication of Integration
Application of IntegrationRaymundo Raymund
 
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETSMINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETSIAEME Publication
 

Similar to Merge sort algorithm (12)

Fourier Series of Music by Robert Fustero
Fourier Series of Music by Robert FusteroFourier Series of Music by Robert Fustero
Fourier Series of Music by Robert Fustero
 
21 All Pairs Shortest Path
21 All Pairs Shortest Path21 All Pairs Shortest Path
21 All Pairs Shortest Path
 
Electronic Spin Orbit Coupling
Electronic Spin Orbit CouplingElectronic Spin Orbit Coupling
Electronic Spin Orbit Coupling
 
Mergesort
MergesortMergesort
Mergesort
 
Daa final
Daa finalDaa final
Daa final
 
Split and list technique for solving hard problems
Split and list technique for solving hard problemsSplit and list technique for solving hard problems
Split and list technique for solving hard problems
 
09 permutations
09   permutations09   permutations
09 permutations
 
Application of Integration
Application of IntegrationApplication of Integration
Application of Integration
 
draft5
draft5draft5
draft5
 
24 Cs146 Jc Merge
24 Cs146 Jc Merge24 Cs146 Jc Merge
24 Cs146 Jc Merge
 
Recursion Lecture in C++
Recursion Lecture in C++Recursion Lecture in C++
Recursion Lecture in C++
 
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETSMINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
 

More from Shubham Dwivedi

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL ExamplesShubham Dwivedi
 
Spectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | NetworkingSpectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | NetworkingShubham Dwivedi
 
User define data type In Visual Basic
User define data type In Visual Basic User define data type In Visual Basic
User define data type In Visual Basic Shubham Dwivedi
 

More from Shubham Dwivedi (6)

Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz |  PL SQL ExamplesPL SQL Quiz |  PL SQL Examples
PL SQL Quiz | PL SQL Examples
 
Spectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | NetworkingSpectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | Networking
 
User define data type In Visual Basic
User define data type In Visual Basic User define data type In Visual Basic
User define data type In Visual Basic
 
Dbms architecture
Dbms architectureDbms architecture
Dbms architecture
 
Internet address
Internet addressInternet address
Internet address
 

Recently uploaded

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Recently uploaded (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate AgentsRyan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
Ryan Mahoney - Will Artificial Intelligence Replace Real Estate Agents
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Merge sort algorithm

  • 2.  Merge sort is a sorting technique based on divide and conquer technique. With worst- case time complexity being Ο(n log n), it is one of the most respected algorithms.  Merge sort first divides the array into equal halves and then combines them in a sorted manner.
  • 3. Invented by John von Neumann (1903-1957)  Follows divide and conquer paradigm.  Developed merge sort for EDVAC in 1945
  • 4. 1.Divide: Divide the unsorted list into two sub lists of about half the size. 2.Conquer: Sort each of the two sub lists recursively until we have list sizes of length 1,in which case the list itself is returned. 3.Combine: Merge the two-sorted sub lists back into one sorted list.
  • 5.  MERGE SORT (A,p,r) //divide if p < r then q= [ (p + r) / 2 ] MERGE SORT(A,p,q) MERGER SORT(A,q + 1,r) MERGE(A,p,q,r)
  • 6. Merge(array A, int p, int q, int r) { array B[p..r] //temp array taken i = k = p // initialize pointers j = q+1 while (i <= q and j <= r) { if (A[i] <= A[j]) B[k++] = A[i++] else B[k++] = A[j++] } while (i <= q) B[k++] = A[i++] // copy any leftover to B while (j <= r) B[k++] = A[j++] for i = p to r A[i] = B[i] // copy B back to A }
  • 7. 99 6 86 15 58 35 86 4 0
  • 8. 99 6 86 15 58 35 86 4 0 99 6 86 15 58 35 86 4 0
  • 9. 99 6 86 15 58 35 86 4 0 99 6 86 15 58 35 86 4 0 86 1599 6 58 35 86 4 0
  • 10. 99 6 86 15 58 35 86 4 0 99 6 86 15 58 35 86 4 0 86 1599 6 58 35 86 4 0 99 6 86 15 58 35 86 4 0
  • 11. 99 6 86 15 58 35 86 4 0 99 6 86 15 58 35 86 4 0 86 1599 6 58 35 86 4 0 99 6 86 15 58 35 86 4 0 4 0
  • 12. 99 6 86 15 58 35 86 0 4 4 0Merge
  • 13. 15 866 99 58 35 0 4 86 99 6 86 15 58 35 86 0 4 Merge
  • 14. 6 15 86 99 0 4 35 58 86 15 866 99 58 35 0 4 86 Merge
  • 15. 0 4 6 15 35 58 86 86 99 6 15 86 99 0 4 35 58 86 Merge