-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path4-mergeSort.js
More file actions
30 lines (18 loc) · 1013 Bytes
/
4-mergeSort.js
File metadata and controls
30 lines (18 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
///////////////////////////////////////////////////////
////////////*** MERGE SORT QUESTION ***////////////
///////////////////////////////////////////////////////
// Merges two already sorted arrays
//pseudocode
// 1. create an empty arr, take a look at the smallest values in each input arr.
// 2. while there are still values, we haven't looked at ..
// 2-1. if the value in the first arr is smaller than the value in the second arr, push the val in the first arr into our results and move on to the next value in the first arr.
// 2-2. if the val in the first arr is larger than the val in the second arr, push the val in the second arr into our results and move on to the next val in the second arr.
// 2-3. once we exhaust one arr, push in all remaining val from the other arr.
console.log(merge([2, 3, 4, 5], [1, 100, 200, 300]))
//[
// 1, 2, 3, 4, 5,
// 8, 100, 300, 800
// ]
//explain this sorting method's big O notation
// time complexity:
// space complexity: