SlideShare a Scribd company logo
2
Most read
4
Most read
16
Most read
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
Ad

Recommended

Merge Sort
Merge Sort
Nikhil Sonkamble
 
Merge sort algorithm power point presentation
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Merge sort
Merge sort
Vidushi Pathak
 
Quick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Iniciação à Lógica Matemática - Edgard de Alencar Filho (2003).pdf
Iniciação à Lógica Matemática - Edgard de Alencar Filho (2003).pdf
marcusvinicius13184
 
Radix sort presentation
Radix sort presentation
Ratul Hasan
 
Quick sort
Quick sort
Afaq Mansoor Khan
 
Library Management System SRS
Library Management System SRS
Paras
 
Binary Search
Binary Search
kunj desai
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Binary search
Binary search
AparnaKumari31
 
Deque and its applications
Deque and its applications
Jsaddam Hussain
 
Red black tree
Red black tree
Rajendran
 
Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Dinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Merge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Quick sort
Quick sort
Dhruv Sabalpara
 
Insertion Sorting
Insertion Sorting
FarihaHabib123
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using divide & conquer
Swati Kulkarni Jaipurkar
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Quick sort
Quick sort
International Islamic University
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Solving recurrences
Solving recurrences
Megha V
 
3.9 external sorting
3.9 external sorting
Krish_ver2
 
Algorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Tree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
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 through
Yoshi Watanabe
 

More Related Content

What's hot (20)

Binary Search
Binary Search
kunj desai
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Binary search
Binary search
AparnaKumari31
 
Deque and its applications
Deque and its applications
Jsaddam Hussain
 
Red black tree
Red black tree
Rajendran
 
Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
Dinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Merge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 
Quick sort
Quick sort
Dhruv Sabalpara
 
Insertion Sorting
Insertion Sorting
FarihaHabib123
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using divide & conquer
Swati Kulkarni Jaipurkar
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Quick sort
Quick sort
International Islamic University
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Solving recurrences
Solving recurrences
Megha V
 
3.9 external sorting
3.9 external sorting
Krish_ver2
 
Algorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Tree traversal techniques
Tree traversal techniques
Syed Zaid Irshad
 
Stressen's matrix multiplication
Stressen's matrix multiplication
Kumar
 
Deque and its applications
Deque and its applications
Jsaddam Hussain
 
Red black tree
Red black tree
Rajendran
 
Dinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
finding Min and max element from given array using divide & conquer
finding Min and max element from given array using divide & conquer
Swati Kulkarni Jaipurkar
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First Search
Kevin Jadiya
 
Solving recurrences
Solving recurrences
Megha V
 
3.9 external sorting
3.9 external sorting
Krish_ver2
 
Algorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 

Viewers also liked (20)

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 through
Yoshi Watanabe
 
Presentation-Merge Sort
Presentation-Merge Sort
Md Showrov Ahmed
 
Merge sort
Merge sort
Srikrishnan Suresh
 
Merge sort
Merge sort
Chusnul Khotimah
 
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 applications
yazad dumasia
 
Algorithms lecture 3
Algorithms lecture 3
Mimi Haque
 
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
Takuma Usui
 
Lecture 3 insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
Insertion sort
Insertion sort
Monalisa Patel
 
Java presentation on insertion sort
Java presentation on insertion sort
_fahad_shaikh
 
Merge sort
Merge sort
Sindhoo Oad
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion Sort
Nicholas Case
 
Implementing Merge Sort
Implementing Merge Sort
smita gupta
 
Insertion Sort Demo
Insertion Sort Demo
rentjen
 
Insertion Sort
Insertion Sort
Putra Andry
 
Data Structure Insertion sort
Data Structure Insertion sort
Mahesh Dheravath
 
Merge sort
Merge sort
Kumar
 
Insertion sort
Insertion sort
aditya raj
 
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 through
Yoshi Watanabe
 
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 applications
yazad dumasia
 
Algorithms lecture 3
Algorithms lecture 3
Mimi Haque
 
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
Takuma Usui
 
Lecture 3 insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
Java presentation on insertion sort
Java presentation on insertion sort
_fahad_shaikh
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion Sort
Nicholas Case
 
Implementing Merge Sort
Implementing Merge Sort
smita gupta
 
Insertion Sort Demo
Insertion Sort Demo
rentjen
 
Data Structure Insertion sort
Data Structure Insertion sort
Mahesh Dheravath
 
Merge sort
Merge sort
Kumar
 
Insertion sort
Insertion sort
aditya raj
 
Ad

Similar to Merge sort algorithm (13)

Fourier Series of Music by Robert Fustero
Fourier Series of Music by Robert Fustero
RobertFustero
 
21 All Pairs Shortest Path
21 All Pairs Shortest Path
Andres Mendez-Vazquez
 
Electronic Spin Orbit Coupling
Electronic Spin Orbit Coupling
IOSRJM
 
Mergesort
Mergesort
SimoniShah6
 
Daa final
Daa final
Gagan019
 
Split and list technique for solving hard problems
Split and list technique for solving hard problems
Rohit Kumar Singh
 
09 permutations
09 permutations
Taradiddle81
 
Application of Integration
Application of Integration
Raymundo Raymund
 
draft5
draft5
Jacob H. Haven
 
24 Cs146 Jc Merge
24 Cs146 Jc Merge
Renu Kewalramani
 
Recursion Lecture in C++
Recursion Lecture in C++
Raffi Khatchadourian
 
L2_DatabAlgorithm Basics with Design & Analysis.pptx
L2_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
IAEME Publication
 
Fourier Series of Music by Robert Fustero
Fourier Series of Music by Robert Fustero
RobertFustero
 
Electronic Spin Orbit Coupling
Electronic Spin Orbit Coupling
IOSRJM
 
Split and list technique for solving hard problems
Split and list technique for solving hard problems
Rohit Kumar Singh
 
Application of Integration
Application of Integration
Raymundo Raymund
 
L2_DatabAlgorithm Basics with Design & Analysis.pptx
L2_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
MINIMAL OF 풗-OPEN SETS AND 풗-CLOSED SETS
IAEME Publication
 
Ad

More from Shubham Dwivedi (6)

Java abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz | PL SQL Examples
Shubham Dwivedi
 
Spectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | Networking
Shubham Dwivedi
 
User define data type In Visual Basic
User define data type In Visual Basic
Shubham Dwivedi
 
Dbms architecture
Dbms architecture
Shubham Dwivedi
 
Internet address
Internet address
Shubham Dwivedi
 
Java abstract class & abstract methods
Java abstract class & abstract methods
Shubham Dwivedi
 
PL SQL Quiz | PL SQL Examples
PL SQL Quiz | PL SQL Examples
Shubham Dwivedi
 
Spectrum vs Bandwidth vs Datarate | Networking
Spectrum vs Bandwidth vs Datarate | Networking
Shubham Dwivedi
 
User define data type In Visual Basic
User define data type In Visual Basic
Shubham Dwivedi
 

Recently uploaded (20)

OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
Information Security Response Team Nepal_npCERT_Vice_President_Sudan_Jha.pdf
ICT Frame Magazine Pvt. Ltd.
 
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
“Key Requirements to Successfully Implement Generative AI in Edge Devices—Opt...
Edge AI and Vision Alliance
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Improving Data Integrity: Synchronization between EAM and ArcGIS Utility Netw...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
The Future of AI Agent Development Trends to Watch.pptx
The Future of AI Agent Development Trends to Watch.pptx
Lisa ward
 

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