SlideShare a Scribd company logo
Introduction to Merch Sort
BY GROUP 6ix
What is Merge Sort?
Merge Sort is a popular sorting algorithm that uses a technique called "divide and
conquer."that divides the input array into two halves, sorts them, and then merges the sorted
halves.
Importance in Computer Science
● Efficiency:Merge Sort has a time complexity of O(n log n), meaning it can handle large
amounts of data more quickly.
● Stability: Merge Sort is a stable sort, which means that it preserves the relative order of
equal elements.
● Divide and Conquer: Merge Sort uses the divide-and-conquer approach, which is a
powerful technique in computer science for solving complex problems by breaking
them down into simpler subproblems.
● Foundational Algorithm: Understanding Merge Sort helps in learning about more
complex algorithms and concepts in computer science, making it a foundational
algorithm for students and professionals alike.
How Merge Sort
Works:
It breaks the problem into smaller parts, solves those smaller parts, and then combines them to
get the final sorted list.
Divide:
● Step 1: Take the list and divide it into two halves.
● If the list has an odd number of elements, one half will have one more element than the other.
Conquer:
● Step 2: Recursively sort each half.
● This means you keep dividing each half into smaller halves until you have lists that are either empty
or have only one element (a single element is already sorted).
Combine:
● Step 3: Merge the sorted halves back together.
● This involves comparing the smallest elements of each half and arranging them in order, continuing
until you have a single sorted list.
Here's how it works:
Visual Representation:
Split into Two Halves:
Initial Array:
Split Each Half Again
Conquer (Sort Each Half)
Combine (Merge Sorted Halves)
Merge Sort Algorithm
Divide and Conquer: Merge Sort follows the divide-and-conquer paradigm. It divides the
input array into smaller halves recursively until each subarray contains only one element
(base case).
Sorting: Once the base case is reached (arrays of size 0 or 1), sorting begins. Each pair of
adjacent sorted subarrays is merged into a larger sorted array using the Merge function.
Merge Function: The Merge function compares elements from two sorted arrays
leftleftleft and rightrightright, ensuring that the merged array remains sorted after each
comparison and insertion.
Efficiency: Merge Sort has a time complexity of O(nlogn)O(n log n)O(nlogn) in all cases
(worst, average, and best), making it efficient for large datasets. It divides the sorting
problem into smaller subproblems and guarantees that each subproblem is solved
correctly and efficiently.
Stability: Merge Sort is stable, meaning it preserves the relative order of equal elements in
the input array.
This page is for code
and explanation of
code
And this too
Time and Space Complexity
Merge Sort has a time complexity of O(nlogn)O(n log n)O(nlogn) in all cases
(best, average, and worst). This efficiency stems from its divide-and-conquer
strategy and how it handles the merging of sorted subarrays during the sorting
process:
Breakdown of Time Complexity:
Divide Step: O(logn) divisions to reach subarrays of size 1.
Merge Step: O(n)work per level across O(logn)levels.
Combining these factors gives us the O(nlogn)time complexity for Merge Sort
in all cases.
Complexity Analysis of Merge Sort:
Time Complexity:
● Best Case: O(n log n), When the array is already sorted or nearly sorted.
● Average Case: O(n log n), When the array is randomly ordered.
● Worst Case: O(n log n), When the array is sorted in reverse order.
Space Complexity: O(n), Additional space is required for the temporary array used during
merging.
Advantages of Merge Sort:
● Stability: Merge sort is a stable sorting algorithm, which means it maintains the
relative order of equal elements in the input array.
● Guaranteed worst-case performance: Merge sort has a worst-case time
complexity of O(N logN), which means it performs well even on large datasets.
● Simple to implement: The divide-and-conquer approach is straightforward.
Disadvantage of Merge Sort:
● Space complexity: Merge sort requires additional memory to store the
merged sub-arrays during the sorting process.
● Not in-place: Merge sort is not an in-place sorting algorithm, which means
it requires additional memory to store the sorted data. This can be a
disadvantage in applications where memory usage is a concern.
Comparison to other sorts

