8000 Create Merge Sort.md · Gekk0r/Algorithms-Explanation@a5b00f5 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5b00f5

Browse files
authored
Create Merge Sort.md
1 parent c8a73ab commit a5b00f5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Sorting Algorithms/Merge Sort.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Merge Sort (Divide and Conquer Algorithm)
2+
3+
#### Problem Statement
4+
5+
Given an array of n elements, write a function to sort the array
6+
7+
#### Approach
8+
9+
- Find a mid point and divide the array into to halves based on the mid point
10+
- Recursively call the merge sort function for both the halves
11+
- Merge the two sorted halves to get the sorted array
12+
13+
#### Time Complexity
14+
15+
O(nLogn)
16+
17+
#### Space Complexity
18+
19+
O(n)
20+
21+
#### Example
22+
23+
```
24+
arr = [1, 3, 9, 5, 0, 2]
25+
26+
Divide the array in two halves [1, 3, 9] and [5, 0, 2]
27+
28+
Recursively call merge sort function for both these halves which will provide sorted halves
29+
=> [1, 3, 9] & [0, 2, 5]
30+
31+
Now merge both these halves to get the sorted array [0, 1, 2, 3, 5, 9]
32+
```
33+
34+
#### Code Implementation Links
35+
36+
- [Java](https://github.com/TheAlgorithms/Java/blob/master/Sorts/MergeSort.java)
37+
- [C++](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/Sorting/Merge%20Sort.cpp)
38+
- [Python](https://github.com/TheAlgorithms/Python/blob/master/sorts/merge_sort.py)
39+
- [C-Sharp](https://github.com/TheAlgorithms/C-Sharp/blob/master/sorts/merge_sort.cs)
40+
- [C](https://github.com/TheAlgorithms/C/blob/master/sorting/mergesort.c.c)
41+
42+
#### Video Explanation
43+
44+
[A CS50 video explaining the Merge Sort Algorithm](https://www 3207 .youtube.com/watch?v=EeQ8pwjQxTM)

0 commit comments

Comments
 (0)
0