SlideShare a Scribd company logo
Merge Sort
The basic idea behind merge sort is this: it tends to be a lot easier to
sort two smaller, sorted lists rather than sorting a single large, unsorted
one.
Flowchart:
1.
2.
Concept of Divide and Conquer Algorithm:
• Divide : Break the given problem into subproblems of same
type.
• Conquer : Recursively solve these subproblems.
• Combine : Appropriately combine the answers.
Code:
• https://replit.com/@JatinBhat/Merge-Sort#main.c
Characteristics of merge sort:
1) Merge sort is an External sorting algorithm (just like quick sort).
External sorting is a term for a class of sorting algorithms that can
handle massive amounts of data.
External sorting is required when the data being sorted does not fit into
the main memory of a computing device (usually RAM).
In the sorting phase, chunks of data small enough to fit in the main
memory are read, sorted, and written out to a temporary file. In the
merge phase, the sorted sub-files are combined into a single larger file.
2) Merge sort is stable.
Time complexity:
Merge Sort (w/ principle, algorithm, code, visualizations)
Space complexity:
Visualizers:
1. https://youtu.be/ZRPoEKHXTJg?si=ivrPbxAH6GBRyX2s
2. https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.ht
ml
3. https://www.hackerearth.com/practice/algorithms/sorting/merge-
sort/visualize/
Advantages:
1. Faster runtime: Because merge sort is generally implemented recursively that
makes it faster than the other algorithms we’ve looked at thus far.
Note: Slower Iterative merge sort code:
https://www.techiedelight.com/iterative-merge-sort-algorithm-bottom-up/
2) Consistent Performance: It guarantees O(n log n) time complexity
for worst, average, and best-case scenarios. This makes it a reliable
choice for sorting large datasets.
3) Efficient for Linked Lists: Merge sort does not depend on
indices.
4) External Sorting: Merge sort is well-suited for external
sorting, where data is too large to fit into the computer's main
memory. It can efficiently merge sorted chunks of data from
external storage, minimizing the need for extensive random
access.
Disadvantage:
1) Space Complexity: Merge sort requires additional space
proportional to the size of the input array.
1) Not In-Place: In an in-place algorithm, the sorting is performed using
a constant amount of extra memory.
2) Slower on Small Datasets: less efficient compared to simpler
algorithms like insertion sort or bubble sort.
3) Complexity of Implementation: While the basic idea of merge sort is
simple, the actual implementation can be more complex than some other
sorting algorithms.
4) Not Adaptive: Merge sort does not take advantage of existing order in
the dataset. Even if the input is partially sorted, merge sort still divides
and merges the data in the same way, resulting in the same time
complexity.
5) Cache Inefficiency: The sequential access pattern of merge sort might
result in poor cache locality, especially on modern computer
architectures where cache efficiency is crucial for performance. This can
Criteria Merge Sort Selection Sort Bubble Sort
Time Complexity O(n log n) O(n^2) O(n^2)
Space Complexity O(n) (additional space) O(1) O(1)
In-Place Sorting
No (requires additional
space)
Yes Yes
Stable Sorting Yes No Yes
Adaptive No No
Yes (with optimized
version)
Suitable for Small Arrays No Yes (for small datasets) Yes (for small datasets)
Recursive Implementation Yes No No
Iterative Implementation Yes Yes Yes
Practical Performance Efficient for large datasets
Inefficient for large
datasets
Inefficient for large
datasets
Use Cases
General-purpose sorting
algorithm
Small datasets or partially
sorted data
Educational purposes,
simple sorting tasks

More Related Content

PDF
DB ppt OS unit - 3.pdf
PPTX
Dos unit3
PDF
lecture-2-3_Memory.pdf,describing memory
PDF
Memory Management
PPTX
Memory allocation for real time operating system
PPTX
Blue and Green Narrative Writing Story Starters Education Presentation _20241...
PPTX
slidesgo-mastering-merge-sort-efficient-sorting-techniques-for-modern-applica...
PPT
Chapter 9 OS
 
DB ppt OS unit - 3.pdf
Dos unit3
lecture-2-3_Memory.pdf,describing memory
Memory Management
Memory allocation for real time operating system
Blue and Green Narrative Writing Story Starters Education Presentation _20241...
slidesgo-mastering-merge-sort-efficient-sorting-techniques-for-modern-applica...
Chapter 9 OS
 

Similar to Merge Sort (w/ principle, algorithm, code, visualizations) (20)

