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

More Related Content

What's hot (20)

PPTX
Insertion sort
Monalisa Patel
 
PPT
Dinive conquer algorithm
Mohd Arif
 
PDF
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
PPTX
Sorting
Ashim Lamichhane
 
PPTX
Data Structures : hashing (1)
Home
 
PPTX
Hashing
Amar Jukuntla
 
PPTX
Priority Queue in Data Structure
Meghaj Mallick
 
PPTX
Merge sort
Sindhoo Oad
 
PPTX
Binary Search Tree in Data Structure
Dharita Chokshi
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Terminology of tree
RacksaviR
 
PPTX
Quick sort
Dhruv Sabalpara
 
PPT
Bubble sort
Manek Ar
 
PPTX
Merge sort analysis and its real time applications
yazad dumasia
 
PPTX
Presentation-Merge Sort
Md Showrov Ahmed
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PPT
Heap sort
Mohd Arif
 
PPTX
Linear search-and-binary-search
International Islamic University
 
PPT
Hashing PPT
Saurabh Kumar
 
Insertion sort
Monalisa Patel
 
Dinive conquer algorithm
Mohd Arif
 
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Data Structures : hashing (1)
Home
 
Hashing
Amar Jukuntla
 
Priority Queue in Data Structure
Meghaj Mallick
 
Merge sort
Sindhoo Oad
 
Binary Search Tree in Data Structure
Dharita Chokshi
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Terminology of tree
RacksaviR
 
Quick sort
Dhruv Sabalpara
 
Bubble sort
Manek Ar
 
Merge sort analysis and its real time applications
yazad dumasia
 
Presentation-Merge Sort
Md Showrov Ahmed
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Heap sort
Mohd Arif
 
Linear search-and-binary-search
International Islamic University
 
Hashing PPT
Saurabh Kumar
 

Viewers also liked (20)

PPTX
Merge sort code in C explained
Mohit Tare
 
PDF
Merge sort: illustrated step-by-step walk through
Yoshi Watanabe
 
PDF
Merge sort
Srikrishnan Suresh
 
PPTX
Merge sort
Chusnul Khotimah
 
PDF
Intersection Study - Algorithm(Sort)
Jea Hyeun Jung
 
PDF
Algorithms lecture 3
Mimi Haque
 
PDF
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
Takuma Usui
 
PDF
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
PPTX
Java presentation on insertion sort
_fahad_shaikh
 
ODP
Intro to Sorting + Insertion Sort
Nicholas Case
 
PPTX
Implementing Merge Sort
smita gupta
 
PPSX
Insertion Sort Demo
rentjen
 
PPTX
Insertion Sort
Putra Andry
 
PPT
Data Structure Insertion sort
Mahesh Dheravath
 
PPTX
Merge sort
Kumar
 
PPT
Insertion sort
aditya raj
 
PPTX
Insertion and merge sort
Preetham Devisetty
 
PDF
Insertion Sort Algorithm
Gail Carmichael
 
PPTX
Insertion Sort
Brett Duncan
 
PPTX
Merge sort
Maher Alshammari
 
Merge sort code in C explained
Mohit Tare
 
Merge sort: illustrated step-by-step walk through
Yoshi Watanabe
 
Merge sort
Srikrishnan Suresh
 
Merge sort
Chusnul Khotimah
 
Intersection Study - Algorithm(Sort)
Jea Hyeun Jung
 
Algorithms lecture 3
Mimi Haque
 
A Cost-Effective and Scalable Merge Sort Tree on FPGAs
Takuma Usui
 
Lecture 3 insertion sort and complexity analysis
jayavignesh86
 
Java presentation on insertion sort
_fahad_shaikh
 
Intro to Sorting + Insertion Sort
Nicholas Case
 
Implementing Merge Sort
smita gupta
 
Insertion Sort Demo
rentjen
 
Insertion Sort
Putra Andry
 
Data Structure Insertion sort
Mahesh Dheravath
 
Merge sort
Kumar
 
Insertion sort
aditya raj
 
Insertion and merge sort
Preetham Devisetty
 
Insertion Sort Algorithm
Gail Carmichael
 
Insertion Sort
Brett Duncan
 
Merge sort
Maher Alshammari
 
Ad

Similar to Merge sort algorithm (20)

PPTX
Merge sort
Arafat Hossan
 
PDF
merge sort
ObedurRahman1
 
PPTX
L2_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
PPTX
Merge sort-algorithm for computer science engineering students
University of Science and Technology Chitttagong
 
PPTX
Merge sort
Rojin Khadka
 
PDF
Ds sorting
Hamza Khan
 
PPTX
Mergesort
SimoniShah6
 
PDF
Working of Merge Sort Code
Muhammad Abdullah
 
PDF
Merge sort
Abdelrahman Saleh
 
PPT
Mergesort
luzenith_g
 
DOCX
Assignment 2 data structures National University Of Modern Languages
itsaif1312
 
PDF
Sorting Algorithms and their implementations
ChakravarthiMusic1
 
PDF
Python week4-lecture1-handout
AnmolTwickley
 
PPT
computer notes - Data Structures - 39
ecomputernotes
 
PPTX
Daa final
Gagan019
 
PPT
Computer notes - Mergesort
ecomputernotes
 
PPTX
ch16.pptx
lordaragorn2
 
PPTX
ch16 (1).pptx
lordaragorn2
 
PPT
Tri Merge Sorting Algorithm
Ashim Sikder
 
Merge sort
Arafat Hossan
 
merge sort
ObedurRahman1
 
L2_DatabAlgorithm Basics with Design & Analysis.pptx
dpdiyakhan
 
Merge sort-algorithm for computer science engineering students
University of Science and Technology Chitttagong
 
Merge sort
Rojin Khadka
 
Ds sorting
Hamza Khan
 
Mergesort
SimoniShah6
 
Working of Merge Sort Code
Muhammad Abdullah
 
Merge sort
Abdelrahman Saleh
 
Mergesort
luzenith_g
 
Assignment 2 data structures National University Of Modern Languages
itsaif1312
 
Sorting Algorithms and their implementations
ChakravarthiMusic1
 
Python week4-lecture1-handout
AnmolTwickley
 
computer notes - Data Structures - 39
ecomputernotes
 
Daa final
Gagan019
 
Computer notes - Mergesort
ecomputernotes
 
ch16.pptx
lordaragorn2
 
ch16 (1).pptx
lordaragorn2
 
Tri Merge Sorting Algorithm
Ashim Sikder
 
Ad

More from Shubham Dwivedi (6)

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

Recently uploaded (20)

PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 

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