Sample Experiment DAA
Sample Experiment DAA
of CSIT
Dr. Parimal Kumar Giri
Experiment #3
Aim of the Experiment:
Write a program to perform Merge Sort for the given list of integer values.
Objective:
To familiarized with the implementation of Merge Sort Algorithm
Theory:
Merge sort is a divide-and-conquer sorting algorithm that divides an array into two halves,
sorts each half, and then merges them back together in a sorted fashion. The merge operation,
which combines two sorted arrays into a single sorted array, is the key step in the merge sort
algorithm. The algorithm does this by comparing the first element of each array and adding
the smaller of the two to the result array. This process is then repeated until both input arrays
have been fully merged. This process is repeated on each half of the array recursively until
the entire array is sorted.
The following diagram shows the complete merge sort process for an example array {38,
27, 43, 3, 9, 82, 10}.
If we take a closer look at the diagram, we can see that the array is recursively divided into
two halves till the size becomes 1. Once the size becomes 1, the merge processes come into
action and start merging arrays back till the complete array is merged.
Algorithms:
Algorithm Merge()
Code:
C Programming Code
Output:
Copy and Paste Output Screen here
Discussion:
In this program merge sort algorithm is implemented where number 38, 27, 43, 3, 9, 82, and
10 are provided as a input and was sorted as 3,9,10,27, 38, 43, 82 in ascending order.
Time Complexity:
Merge Sort is a recursive algorithm and time complexity can be expressed as following
recurrence relation.
This implementation of merge sort is recursive and has a time complexity of O (n log n)
using Masters Method, making it more efficient than some other sorting algorithms for large
inputs.
Space Complexity:
• In merge sort all elements are copied into an auxiliary array
• So n auxiliary space is required for merge sort.
Auxiliary Space: O (n)
Conclusion:
Hence in this lab we are familiarized with the concept of merge sort algorithm