PPTX
Os unit 3
PDF
cachememory-210517060741 (1).pdf
PPTX
Cache Memory
PDF
Fixed partitioning of memory
PPTX
Linux Memory Management with CMA (Contiguous Memory Allocator)
PPTX
local_media3192961381667787861026781.pptx
PPT
Chapter 2 part 1
PPTX
Paging +Algorithem+Segmentation+memory management
PDF
Applying Machine Learning to Software Clustering
PPTX
contiguous memory allocation.pptx
PPT
Chapter07_ds.ppt
PPT
Memory organization including cache and RAM.ppt
PPTX
Introduction to Cache FOR ENGINEERING IN 1ST SEM.pptx
PPTX
PARALLEL DATABASE SYSTEM in Computer Science.pptx
PPTX
Memory Managementgggffffffffffgggggggggg
PDF
Dynamic loading
PPT
7. Memory management in operating system.ppt
PDF
INTRODUCTION TO OPERATING SYSTEM_LESSON_2_SHARE.pdf
PDF
Introduction to Parallel Computing
PPTX
Paging & segmentation; advantages and disadvantage
Os unit 3
cachememory-210517060741 (1).pdf
Cache Memory
Fixed partitioning of memory
Linux Memory Management with CMA (Contiguous Memory Allocator)
local_media3192961381667787861026781.pptx
Chapter 2 part 1
Paging +Algorithem+Segmentation+memory management
Applying Machine Learning to Software Clustering
contiguous memory allocation.pptx
Chapter07_ds.ppt
Memory organization including cache and RAM.ppt
Introduction to Cache FOR ENGINEERING IN 1ST SEM.pptx
PARALLEL DATABASE SYSTEM in Computer Science.pptx
Memory Managementgggffffffffffgggggggggg
Dynamic loading
7. Memory management in operating system.ppt
INTRODUCTION TO OPERATING SYSTEM_LESSON_2_SHARE.pdf
Introduction to Parallel Computing
Paging & segmentation; advantages and disadvantage
Ad

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
System and Network Administration Chapter 2
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
L1 - Introduction to python Backend.pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
ai tools demonstartion for schools and inter college
PDF
Digital Strategies for Manufacturing Companies
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Operating system designcfffgfgggggggvggggggggg
Softaken Excel to vCard Converter Software.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Wondershare Filmora 15 Crack With Activation Key [2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How Creative Agencies Leverage Project Management Software.pdf
Design an Analysis of Algorithms II-SECS-1021-03
System and Network Administration Chapter 2
wealthsignaloriginal-com-DS-text-... (1).pdf
Navsoft: AI-Powered Business Solutions & Custom Software Development
Internet Downloader Manager (IDM) Crack 6.42 Build 41
L1 - Introduction to python Backend.pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
ai tools demonstartion for schools and inter college
Digital Strategies for Manufacturing Companies
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Ad

Merge Sort (w/ principle, algorithm, code, visualizations)

  • 2. The basic idea behind merge sort is this: it tends to be a lot easier to sort two smaller, sorted lists rather than sorting a single large, unsorted one.
  • 4. 2.
  • 5. Concept of Divide and Conquer Algorithm: • Divide : Break the given problem into subproblems of same type. • Conquer : Recursively solve these subproblems. • Combine : Appropriately combine the answers.
  • 7. Characteristics of merge sort: 1) Merge sort is an External sorting algorithm (just like quick sort). External sorting is a term for a class of sorting algorithms that can handle massive amounts of data. External sorting is required when the data being sorted does not fit into the main memory of a computing device (usually RAM). In the sorting phase, chunks of data small enough to fit in the main memory are read, sorted, and written out to a temporary file. In the merge phase, the sorted sub-files are combined into a single larger file.
  • 8. 2) Merge sort is stable.
  • 13. Advantages: 1. Faster runtime: Because merge sort is generally implemented recursively that makes it faster than the other algorithms we’ve looked at thus far. Note: Slower Iterative merge sort code: https://www.techiedelight.com/iterative-merge-sort-algorithm-bottom-up/
  • 14. 2) Consistent Performance: It guarantees O(n log n) time complexity for worst, average, and best-case scenarios. This makes it a reliable choice for sorting large datasets. 3) Efficient for Linked Lists: Merge sort does not depend on indices. 4) External Sorting: Merge sort is well-suited for external sorting, where data is too large to fit into the computer's main memory. It can efficiently merge sorted chunks of data from external storage, minimizing the need for extensive random access.
  • 15. Disadvantage: 1) Space Complexity: Merge sort requires additional space proportional to the size of the input array. 1) Not In-Place: In an in-place algorithm, the sorting is performed using a constant amount of extra memory. 2) Slower on Small Datasets: less efficient compared to simpler algorithms like insertion sort or bubble sort. 3) Complexity of Implementation: While the basic idea of merge sort is simple, the actual implementation can be more complex than some other sorting algorithms. 4) Not Adaptive: Merge sort does not take advantage of existing order in the dataset. Even if the input is partially sorted, merge sort still divides and merges the data in the same way, resulting in the same time complexity. 5) Cache Inefficiency: The sequential access pattern of merge sort might result in poor cache locality, especially on modern computer architectures where cache efficiency is crucial for performance. This can
  • 16. Criteria Merge Sort Selection Sort Bubble Sort Time Complexity O(n log n) O(n^2) O(n^2) Space Complexity O(n) (additional space) O(1) O(1) In-Place Sorting No (requires additional space) Yes Yes Stable Sorting Yes No Yes Adaptive No No Yes (with optimized version) Suitable for Small Arrays No Yes (for small datasets) Yes (for small datasets) Recursive Implementation Yes No No Iterative Implementation Yes Yes Yes Practical Performance Efficient for large datasets Inefficient for large datasets Inefficient for large datasets Use Cases General-purpose sorting algorithm Small datasets or partially sorted data Educational purposes, simple sorting tasks