More Related Content

PPTX
DSA- Merge Sort-a sorting technique.pptx
PPTX
merg sort slide created by anas sanan.pptx
PPTX
Data Structure Marge sort Group 5 pptx so
PPTX
MergeSort presentation dgdfgdfgdfgg.pptx
PDF
advanced algo
PPTX
Presentation merge sort.pptx
PPTX
Merge sort
PPTX
Daa final
DSA- Merge Sort-a sorting technique.pptx
merg sort slide created by anas sanan.pptx
Data Structure Marge sort Group 5 pptx so
MergeSort presentation dgdfgdfgdfgg.pptx
advanced algo
Presentation merge sort.pptx
Merge sort
Daa final

Similar to Data structure Merge Sort implementation (20)

PPTX
24671A08972ds.pptxxxxxxxxxkkkskjsjsjskskssjdhdjskw
PPTX
Merge Sort with real example using animation
PPT
Merge sort
PPTX
Merge and merge sorting
PPTX
Merj sort
PPTX
dsa presentation on merge sorting in C++.pptx
PPTX
Merge sort
PPTX
Merge Sort (w/ principle, algorithm, code, visualizations)
PPTX
Mergesort
PPTX
Merge sort analysis and its real time applications
PPTX
presentation.pptx
PPTX
Lecture -16-merge sort (slides).pptx
PPT
MergeSort algoritmos de complegidada (1).ppt
PPT
MergeSort.ppt algorithm History and Examples
PPT
MergeSort.ppt algorithm History and Examples
PPT
MergeSort_DATA_strucute_dsa_algorithm.ppt
PPT
MergeSortfbsjbjsfk sdfik k
PPTX
Module 2_ Divide and Conquer Approach.pptx
DOCX
Merge sort lab mannual
24671A08972ds.pptxxxxxxxxxkkkskjsjsjskskssjdhdjskw
Merge Sort with real example using animation
Merge sort
Merge and merge sorting
Merj sort
dsa presentation on merge sorting in C++.pptx
Merge sort
Merge Sort (w/ principle, algorithm, code, visualizations)
Mergesort
Merge sort analysis and its real time applications
presentation.pptx
Lecture -16-merge sort (slides).pptx
MergeSort algoritmos de complegidada (1).ppt
MergeSort.ppt algorithm History and Examples
MergeSort.ppt algorithm History and Examples
MergeSort_DATA_strucute_dsa_algorithm.ppt
MergeSortfbsjbjsfk sdfik k
Module 2_ Divide and Conquer Approach.pptx
Merge sort lab mannual
Ad

Recently uploaded (20)

PPTX
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
IB Computer Science - Internal Assessment.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PDF
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
PDF
annual-report-2024-2025 original latest.
PPTX
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPTX
Database Infoormation System (DBIS).pptx
PPTX
Business Acumen Training GuidePresentation.pptx
PDF
Lecture1 pattern recognition............
PPT
ISS -ESG Data flows What is ESG and HowHow
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PDF
Clinical guidelines as a resource for EBP(1).pdf
PDF
Foundation of Data Science unit number two notes
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
oil_refinery_comprehensive_20250804084928 (1).pptx
DISORDERS OF THE LIVER, GALLBLADDER AND PANCREASE (1).pptx
Miokarditis (Inflamasi pada Otot Jantung)
IB Computer Science - Internal Assessment.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
Acceptance and paychological effects of mandatory extra coach I classes.pptx
“Getting Started with Data Analytics Using R – Concepts, Tools & Case Studies”
annual-report-2024-2025 original latest.
Introduction to Firewall Analytics - Interfirewall and Transfirewall.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Database Infoormation System (DBIS).pptx
Business Acumen Training GuidePresentation.pptx
Lecture1 pattern recognition............
ISS -ESG Data flows What is ESG and HowHow
STUDY DESIGN details- Lt Col Maksud (21).pptx
Clinical guidelines as a resource for EBP(1).pdf
Foundation of Data Science unit number two notes
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
oil_refinery_comprehensive_20250804084928 (1).pptx
Ad

