Unit Iv Non-Linear Data Structures Syllabus
Unit Iv Non-Linear Data Structures Syllabus
SYLLABUS:
Trees – Binary Trees – Binary tree representation and traversals –Binary Search Trees – Applications of trees.
Set representations – Union-Find operations. Graph and its representations – Graph Traversals.
OBJECTIVE TYPE QUESTIONS
3. What must be the ideal size of array if the height of tree is ‘l’?
a) 2l-1
b) l-1
c) l
d) 2l
Answer: a
4. What are the children for node ‘w’ of a complete-binary tree in an array representation?
a) 2w and 2w+1
b) 2+w and 2-w
c) w+1/2 and w/2
d) w-1/2 and w+1/2
Answer: a
5. What is the parent for a node ‘w’ of a complete binary tree in an array representation when w is not 0?
a) floor(w-1/2)
b) ceil(w-1/2)
c) w-1/2
d) w/2
Answer: a
6. If the tree is not a complete binary tree then what changes can be made for easy access of children of a node
in the array?
a) every node stores data saying which of its children exist in the array
b) no need of any changes continue with 2w and 2w+1, if node is at i
c) keep a seperate table telling children of a node
d) use another array parallel to the array with tree
Answer: a
8. Consider a situation of writing a binary tree into a file with memory storage efficiency in mind, is array
representation of tree is good?
a) yes because we are overcoming the need of pointers and so space efficiency
b) yes because array values are indexable
c) No it is not efficient in case of sparse trees and remaning cases it is fine
d) No linked list representation of tree is only fine
Answer: c
13. Which of the following traversing algorithm is not used to traverse in a tree?
a) Post order
b) Pre order
c) Post order
d) Randomized
Answer: d
15. Identify the reason which doesn’t play a key role to use threaded binary trees?
a) The storage required by stack and queue is more
b) The pointers in most of nodes of a binary tree are NULL
c) It is Difficult to find a successor node
d) They occupy less size
Answer: d
16. The following lines talks about deleting a node in a binary tree.(the tree property must not be violated after
deletion)
i) from root search for the node to be deleted
ii)
iii) delete the node at
what must be statement ii) and fill up statement iii)
a) ii)-find random node,replace with node to be deleted. iii)- delete the node
b) ii)-find node to be deleted. iii)- delete the node at found location
c) ii)-find deepest node,replace with node to be deleted. iii)- delete a node
d) ii)-find deepest node,replace with node to be deleted. iii)- delete the deepest node
Answer: d
17. What may be the psuedo code for finding the size of a tree?
a) find_size(root_node–>left_node) + 1 + find_size(root_node–>right_node)
b) find_size(root_node–>left_node) + find_size(root_node–>right_node)
c) find_size(root_node–>right_node) – 1
d) find_size(root_node–>left_node + 1
Answer: a
18. What is missing in this logic of finding a path in the tree for a given sum (i.e checking whether there will be
a path from roots to leaf nodes with given sum)?
checkSum(struct bin-treenode*root , int sum):
if(root==null)
return sum as 0
else:
leftover_sum=sum-root_node-->value
//missing
a) code for having recursive calls to either only left tree or right trees or to both subtrees depending on their
existence
b) code for having recursive calls to either only left tree or right trees
c) code for having recursive calls to either only left tree
d) code for having recursive calls to either only right trees
Answer: a
19. What must be the missing logic below so as to print mirror of a tree as below as an example?
if(rootnode):
mirror(rootnode-->left)
mirror(rootnode-->right)
//missing
end
a) swapping of left and right nodes is missing
b) swapping of left with root nodes is missing
c) swapping of right with root nodes is missing
d) nothing is missing
Answer: a
25. What is the average case time complexity for finding the height of the binary tree?
a) h = O(loglogn)
b) h = O(nlogn)
c) h = O(n)
d) h = O(log n)
Answer: d
27. In a full binary tree if number of internal nodes is I, then number of leaves L are?
a) L = 2*I
b) L = I + 1
c) L = I – 1
d) L = 2*I – 1
Answer: b
28. In a full binary tree if number of internal nodes is I, then number of nodes N are?
a) N = 2*I
b) N = I + 1
c) N = I – 1
d) N = 2*I + 1
Answer: d
29. In a full binary tree if there are L leaves, then total number of nodes N are?
a) N = 2*L
b) N = L + 1
c) N = L – 1
d) N = 2*L – 1
Answer: d
31. Construct a binary tree by using postorder and inorder sequences given below.
Inorder: N, M, P, O, Q
Postorder: N, P, Q, O, M
a)
b)
c)
d)
Answer: d
12. Construct a binary search tree by using postorder sequence given below.
Postorder: 2, 4, 3, 7, 9, 8, 5.
a)
b)
c)
d)
Answer: b
32. Construct a binary tree using inorder and level order traversal given below.
Inorder Traversal: 3, 4, 2, 1, 5, 8, 9
Level Order Traversal: 1, 4, 5, 9, 8, 2, 3
a)
b)
c)
d)
Answer: a
33. The height of a BST is given as h. Consider the height of the tree as the no. of edges in the longest path from
root to the leaf. The maximum no. of nodes possible in the tree is?
a) 2h-1 -1
b) 2h+1 -1
c) 2h +1
d) 2h-1 +1
ANSWER: B
34. The no of external nodes in a full binary tree with n internal nodes is?
a) n
b) n+1
c) 2n
d) 2n + 1
ANSWER: B
35. The difference between the external path length and the internal path length of a binary tree with n internal
nodes is?
a) 1
b) n
c) n + 1
d) 2n
ANSWER: D
36. Suppose a binary tree is constructed with n nodes, such that each node has exactly either zero or two
children. The maximum height of the tree will be?
a) (n+1)/2
b) (n-1)/2
c) n/2 -1
d) (n+1)/2 -1
ANSWER: B
38. Suppose we have numbers between 1 and 1000 in a binary search tree and want to search for the number
363. Which of the following sequence could not be the sequence of the node examined?
a) 2, 252, 401, 398, 330, 344, 397, 363
b) 924, 220, 911, 244, 898, 258, 362, 363
c) 925, 202, 911, 240, 912, 245, 258, 363
d) 2, 399, 387, 219, 266, 382, 381, 278, 363
ANSWER : C
39. In full binary search tree every internal node has exactly two children. If there are 100 leaf nodes in the tree,
how many internal nodes are there in the tree?
a) 25
b) 49
c) 99
d) 101
ANSWER: C
39. Which type of traversal of binary search tree outputs the value in sorted order?
a) Pre-order
b) In-order
c) Post-order
d) None
ANSWER: B
40. Suppose a complete binary tree has height h>0. The minimum no of leaf nodes possible in term of h is?
a) 2h -1
b) 2h -1 + 1
c) 2h -1
d) 2h +1
ANSWER: C
41. A 2-3 is a tree such that
a) All internal nodes have either 2 or 3 children
b) All path from root to leaves have the same length
42. The number of internal nodes of a 2-3 tree having 9 leaves could be
a) 4
b) 5
c) 6
d) 7
ANSWER: A, D
43. If a node having two children is to be deleted from binary search tree, it is replaced by its
a) In-order predecessor
b) In-order successor
c) Pre-order predecessor
d) None
ANSWER: B
44. A binary search tree is formed from the sequence 6, 9, 1, 2, 7, 14, 12, 3, 8, 18. The minimum number of
nodes required to be added in to this tree to form an extended binary tree is?
a) 3
b) 6
c) 8
d) 11
ANSWER: D
45. In a full binary tree, every internal node has exactly two children. A full binary tree with 2n+1 nodes
contains
a) n leaf node
b) n internal nodes
c) n-1 leaf nodes
d) n-1 internal nodes
ANSWER: B
46. the run time for traversing all the nodes of a binary search tree with n nodes and printing them in an order is
a) O(nlg(n))
b) O(n)
c) O(√n)
d) O(log(n))
ANSWER: B
47. When a binary tree is converted in to an extended binary tree, all the nodes of a binary tree in the external
node becomes
a) Internal nodes
b) External nodes
c) Root nodes
d) None
ANSWER: A
48. If n numbers are to be sorted in ascending order in O(nlogn) time, which of the following tree can be used
a) Binary tree
b) Binary search tree
c) Max-heap
d) Min-heap
ANSWER: D
49. If n elements are sorted in a binary search tree. What would be the asymptotic complexity to search a key in
the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: C
50. If n elements are sorted in a balanced binary search tree. What would be the asymptotic complexity to
search a key in the tree?
a) O(1)
b) O(logn)
c) O(n)
d) O(nlogn)
ANSWER: B
53. In which of the following tree, parent node has a key value greater than or equal to the key value of both of
its children?
a) Binary search tree
b) Threaded binary tree
c) Complete binary tree
d) Max-heap
ANSWER: D
54. A binary tree T has n leaf nodes. The number of nodes of degree 2 in T is
a) log2n
b) n-1
c) n
d) 2n
ANSWER: B
55. A binary search tree is generated by inserting in order the following integers:
50, 15, 62, 5, 20, 58, 91, 3, 8, 37, 60, 24
The number of the node in the left sub-tree and right sub-tree of the root, respectively, is
a) (4, 7)
b) (7, 4)
c) (8, 3)
d) (3, 8)
ANSWER: B
58. For the given graph(G), which of the following statements is true?
a) G is a complete graph
b) G is not a connected graph
c) The vertex connectivity of the graph is 2
d) The edge connectivity of the graph is 1
Answer: c
59. What is the number of edges present in a complete graph having n vertices?
a) (n*(n+1))/2
b) (n*(n-1))/2
c) n
d) Information given is insufficient
Answer: b
60. The given Graph is regular.
a) True
b) False
Answer: a
61. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.
a) True
b) False
Answer: b
62. A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
a) 15
b) 3
c) 1
d) 11
Answer: b
63. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph G'(Complement of
G) is ___________
a) (n*n-n-2*m)/2
b) (n*n+n+2*m)/2
c) (n*n-n-2*m)/2
d) (n*n-n+2*m)/2
Answer: a
64. Which of the following properties does a simple graph not hold?
a) Must be connected
b) Must be unweighted
c) Must have no loops or multiple edges
d) Must have no multiple edges
Answer: a
65. What is the maximum number of edges in a bipartite graph having 10 vertices?
a) 24
b) 21
c) 25
d) 16
Answer: c
67. For a given graph G having v vertices and e edges which is connected and has no cycles, which of the
following statements is true?
a) v=e
b) v = e+1
c) v + 1 = e
d) v = e-1
Answer: b
68. For which of the following combinations of the degrees of vertices would the connected graph be eulerian?
a) 1,2,3
b) 2,3,4
c) 2,4,5
d) 1,3,5
Answer: a
69. A graph with all vertices having equal degree is known as a __________
a) Multi Graph
b) Regular Graph
c) Simple Graph
d) Complete Graph
Answer: b
74. Depth First Search is equivalent to which of the traversal in the BinaryTrees?
a)Pre-orderTraversal
b)Post-orderTraversal
c)Level-orderTraversal
d)In-order Traversal Answer:
answer: a
76. The Data structure used in standard implementation of Breadth First Searchis?
a)Stack
b)Queue
c)LinkedList
d)Tree
Answer:a
78. A person wants to visit some places. He starts from a vertex and then wants to visit every vertex till it
finishes from one vertex, backtracks and then explore other vertex from same vertex. What algorithm he
shoulduse?
a) Depth FirstSearch
b) Breadth FirstSearch
c) Trim’salgorithm
d) Kruskal’sAlgorithm
Answer: a
79. Which of the following is not an application of Depth FirstSearch?
a)For generating topological sort of agraph
b)For generating Strongly Connected Components of a directedgraph
c)Detecting cycles in thegraph
d)Peer to Peer Networks
Answer:d
83. Breadth First Search is equivalent to which of the traversal in the BinaryTrees?
a)Pre-orderTraversal
b)Post-orderTraversal
c)Level-orderTraversal
d)In-order Traversal
Answer:c
86. Regarding implementation of Breadth First Search using queues, what is the maximumdistance between
two nodes present in the queue? (considering each edge length1)
a)Can beanything
b)0
c)At most1
d)Insufficient Information
Answer:c
89. In linked representation of Binary trees LEFT[k] contains the ........of at the node N, where k is thelocation.
a.Data
b.Location and left child
c. Right child address
d. Null value
Answer:a
90. Three standards ways of traversing a binary tree T with root R.......
a.Prefix, infix,postfix
b Pre-process, in-process, post-process
c.Pre, in-traversal,post-traversal
d.Pre-order, in-order,post-order
Answer:d
93. Which of the following is the most widely used external memory data structure?
a)AVLtree
b)B-tree
c)Red-blacktree
d)Both AVL tree and Red-blacktree
Answer:b
106. What is the maximum number of possible non zero values in an adjacency matrix of a simple graph with n
vertices?
A. (n*(n-1))/2
B. (n*(n+1))/2
C. n*(n-1)
D. n*(n+1)
Ans : C
107. Which of the following is an advantage of adjacency list representation over adjacency matrix
representation of a graph?
A. In adjacency list representation, space is saved for sparse graphs.
B. DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take O(V^2)
time in adjacency matrix representation. Here is V and E are number of vertices and edges respectively.
C. Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
D. All of the above
Ans : D
108.A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
A. 15
B. 3
C. 1
D. 11
Ans : B
109.On which of the following statements does the time complexity of checking if an edge exists between two
particular vertices is not, depends?
A. Depends on the number of edges
B. Depends on the number of vertices
C. Is independent of both the number of edges and vertices
D. It depends on both the number of edges and vertices
Ans : C
110. The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in
decreasing order. Which of the following sequences can not be the degree sequence of any graph?
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III.7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1
A. I and II
B. III and IV
C. IV only
D. II and IV
Ans : D
111. What is the maximum number of edges in a bipartite graph having 10 vertices?
A. 24
B. 21
C. 25
D. 16
Ans : C
112. Possible number of labelled simple Directed, Pseudo and Multigarphs exist having 2 vertices?
A. 3, Infinite, 4
B. 4, 3, Infinite
C. 4, Infinite, infinite
D. 4, Infinite, Infinite
Ans : D
113.The most efficient algorithm for finding the number of connected components in an undirected graph on n
vertices and m edges has time complexity.
(A) \theta(n)
(B) \theta(m)
(C) \theta(m + n)
(D) \theta(mn)
A. A
B. B
C. C
D. D
Ans : C
114. What is time complexity to check if a string(length S1) is a substring of another string(length S2) stored in
a Directed Acyclic Word Graph, given S2 is greater than S1?
A. O(S1)
B. O(S2)
C. O(S1+S2)
D. O(1)
Ans : A
115. The no of external nodes in a full binary tree with n internal nodes is?
A. n
B. n+1
C. 2n
D. 2n + 1
Ans : B
119.The difference between the external path length and the internal path length of a binary tree with n internal
nodes is?
A. 1
B. n
C. n + 1
D. 2n
Ans : D
120.Finding an element, whether that is present in a list or not. It is called
a)Sorting
b)Searching
c)Storing
d)none
Answer: b