CSCL 2102 Lab Data Structures and Algorithms BS AI 3A
CSCL 2102 Lab Data Structures and Algorithms BS AI 3A
IMPORTANT instructions:
Students are strictly advised not to bring cell phones/smart watch and/or any
kind of electronic devices in the examination hall except for a simple
calculator (if allowed). If they bring any such devices in the examination hall,
they should make sure that the cell phones/smart watch and/or any other
electronic device is properly switched off. Otherwise, a penalty including “F”
grade could be awarded.
Read all the questions carefully first and then ask for clarifications.
Question paper related queries will not be entertained after 30 minutes for midterm
exams and 60 minutes for final exam after the start of the exam.
Do not write anything on the question paper unless specifically asked to do so by your
course instructor.
Marks of each question are mentioned at the end of each question.
BT
CLO Description Domain
Level*
Implement various data Structures and their algorithms and Cognitive
1 2,3
apply them in implementing simple applications. domain
Implement hash tables, including collision avoidance and Cognitive
2 2
resolution. domain
*BT=Bloom’s Taxonomy, C=Cognitive domain, P=Psychomotor domain, A=Affective
domain
SHAHEED ZULFIKAR ALI BHUTTO INSTITUTE OF
SCIENCE AND TECHNOLOGY UNIVERSITY
Section- A
Second Algorithm:
if the last digit of n is 0, 2, 4, 6, or 8
n is even
else
n is odd
Calculate the number of steps taken by these programs for the following values and determine
which algorithm is faster. Assume the computer takes 1 millisecond for each step.
i. n = 7
ii. n = 42
iii. n = 1003
iv. n = 987654321
Implement the bubble and selectionSort function to sort an array of integers in ascending order.
Write a helper function printArray to display the contents of the array before and after sorting. Test
your implementation with the following array: {54, 35, 12, 34, 22}.
a. Take 5 values from the user and insert them into an array.
b. Display the values in the array. [6 marks]
c. Ask the user to enter a number to search for.
d. Ask the user to choose either Linear Search or Binary Search.
e. If Binary Search is chosen, sort the array automatically before searching.
SHAHEED ZULFIKAR ALI BHUTTO INSTITUTE OF
SCIENCE AND TECHNOLOGY UNIVERSITY
f. Perform the search based on the user's choice and display whether the number was found and at
which index, or display a message if the number is not found.