Data structure Merge Sort implementation

  • 1. Introduction to Merch Sort BY GROUP 6ix
  • 2. What is Merge Sort? Merge Sort is a popular sorting algorithm that uses a technique called "divide and conquer."that divides the input array into two halves, sorts them, and then merges the sorted halves. Importance in Computer Science ● Efficiency:Merge Sort has a time complexity of O(n log n), meaning it can handle large amounts of data more quickly. ● Stability: Merge Sort is a stable sort, which means that it preserves the relative order of equal elements. ● Divide and Conquer: Merge Sort uses the divide-and-conquer approach, which is a powerful technique in computer science for solving complex problems by breaking them down into simpler subproblems. ● Foundational Algorithm: Understanding Merge Sort helps in learning about more complex algorithms and concepts in computer science, making it a foundational algorithm for students and professionals alike.
  • 3. How Merge Sort Works: It breaks the problem into smaller parts, solves those smaller parts, and then combines them to get the final sorted list. Divide: ● Step 1: Take the list and divide it into two halves. ● If the list has an odd number of elements, one half will have one more element than the other. Conquer: ● Step 2: Recursively sort each half. ● This means you keep dividing each half into smaller halves until you have lists that are either empty or have only one element (a single element is already sorted). Combine: ● Step 3: Merge the sorted halves back together. ● This involves comparing the smallest elements of each half and arranging them in order, continuing until you have a single sorted list. Here's how it works:
  • 4. Visual Representation: Split into Two Halves: Initial Array: Split Each Half Again Conquer (Sort Each Half) Combine (Merge Sorted Halves)
  • 5. Merge Sort Algorithm Divide and Conquer: Merge Sort follows the divide-and-conquer paradigm. It divides the input array into smaller halves recursively until each subarray contains only one element (base case). Sorting: Once the base case is reached (arrays of size 0 or 1), sorting begins. Each pair of adjacent sorted subarrays is merged into a larger sorted array using the Merge function. Merge Function: The Merge function compares elements from two sorted arrays leftleftleft and rightrightright, ensuring that the merged array remains sorted after each comparison and insertion. Efficiency: Merge Sort has a time complexity of O(nlogn)O(n log n)O(nlogn) in all cases (worst, average, and best), making it efficient for large datasets. It divides the sorting problem into smaller subproblems and guarantees that each subproblem is solved correctly and efficiently. Stability: Merge Sort is stable, meaning it preserves the relative order of equal elements in the input array.
  • 6. This page is for code and explanation of code
  • 8. Time and Space Complexity Merge Sort has a time complexity of O(nlogn)O(n log n)O(nlogn) in all cases (best, average, and worst). This efficiency stems from its divide-and-conquer strategy and how it handles the merging of sorted subarrays during the sorting process: Breakdown of Time Complexity: Divide Step: O(logn) divisions to reach subarrays of size 1. Merge Step: O(n)work per level across O(logn)levels. Combining these factors gives us the O(nlogn)time complexity for Merge Sort in all cases.
  • 9. Complexity Analysis of Merge Sort: Time Complexity: ● Best Case: O(n log n), When the array is already sorted or nearly sorted. ● Average Case: O(n log n), When the array is randomly ordered. ● Worst Case: O(n log n), When the array is sorted in reverse order. Space Complexity: O(n), Additional space is required for the temporary array used during merging. Advantages of Merge Sort: ● Stability: Merge sort is a stable sorting algorithm, which means it maintains the relative order of equal elements in the input array. ● Guaranteed worst-case performance: Merge sort has a worst-case time complexity of O(N logN), which means it performs well even on large datasets. ● Simple to implement: The divide-and-conquer approach is straightforward.
  • 10. Disadvantage of Merge Sort: ● Space complexity: Merge sort requires additional memory to store the merged sub-arrays during the sorting process. ● Not in-place: Merge sort is not an in-place sorting algorithm, which means it requires additional memory to store the sorted data. This can be a disadvantage in applications where memory usage is a concern.