Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
68 views2 pages

Merge Sort

Merge Sort is a divide-and-conquer sorting algorithm developed by John von Neumann in 1945, which recursively splits an array into halves, sorts them, and merges the sorted halves. Its time complexity is O(n log n) for best, average, and worst cases, with a space complexity of O(n) due to temporary arrays. An example demonstrates sorting the array [38, 27, 43, 3, 9, 82, 10] into [3, 9, 10, 27, 38, 43, 82].

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

Merge Sort

Merge Sort is a divide-and-conquer sorting algorithm developed by John von Neumann in 1945, which recursively splits an array into halves, sorts them, and merges the sorted halves. Its time complexity is O(n log n) for best, average, and worst cases, with a space complexity of O(n) due to temporary arrays. An example demonstrates sorting the array [38, 27, 43, 3, 9, 82, 10] into [3, 9, 10, 27, 38, 43, 82].

Uploaded by

Subhadip Das
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Merge Sort – Report

1. Introduction

Merge Sort is an efficient, general-purpose, comparison-based divide-and-conquer sorting


algorithm. It was invented by John von Neumann in 1945. Merge Sort divides the input array into
two halves, sorts them recursively, and then merges the sorted halves.

2. How It Works

Merge Sort follows the divide-and-conquer strategy:

1. Divide: Split the array into two halves.

2. Conquer: Recursively sort both halves.

3. Combine: Merge the sorted halves into a single sorted array.

3. Algorithm (Pseudocode)

plaintext

CopyEdit

MergeSort(arr[], l, r)

if l < r:

m = (l + r) / 2

MergeSort(arr, l, m)

MergeSort(arr, m+1, r)

Merge(arr, l, m, r)

Merge(arr[], l, m, r)

Create temporary arrays L[] and R[]

Copy data to L[] and R[]

Merge L[] and R[] into arr[]

4. Time and Space Complexity

Case Time Complexity

Best Case O(n log n)

Average Case O(n log n)


Case Time Complexity

Worst Case O(n log n)

• Space Complexity: O(n) – due to the use of temporary arrays during the merge step.

5. Example

For the array: [38, 27, 43, 3, 9, 82, 10]

1. Divide: [38, 27, 43] and [3, 9, 82, 10]

2. Further divide until subarrays of size 1

3. Merge step-by-step:

o [27, 38, 43], [3, 9, 10, 82]

o Final merge: [3, 9, 10, 27, 38, 43, 82]

You might also like