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

Quiz2 Sec C Solution

This document contains the solutions to a quiz on data structures and algorithms. It includes 3 questions: 1) Comparing bubble, insertion, and selection sorts in terms of time complexity and number of passes. 2) Describing the algorithm to insert a patient "Hameed" into the first available bed in a hospital ward, which has a time complexity of O(1). 3) Showing the final hash table after a sequence of number insertions using quadratic probing for collision resolution.

Uploaded by

Huzaifa Muhammad
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)
70 views2 pages

Quiz2 Sec C Solution

This document contains the solutions to a quiz on data structures and algorithms. It includes 3 questions: 1) Comparing bubble, insertion, and selection sorts in terms of time complexity and number of passes. 2) Describing the algorithm to insert a patient "Hameed" into the first available bed in a hospital ward, which has a time complexity of O(1). 3) Showing the final hash table after a sequence of number insertions using quadratic probing for collision resolution.

Uploaded by

Huzaifa Muhammad
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

Reg.

# _______________Section ________ Name _________________________

Department: Computer Engineering Program: B.S (CE)

Quiz 2: Solution
CE-205T: Data Structures & Algorithm

Date : 1/12/2022 Allowed Time: 25 minutes Total Marks = 03


Marks Obtained =
Teacher Name: Aneeta Siddiqui
(CLO_1): (Cognitive Level C2, i.e., Understanding) (PLO_1, i.e., Engineering Knowledge)
[01 Marks]

QUESTION# 1: Discuss the following:

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

b) Conditions for overflow and underflow in arrays and linked list.


Overflow: If the linked list is already full and we try to insert any element
Underflow: If the linked list is empty and we try to delete any element

(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:

Algorithm: InsertFirst(START, ITEM)


1. Set New:= CreateNode()
2. Set INFO(New):=ITEM and LINK(New):=NULL
3. Set LINK(NEW):=START
4. Set START:=New
5. Exit
(CLO_3): (Cognitive Level C3, i.e., Applying) (PLO_3, i.e., Design of Solution) [01 Marks]
1
QUESTION# 2: The size of the hash table is 7. Quadratic probing is used to resolve collisions.
The hash function used is H(k) = k mod 7. Show the hash table after the following sequence of
insertions?

6, 13, 14, 21, 28

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

You might also like