Professional Documents
Culture Documents
Cse2202 LabReport03
Cse2202 LabReport03
CSE 2202
Lab Report 02
Name of the Experiment: Complexity analysis of searching algorithm (Linear search and
Binary search)
Date of the Experiment: 10/10/2022
Date of Submission: 17/10/2022
INDEX
1|Page
Lab Report 03
1. 3
Title
2. Objective 3
3. Theory 3-5
4. Table 6
5. Graph 6
6. Discussion 7
MACHINE CONFIGURATION:
2|Page
Lab Report 03
Title: Complexity analysis of searching algorithm (Linear search and Binary search)
Objective:
Theory:
Linear Search:
Linear Search is defined as a sequential search algorithm that starts at one end and goes through each element of
a list until the desired element is found, otherwise the search continues till the end of the data set. It is the
easiest searching algorithm.
Algorithm
Linear_Search(A,x)
Set i to 1.
Set i to i + 1.
Return i.
Recursive
LinearSearch(value, list)
3|Page
Lab Report 03
else
if the first item of the list has the desired value, return its location;
Binary Search:
Algorithm:
Begin with the mid element of the whole array as a search key.
If the value of the search key is equal to the item then return an index of the search key.
Or if the value of the search key is less than the item in the middle of the interval, narrow the interval to
the lower half.
Repeatedly check from the second point until the value is found or the interval is empty.
1. Iterative Method
2. Recursive Method
1. Iteration Method
if (x == arr[mid])
return mid
low = mid + 1
high = mid - 1
4|Page
Lab Report 03
2. Recursive Method (The recursive method follows the divide and conquer approach)
return False
else
if x == arr[mid]
return mid
Binary Search:
Graph:
Linear Search:
6|Page
Lab Report 03
Binary Search:
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.
7|Page