DSA Lab 5 Merge Sort
DSA Lab 5 Merge Sort
• Merge sort first divides the array into equal halves and then
combines them in a sorted manner.
• Merge sort keeps on dividing the list into equal halves until it can
no more be divided. By definition, if it is only one element in the
list, it is sorted. Then, merge sort combines the smaller sorted
lists keeping the new list sorted too.
• Step 1 − if it is only one element in the list it is already sorted,
return.
• Step 2 − divide the list recursively into two halves until it can no
more be divided.
• Step 3 − merge the smaller lists into new list in sorted order.
CSC-221 Data Structures and Algorithm Bahria University Karachi Campus
MERGE FUNCTION ALGORITHM
1. Implement merge sort algorithm to merge two integer arrays into a third
array in sorted order.