0% found this document useful (0 votes)
8 views2 pages

Most of the Matplotlib utilities lies under the pyplot submodule

The document provides a Python script that utilizes Matplotlib's pyplot module to visualize the time efficiency of a linear search algorithm. It prompts the user to input an array of elements and a key to search for, measuring the CPU processing time for each search. The results are plotted on a graph with the array size on the x-axis and CPU processing time on the y-axis.

Uploaded by

msanthoshm379
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Most of the Matplotlib utilities lies under the pyplot submodule

The document provides a Python script that utilizes Matplotlib's pyplot module to visualize the time efficiency of a linear search algorithm. It prompts the user to input an array of elements and a key to search for, measuring the CPU processing time for each search. The results are plotted on a graph with the array size on the x-axis and CPU processing time on the y-axis.

Uploaded by

msanthoshm379
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Most of the Matplotlib utilities lies under the pyplot submodule, and are usually

imported under the plt alias: import matplotlib.pyplot as plt. Now the Pyplot
package can be referred to as plt .
import timeit
import matplotlib.pyplot as plt
# Input Array elments
def Input(Array, n):
# iterating till the range
for i in range(0, n):
ele = int(input("Arr : "))
# adding the element
Array.append(ele)
# Linear Searching
def linear_search(Array, key):
for x in Array:
if x == key:
return True
return False
# Main Block()
N=[]
CPU=[]
trail = int(input("Enter no. of trails : "))
for t in range(0, trail):
Array = []
print("-----> TRAIL NO : ", t + 1)
n = int(input("Enter number of elements : "))
Input(Array, n)
print(Array)
key = int(input("Enter key :"))
start = timeit.default_timer()
s = linear_search(Array, key)
print("Element Found = ", s)
times = timeit.default_timer() - start
N.append(n)
CPU.append(round(float(times) * 1000000, 2))
print("N CPU")
for t in range(0, trail):
print(N[t], CPU[t])
# Plotting Graph
plt.plot(N, CPU)
plt.scatter(N, CPU, color= "red", marker= "*", s=50)
# naming the x axis
plt.xlabel('Array Size - N')
# naming the y axis
plt.ylabel('CPU Processing Time')
# giving a title to graph
plt.title('Linear Search Time efficiency')
# function to show the plot
plt.show()

You might also like