Professional Documents
Culture Documents
CSE 2202
Lab Report 03
Name of the Experiment: Complexity analysis of Finding Maximum and Minimum Value
[Max-Min Algorithm] and various sorting algorithms [Quick Sort and Merge Sort].
Date of the Experiment: 10/10/2022
Date of Submission: 17/10/2022
1|P age
Lab Report 03
INDEX
1. 3
Title
2. Objective 3
3. Theory 3-5
4. Table 6
5. Graph 6
6. Discussion 7
2|P age
Lab Report 03
MACHINE CONFIGURATION:
Title: Complexity analysis of Finding Maximum and Minimum Value [Max-Min Algorithm] and various
sorting algorithms [Quick Sort and Merge Sort].
Objective:
Theory:
Merge Sort:
The Merge Sort algorithm is a sorting algorithm that is based on the Divide and Conquer paradigm. In this
algorithm, the array is initially divided into two equal halves and then they are combined in a sorted manner.
Algorithm:
step 1: start
step 4: Stop
3|P age
Lab Report 03
MergeSort(arr[], l, r)
If r > l
• Find the middle point to divide the array into two halves:
• middle m = l + (r – l)/2
• Call mergeSort(arr, l, m)
• Call mergeSort(arr, m + 1, r)
• Call merge(arr, l, m, r)
Quick Sort:
QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array
around the picked pivot. There are many different versions of quickSort that pick pivot in different ways.
The key process in quickSort is a partition(). The target of partitions is, given an array and an element x of an
array as the pivot, put x at its correct position in a sorted array and put all smaller elements (smaller than x)
before x, and put all greater elements (greater than x) after x. All this should be done in linear time.
/* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and
places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */
Complexity:
5|P age
Lab Report 03
Data Table:
Quick Sort:
6|P age
Lab Report 03
Merge Sort:
7|P age
Lab Report 03
Graph:
Quick Sort:
8|P age
Lab Report 03
Merge Sort:
9|P age
Lab Report 03
Discussion:
In this lab, we have analysis the complexity of quick sort and merge sort. The main difference between
quicksort and merge sort is that the quicksort sorts the elements by comparing each element with an element
called a pivot while merge sort divides the array into two subarrays again and again until one element is left.
Sorting is the method of arranging data in a particular order.
Merge sort and quick sort are suitable for larger input sizes but quick sort perform slow .
From our graphs and experiment Quick sort algorithm is slightly faster than Merge sort algorithm and largely
faster than the Insertion sort algorithm.
10 | P a g e