Algorithms - Exam 2021-2022 Model Answer
Algorithms - Exam 2021-2022 Model Answer
33. If G is an directed graph with 20 vertices, how many boolean values will be needed to represent
G using an adjacency matrix?
A-20 B-40 C- 200 D-400
34. What is the special property of red-black trees and what root should always be?
a) a color which is either red or black and root should always be black color only
b) height of the tree c) pointer to next node d) a color which is either green or black
2
35. Why do we impose restrictions like . root property is black . every leaf is black . children of
red node are black . all leaves have same black
a) to get logarithm time complexity b) to get linear time complexity
c) to get exponential time complexity d) to get constant time complexity
36. What are the operations that could be performed in O(logn) time complexity by red-black
tree?
a) insertion, deletion, finding predecessor, successor
b) only insertion c) only finding predecessor, successor d) for sorting
37. Why Red-black trees are preferred over hash tables though hash tables have constant time
complexity?
a) no they are not preferred
b) because of resizing issues of hash table and better ordering in redblack trees
c) because they can be implemented using trees d) because they are balanced
38. What is the below pseudo code trying to do, where pt is a node pointer and root pointer?
redblack(Node root, Node pt) :
if (root == NULL) return pt
if (pt.data < root.data)
{
root.left = redblack(root.left, pt);
root.left.parent = root
}
else if (pt.data > root.data)
{
root.right = redblackt(root.right, pt)
root.right.parent = root
} return root
A) insert a new node B ) delete a node C) search a node D) count the number of nodes
39. Dijkstra’s Algorithm is used to solve _____________ problems.
a) All pair shortest path b) Single source shortest path c) Network flow d) Sorting
40. What is the time complexity of Dijikstra’s algorithm?
a) O(N) b) O(N3) c) O(N2) d) O(logN)
41. Dijkstra’s Algorithm cannot be applied on ______________
a) Directed and weighted graphs b) Graphs having negative weight function
c) Unweighted graphs d) Undirected and unweighted graphs
42. How many times the insert and extract min operations are invoked per vertex?
a) 1 b) 2 c) 3 d) 0
43. The maximum number of times the decrease key operation performed in Dijkstra’s
algorithm will be equal to ___________
a) Total number of vertices b) Total number of edges c) Number of vertices – 1
d) Number of edges – 1
44. What is running time of Dijkstra’s algorithm using Binary min- heap method?
a) O(V) b) O(VlogV) c) O(E) d) O(ElogV)
3
45. Consider the following graph
49. If number of cities = 6 then TSP search space will be a) 120 b)720 c) 120 d) 24
50. In the following graph there exist a clique of size = 5 a) true b) false
Good Luck
Dr Basheer Youssef.