Posts

Showing posts with the label merge sort pseudo code

Merge Sort Algorithm

Image
Merge Sort is a sorting algorithm that implement divide and conquer method. It generally use to motivates guiding principles for algorithm analysis (worst-case and asymptotic analysis) and also provide the analysis generalizes to “Master Method”. (PS: algorithm also known as Pseudocode.) Purpose of merge sort: If you given an arrays of n numbers that is unsorted for example like "5,4,1,8,7,2,6,3", you are required have the output of the same number arrays sorted in increasing order like"1,2,3,4,5,6,7,8". Illustrate how merge sort work How Merge sort Work? The arrays will divide into half Recursively  sort the first half of the input array recursively sort the second half of the input array Merge the 2 sorted half array into 1 like the picture above. Pseudocode for Merge: C = output [length = n] A = 1st sorted array [n/2] B = 2nd sorted array [n/2] i = 1 j = 1