DSA LAB 05 OpenEnded
DSA LAB 05 OpenEnded
Instructions:
Take snapshots of both input and output and provide a brief summary explaining what you
have learned in this lab.
Lab Tasks:
Task 1:
Implement functions for linear search and binary search to find and display the
information (name, contact etc.) of a specific student based on their ID.
Allow the user to choose between linear and binary search for searching.
Task 2:
Extend the program to handle multiple subjects for each student, with each subject
having different weightage. Implement a bubble sort algorithm that takes into
account the weights of each subject and sorts the list of students based on their
weighted average grades in descending order.
Task 3:
Modify the program to determine whether a given square matrix is not only
symmetric but also a sparse matrix. A sparse matrix is one in which most of the
elements are zero.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Task 4:
Analyze the time complexity of linear search. Discuss its performance on sorted and
unsorted data.
Hint:
Time Complexity Analysis:
For Unsorted Data:
Best-case: O (1) - Target is the first element.
Average-case: O (n/2) - Average comparison until finding the target.
Worst-case: O (n) - Target is the last element or not in the array.
Task 5:
Task 1:
Implement functions for linear search and binary search to find and display the information
(name, contact etc.) of a specific student based on their ID.
Allow the user to choose between linear and binary search for searching.
CODE:
OUTPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Task 2:
Extend the program to handle multiple subjects for each student, with each subject having
different weightage. Implement a bubble sort algorithm that takes into account the weights of
each subject and sorts the list of students based on their weighted average grades in descending
order.
CODE:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
OUTPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Task 3:
Modify the program to determine whether a given square matrix is not only symmetric but also a
sparse matrix. A sparse matrix is one in which most of the elements are zero.
CODE:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
OUTPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Task 4:
Analyze the time complexity of linear search. Discuss its performance on sorted and unsorted
data.
Hint:
Time Complexity Analysis:
For Unsorted Data:
Best-case: O (1) - Target is the first element.
Average-case: O (n/2) - Average comparison until finding the target.
Worst-case: O (n) - Target is the last element or not in the array.
CODE:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
OUTPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Task 5:
Implement an efficient algorithm using binary search to search for a specific element in a partially
sorted 2D matrix. In this case, each row is sorted, but the columns might not be in sorted order.
CODE:
OUTPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
SUMMARY:
In the following lab we learnt how to perform binary and linear search using different data
types and while putting different conditions and learning how to apply them, including
bubble sort algorithm by giving numerous data of students. We also found a way how to
check time complexity of a code and opting it’s different cases: best, average and worst
cases.