SlideShare a Scribd company logo
Group-5
MERGE SORT
Introduction
• Merge sort is a popular sorting algorithm that follows the divide-
and-conquer approach. The algorithm works by dividing the input
array into two halves, sorting each half separately, and then
merging the two sorted halves back into a single sorted array.And is
known for its stability and efficiency on large datasets. It is
commonly used in various applications, including sorting massive
amounts of data, parallel computing, and external sorting. In this
algorithm, the main operations are merging and splitting the array,
making it easy to implement and understand.
MERGE SORT
ALGORITHM
Top-down Approach
It starts at the top and works its
way down, splitting the array in
half, making a recursive call, and
merging the results until it reaches
the bottom of the array tree.
Merge Sort How Code Works
• Pseudocode for MergeSort
As we know, merge sort works on the divide and conquer approach. It repeatedly
divides the array into smaller parts until it is left with a single element. Now let us
see the pseudocode of merge sort.
• Step 1: Declare the variable low and high to mark the start and end of the array.
• Step 2: Low will equal 0, and high will equal array size -1.
• Step 3: Calculate mid using low + high / 2.
• Step 4: Call the mergeSort function on the part (low, mid) and (mid+1, high).
• Step 5: This calling will continue till low<high is satisfied.
• Step 6: Finally, call the merge function to merge these two halves.
• Implement the Merge Sort In Python
def merge_sort(arr):
if len(arr) > 1:
mid = len(arr) // 2
L = arr[:mid]
R = arr[mid:]
merge_sort(L)
merge_sort(R)
i = j = k = 0
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1
k += 1
while i < len(L):
arr[k] = L[i]
i += 1
k += 1
while j < len(R):
arr[k] = R[j]
j += 1
k += 1
arr = [12, 11, 13, 5, 6, 7]
merge_sort(arr)
print(arr)
Summary
• Merge Sort is a sorting algorithm that uses the divide-and-conquer
approach to sort an array. It is efficient for large data sets. Merge
Sort first divides the input array into smaller sub-arrays until each
sub-array contains only one element. Overall, Merge Sort is a
reliable and efficient sorting algorithm that is widely used in
many applications.
• Disadvantages of Merge Sort
• Merge sort is not efficient for sorting input of large size if you are having low stack
space.
• Merge sort while sorting the array goes through the entire process even if the array is
sorted.

More Related Content

PPTX
DSA- Merge Sort-a sorting technique.pptx
PPTX
Data structure Merge Sort implementation
PPTX
Presentation merge sort.pptx
PPTX
MergeSort presentation dgdfgdfgdfgg.pptx
PPTX
merg sort slide created by anas sanan.pptx
PPTX
dsa presentation on merge sorting in C++.pptx
PPT
Merge sort
DSA- Merge Sort-a sorting technique.pptx
Data structure Merge Sort implementation
Presentation merge sort.pptx
MergeSort presentation dgdfgdfgdfgg.pptx
merg sort slide created by anas sanan.pptx
dsa presentation on merge sorting in C++.pptx
Merge sort

Similar to Data Structure Marge sort Group 5 pptx so (20)

PDF
advanced algo
PPTX
Merge Sort
PDF
MERGE SORT ALGORITHMS DIVIDE AND CONQUER
PPTX
24671A08972ds.pptxxxxxxxxxkkkskjsjsjskskssjdhdjskw
PPTX
Merge sort
PPTX
Merge sort
PPTX
Weak 11-12 Sorting update.pptxbhjiiuuuuu
PPTX
presentation.pptx
PPTX
Daa final
PPTX
Merge sort analysis and its real time applications
DOCX
Merge sort lab mannual
PDF
Working of Merge Sort Code
PPTX
Module 2_ Divide and Conquer Approach.pptx
PPTX
Mergesort
PPTX
Merj sort
PPTX
Lecture -16-merge sort (slides).pptx
PPTX
Merge Sort with real example using animation
PPTX
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
PPTX
Merge sort
PDF
Heap, quick and merge sort
advanced algo
Merge Sort
MERGE SORT ALGORITHMS DIVIDE AND CONQUER
24671A08972ds.pptxxxxxxxxxkkkskjsjsjskskssjdhdjskw
Merge sort
Merge sort
Weak 11-12 Sorting update.pptxbhjiiuuuuu
presentation.pptx
Daa final
Merge sort analysis and its real time applications
Merge sort lab mannual
Working of Merge Sort Code
Module 2_ Divide and Conquer Approach.pptx
Mergesort
Merj sort
Lecture -16-merge sort (slides).pptx
Merge Sort with real example using animation
8.05.Merge_sort.pptxCUYGYUKTGUIJBJKGKUYGFKJBNVKUYV87VYFHHGVTFGU
Merge sort
Heap, quick and merge sort
Ad

Recently uploaded (20)

PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
NewMind AI Weekly Chronicles - August'25 Week I
sap open course for s4hana steps from ECC to s4
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Ad

Data Structure Marge sort Group 5 pptx so

  • 2. Introduction • Merge sort is a popular sorting algorithm that follows the divide- and-conquer approach. The algorithm works by dividing the input array into two halves, sorting each half separately, and then merging the two sorted halves back into a single sorted array.And is known for its stability and efficiency on large datasets. It is commonly used in various applications, including sorting massive amounts of data, parallel computing, and external sorting. In this algorithm, the main operations are merging and splitting the array, making it easy to implement and understand.
  • 3. MERGE SORT ALGORITHM Top-down Approach It starts at the top and works its way down, splitting the array in half, making a recursive call, and merging the results until it reaches the bottom of the array tree.
  • 4. Merge Sort How Code Works • Pseudocode for MergeSort As we know, merge sort works on the divide and conquer approach. It repeatedly divides the array into smaller parts until it is left with a single element. Now let us see the pseudocode of merge sort. • Step 1: Declare the variable low and high to mark the start and end of the array. • Step 2: Low will equal 0, and high will equal array size -1. • Step 3: Calculate mid using low + high / 2. • Step 4: Call the mergeSort function on the part (low, mid) and (mid+1, high). • Step 5: This calling will continue till low<high is satisfied. • Step 6: Finally, call the merge function to merge these two halves. • Implement the Merge Sort In Python def merge_sort(arr): if len(arr) > 1: mid = len(arr) // 2 L = arr[:mid] R = arr[mid:] merge_sort(L) merge_sort(R) i = j = k = 0 while i < len(L) and j < len(R): if L[i] < R[j]: arr[k] = L[i] i += 1 else: arr[k] = R[j] j += 1 k += 1 while i < len(L): arr[k] = L[i] i += 1 k += 1 while j < len(R): arr[k] = R[j] j += 1 k += 1 arr = [12, 11, 13, 5, 6, 7] merge_sort(arr) print(arr)
  • 5. Summary • Merge Sort is a sorting algorithm that uses the divide-and-conquer approach to sort an array. It is efficient for large data sets. Merge Sort first divides the input array into smaller sub-arrays until each sub-array contains only one element. Overall, Merge Sort is a reliable and efficient sorting algorithm that is widely used in many applications. • Disadvantages of Merge Sort • Merge sort is not efficient for sorting input of large size if you are having low stack space. • Merge sort while sorting the array goes through the entire process even if the array is sorted.