Algo Final
Algo Final
Course Instructors
Rizwan ul Haq and Asma Sattar
(1) Understanding the question paper is also part of the exam. No clarification will be offered by the
instructors.
(2) Use permanent ink pens only.
(3) Exchange of stationary and possession of mobile phone is strictly disallowed.
(4) Write your name, section and complete roll number XXF-XXXX on each page.
(5) The paper consist of ONE/TWO (Objective & Subjective) parts. Objective part to be attempted in 25
minutes and subjective part to be attempted in 155 minutes. Subjective part is required to be
distributed after collecting objective part.
(6) Don't write stories focus on your task
Question 1 2 3 4 5 6 7 8 Total
Points 18 10 15 10 10 15 12 5 95
Score
Good Luck ☺
4. What is the time complexity to extract a vertex from the priority queue in Prim’s algorithm?
A. log (V)
B. V.V
C. E.E
D. log (E)
5. What is generally true of Adjacency List and Adjacency Matrix representations of graphs?
A. Lists require less space than matrices but take longer to find the weight of an edge (v1,v2)
B. Lists require less space than matrices and they are faster to find the weight of an edge (v1, v2)
C. Lists require more space than matrices and they take longer to find the weight of an edge (v1, v2)
D. Lists require more space than matrices but are faster to find the weight of an edge (v1, v2)
6. Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on
Depth First Search of G? Assume that the graph is represented using adjacency matrix.
A. O(n)
B. O(m+n)
C. O(n2)
D. O(mn)
7. Consider the directed graph given below. Which one of the following is TRUE?
12. Which of the following formula is/are used to find the total number of edges e in directed and undirected
graph having n nodes.
n n−1
A. e=( ∑ d )/2 B. e=( ∑ d ) /2
i i
i=0 i=0
n n−1
C. e=( ∑ d i )/2 D. e=( ∑ d i ) /2
i=1 i=1
E. both A and C F. both B and D
13. Consider a B+-tree in which the maximum number of keys in a node is 5. What is the minimum number of
keys in any non-root node? (GATE CS 2010)
A. 1
B. 2
C. 3
D. 4
14. With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the
root node) that must be fetched in order to satisfy the following query: “Get all records with a search key
greater than or equal to 7 and less than 15” is ________
A. 4
B. 5
C. 6
D. 7
15. Heap sort is stable
A. True
B. False
16. In a weighted graph, assume that the shortest path from a source ‘s’ to a destination ‘t’ is correctly
calculated using a shortest path algorithm. Is the following statement true? If we increase weight of every
edge by 1, the shortest path always remains same.
A. Yes
B. No
17. Is the following statement valid about shortest paths?
Given a graph, suppose we have calculated shortest path from a source to all other vertices. If we modify
the graph such that weights of all edges is becomes double of the original weight, then the shortest path
remains same only the total weight of path changes.
A. True
B. False
18. Closest to the maximum number of keys that can be store in a B-tree of height 2 and minimum degree t =
500.
A. 1,000, 000
B. 1, 000, 000, 000
C. 1, 000, 000, 000, 000
Question 2 [8+2=10 points]
A company ABC corporation is about to execute a project underneath given is the timeline of tasks is the form of a
graph. ABC's director is interested in finding out how much time is at-least required to complete the project if none of
the task get delayed.
a) Dijkstra's algorithm does not work for a graph that contains negative weighted edges. Prove by providing an
example
b) Write a code/ pseudo code segment that tells if a given code can be worked with Dijkstra's algorithm's algorithm.
c) Analyse pseudo code/code of part(b) and give its asymptotic upper bound.
d) In Dijkstra's algorithm we use a priority queue that is implemented by min-priority queue that is implemented by
min-priority heap and the running complexity is O(V logV). What if we do not use priority-queue and sort the
array of vertices each time using merge sort (Analysis of merge sort is O(n log n)). What will be complexity now?
Question 4 [5+5= 10 points]
a) Determine which pairs of graphs below are isomorphic. Justify your answer
1)
2)
b) Given two strings T and P. You are required to find out P in T using KMP algorithm. Give all the possible
points the sequence matches and how many shifts are done.
T= abcabacddabcabdabd
P=abcab
Question 5 [8+2=10 points]
In broadcasting a packet we are concerned that the packet reach all the destinations in least amount of time.
Underneath is given a part of network that shows different routers that will receive the packet sent from the
source 'S'.
a) Using some algorithm find out the least time required for a
packet to reach each node i-e each node's least time.
b) Give reason for preferring the chosen algorithm upon
other.
c) Consider the 4 way B tree in which each data item is a letter. The usual alphabetical ordering of letters is used in
constructing the tree.
What is the result of inserting G in the above tree ?
d) Write a pseudo code that will return position of smallest element in skip list.
a) Suppose we partition this array using quick sort's partition function and using 5 for the pivot. Draw the resulting array
after the partition finishes. Show intermediate steps to reach the final resultant array.
Here is an array of ten integers: 5 3 8 9 1 7 0 2 6 4.
1. T (n) = 3T (n/2)+ n2
2. T (n) = 4T (n/2)+ n
3. T (n) = 2T (n/4)+ n0.51
4. T (n) = 16T (n/4)+ n
c) Given an array e.g. 17, 23, 10, 1, 7, 16, 9, 20, sort it in ascending order using heap sort. Write down explicitly each
step.
Question 8 [5 points]
Write a code/ pseudo code of counting sort algorithm that sort the array in descending order.