0% found this document useful (0 votes)
11 views4 pages

Template For DSA Lab 4 - 0021

Uploaded by

Two Punch Fire
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)
11 views4 pages

Template For DSA Lab 4 - 0021

Uploaded by

Two Punch Fire
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/ 4

Roll Number: 2023F-BCNS-007 Lab Number: 04

LABORATORY EXERCISE 4
Objective:
 Follow instructions to implement and compare linear and binary search algorithms
on arrays and explore their efficiencies.

Lab Tasks
Task 01(a) Objective:

a) Write an algorithm to create a python module to implement linear searching technique to


search a key element or its index from the given list of integers.

Source Code:

Output/Result:

BS Computer Networks and Security, TED


Sir Syed University of Engineering & Technology Page | 1
Roll Number: 2023F-BCNS-007 Lab Number: 04

Task 01(b) Objective:

b) Consider a company ABC having 25 employees working in different departments. Company


has decided to increase the pay of those employees by 50% whose salaries are 5000. Search the
employees having salary equal to 5000 and print their incremented salaries along with their id’s.
Generate a list of 25 random integers ranging up to 2000-80000 representing the salary of
employees of ABC company. Solve the problem given in part b by using module created in part
a. Assume that the id of employee is the index of array in which random integers are generated.

Source Code:

Output/Result:

BS Computer Networks and Security, TED


Sir Syed University of Engineering & Technology Page | 2
Roll Number: 2023F-BCNS-007 Lab Number: 04

Task 02(a) Objective:

a) Write an algorithm to create a python module to implement binary searching technique to


search a key element or its index from the given list of integers.

Source Code:

Output/Result:

BS Computer Networks and Security, TED


Sir Syed University of Engineering & Technology Page | 3
Roll Number: 2023F-BCNS-007 Lab Number: 04

Task 02(b) Objective:

b) Consider a company ABC having 25 employees working in different departments. Company


has decided to increase the pay of those employees by 50% whose salaries are 5000. Search the
employees having salary equal to 5000 and print their incremented salaries along with their id’s.
Generate a list of 25 random integers ranging up to 2000-80000 representing the salary of
employees of ABC company. Solve the problem given in part b by using module created in part
a. Assume that the id of employee is the index of array in which random integers are generated.

Source Code:

Output/Result:

Lab 04 Conclusion:

We tested two searching methods: Linear Search and Binary Search. Binary Search
works best for large datasets, while Linear Search is slower for bigger lists.
Overall, Binary Search is usually the most efficient for the given tasks.

BS Computer Networks and Security, TED


Sir Syed University of Engineering & Technology Page | 4

You might also like