






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







Your Date Here Your Footer Here ALGORITHM
OUTLINE HOW MERGE SORT WORKS GENERAL PRINCIPLES USING SAMPLE ARRAY TIME COMPLEXITIES
INTRODUCTION USING CODE SAMPLE
How Merge Sort uses “Divide and Conquer Algorithm: 4 It basically has 3 steps:
MERGE GENERAL PRINCIPLES SORT Sorting Problem: Sort a sequence of n elements into non-decreasing order. Divide: Split array in half Conquer: Call merge sort on each half to sort them recursively Combine: Merge both halves into one sorted array.
(^) Worst Case Time Complexity: O(nlog n)* 7 ALGORITHM (^) Best Case Time Complexity: O(nlog n)* Average Time Complexity: O(nlog n)*
Your Date Here 8 #include
//calculate sizes of left and right arrays int size1 = sizeof(arrL)/sizeof(arrL[0]); int size2 = sizeof(arrR)/sizeof(arrR[0]); int dex1, dex2, dex3;//index variables for left, right and merged arrays //copy data to temporary arrays for(dex1=0;dex1<size1;dex1++){ arrL[dex1] = arr[left+dex1]; } for(dex2=0;dex2<size2;dex2++){ arrR[dex2] = arr[mid+1+dex2]; }
M