cs3401 Lab Manual - IGCE
cs3401 Lab Manual - IGCE
TRICHY - 12
B.E (CSE)
IV SEMESTER
REGULATION R -2021
CS3401 – ALGORITHMS
LAB MANUAL
lOMoARcPSD|39223546
Ex. Page
No. Date Name of The Experiments No. Marks Sign.
Graph Algorithms
EX. NO: 1 Implement Linear Search. Determine the time required to search
for element. Repeat the experiment for different values of n, the
number of elements in the list to besearched and plot a graph of the
time taken versus n.
Aim:
To implement Linear Search, measure its time complexity for searching an element,
vary the input size by changing the number of elements in the list, and plot a graph to visualize
the relationship between time taken and input size
Algorithm:
Note:
This code first implements the linear_search function which takes a list arr and an
element x as input and returns the index of x in arr if it exists, otherwise returns -1. The function
measure_time takes a number n as input and returns the time taken to search for an element
that is not in the list of n elements. The main block of code then creates a list of n_values, each
representing the number of elements in the list, and measures the time taken to search for an
element in each of these lists. Finally, it plots the graph of the time taken versus n.