Quiz2 Sec C Solution
Quiz2 Sec C Solution
Quiz 2: Solution
CE-205T: Data Structures & Algorithm
a) Compare bubble sort, insertion sort and selection sort in terms of time complexity &
no of passes.
Algorithm Time Complexity No of Passes
Bubble Sort O(n2) N-1
Selection Sort O(n2) N-1
Insertion Sort O(n2) N
(CLO_2): (Cognitive Level C4, i.e., Analyzing) (PLO_2, i.e., Problem Analysis) [01 Marks]
QUESTION# 2:
Consider the alphabetical list of patients in a ward. Suppose a patient Hameed is admitted to the
ward. Outline the algorithm and mention the time complexity if Hameed is put in bed 10, the
first available bed in the ward.
Solution:
Solution:
1. H(6) = 6 mod 7 = 6
2. H(13) = 13 mod 7 = 6 Collision
a. 6 + 1 = 7 0
3. H(14) = 14 mod 7 = 0 Collision
a. 0 + 1 = 1
0 13
4. H(21) = 21 mod 7 = 0 Collision
1 14
a. 0 + 1 = 1 Collision 2 28
b. 0 + 4 = 4 3
5. H(28) = 28 mod 7 = 0 Collision 4 21
a. 0 + 1 = 1 Collision 5
b. 0 + 4 = 4 Collision 6 6
c. 0 + 9 = 2