Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Data StructuresMCQ

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

Data Structures

MCQ

UNIT I
1. Which of these best describes an array?
a) A data structure that shows a hierarchical behaviour
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure
Answer: b
2. How do you initialize an array in C?
a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);
Answer: c
3. Which of the following concepts make extensive use of arrays?
a) Binary trees
b) Scheduling of processes
c) Caching
d) Spatial locality

Answer: d
4. What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type
Answer: d
5.Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Answer: d
6. In general, the index of the first element in an array is __________
a) 0
b) -1
c) 2
d) 1
Answer: a
7. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically
Answer: a
8. Which matrix has most of the elements (not all) as Zero?
a) Identity Matrix
b) Unit Matrix
c) Sparse Matrix
d) Zero Matrix
Answer: c
9. Which of the following is not the method to represent Sparse Matrix?
a) Dictionary of Keys
b) Linked List
c) Array
d) Heap
Answer: d
10. A linear collection of data elements where the linear node is given by means of pointer is
called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer: a
11. What would be the asymptotic time complexity to insert an element at the front of the linked
list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer: a
12. Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
Answer: a
13. What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
d) Head node is known in circular linked list
Answer: c
14. What is the time complexity of searching for an element in a circular linked list?
a) O(n)
b) O(nlogn)
c) O(1)
d) O(n2)
Answer: a
15. Which of the following application makes use of a circular linked list?
a) Undo operation in a text editor
b) Recursive function calls
c) Allocating CPU to resources
d) Implement Hash Tables
Answer: c
16. Which of the following is false about a doubly linked list?
a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list
Answer: d
17. What is a memory efficient double linked list?
a) Each node has only one pointer to traverse the list back and forth
b) The list has breakpoints for faster traversal
c) An auxiliary singly linked list acts as a helper list to traverse through the doubly linked list
d) A doubly linked list that uses bitwise AND operator for storing addresses
Answer: a
18. What is the worst case time complexity of inserting a node in a doubly linked list?
a) O(nlogn)
b) O(logn)
c) O(n)
d) O(1)
Answer: c
19. What kind of linked list is best to answer question like “What is the item at position n?”
a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Array implementation of linked list
Answer: d
20. Linked list is considered as an example of ___________ type of memory allocation.
a) Dynamic
b) Static
c) Compile time
d) Heap
Answer: a

UNIT II
21. The data structure required to evaluate a postfix expression is
a. queue
b. stack
c. array
d. linked-list

Answer Option B

22. The data structure required to check whether an expression contains balanced parenthesis is
a. Stack
b. Queue
c. Tree
d. Array
Answer Option A
23. Which data structure is needed to convert infix notation to postfix notation?
a. Branch

b. Queue

c. Tree

d. Stack
Answer: Option D
24. Which data structure is used for implementing recursion?
a. Queue
b. Stack
c. Arrays
d. List
Answer: Option B
25. The result of evaluating the postfix expression 5,4,6,+,*,4,9,3,/,+,* is
a. 600
b. 350
c. 650
d. 588
e. Answer: Option B
26. Let S be the original stack and S1 and S2 the two additional stacks then the following pseudo
code is to reverse the stack S:
while (S not empty)
{
push(S1,pop(S));
}
while(S1 not empty)
{
push(S2,pop(S1));
}
while(S2 not empty)
{
push(S,pop(S2));
}?
a. TRUE
b. False
c. Not Answer

Answer: Option A
27. The data structure required to check whether an expression contains balanced parenthesis is
a. Stack
b. Queue
c. Tree
d. Array
e. Answer: Option A
28. Let ' s' be a stack and push and pop be functions implementing the Insertion and Deletion
operations in a Stack. push takes 2 parameters: the stack and the element to be inserted , pop
takes a single parameter: the stack. What will be the contents of the stack after the following
operations: push(s,A), push(s,B), push(s,C), pop(s), pop(s), push(s, D), push (s, E), pop(s) ?
a. A D
b. D E
c. C E
d. A E
e. Answer: Option A
29. The term "push" and "pop" is related to the
a. Array
b. Lists
c. stacks
d. all of above
e. Answer: Option C
30. The post fix form of A & B * C-D + E/F/ (G + H) is
a. AB $ C * D - EF/GH +I+
b. AB$* C- D + EF I GH I+
c. AB $ C + D - EF I GH I - +
d. AB $ C - D * EF I GH I ++
i. Answer: Option A

31. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a ?
a) Queue
b) Stack
c) Tree
d) Linked list
Answer: a
32. A queue follows __________
a) FIFO (First In First Out) principle
b) LIFO (Last In First Out) principle
c) Ordered array
d) Linear tree

Answer: a
33. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer: a
34. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a
time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
Answer: a

35. A data structure in which elements can be inserted or deleted at/from both the ends
but not in the middle is?
a) Queue
b) Circular queue
c) Dequeue
d) Priority queue
View Answer
Answer: c
36. A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front
Answer: a
37. Queues serve major role in ______________
a) Simulation of recursion
b) Simulation of arbitrary linked list
c) Simulation of limited resource allocation
d) Simulation of heap sort
Answer: c

38. Which of the following is not the type of queue?


a) Ordinary queue
b) Single ended queue
c) Circular queue
d) Priority queue
Answer: b
39. Insertion and Deletion operation in Queue is known as ?
a. Push and Pop
b. Enqueue and Dequeue
c. Insert and Delete
d. None
Answer: b
40. Which of the following is not an advantage of priority queue?
a) Easy to implement
b) Processes with different priority can be efficiently handled
c) Applications with differing requirements
d) Easy to delete elements in any case

Answer: d

UNIT III
1. What is/are the disadvantages of implementing tree using normal arrays?
a) difficulty in knowing children nodes of a node
b) difficult in finding the parent of a node
c) have to know the maximum number of nodes possible before creation of trees
d) difficult to implement
Answer: c

2. Advantages of linked list representation of binary trees over arrays?


a) dynamic size
b) ease of insertion/deletion
c) ease in randomly accessing a node
d) both dynamic size and ease in insertion/deletion
Answer: d
3. Disadvantages of linked list representation of binary trees over arrays?
a) Randomly accessing is not possible
b) Extra memory for a pointer is needed with every element in the list
c) Difficulty in deletion
d) Random access is not possible and extra memory with every element
Answer: d
4. 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
5. 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

6. What is the time complexity of pre-order traversal in the iterative fashion?


a) O(1)
b) O(n)
c) O(logn)
d) O(nlogn)
Answer: b

7. What is the space complexity of the post-order traversal in the recursive fashion? (d is the tree
depth and n is the number of nodes)
a) O(1)
b) O(nlogd)
c) O(logd)
d) O(d)
Answer: d

8. To obtain a prefix expression, which of the tree traversals is used?


a) Level-order traversal
b) Pre-order traversal
c) Post-order traversal
d) In-order traversal
Answer: b

9. Consider the following data. The pre order traversal of a binary tree is A, B, E, C, D. The in
order traversal of the same binary tree is B, E, A, D, C. The level order sequence for the binary
tree is _________
a) A, C, D, B, E
b) A, B, C, D, E
c) A, B, C, E, D
d) D, B, E, A, C
Answer: b
10. If binary trees are represented in arrays, what formula can be used to locate a left child, if the
node has an index i?
a) 2i+1
b) 2i+2
c) 2i
d) 4i
Answer: a
11. What is the maximum number of children that a binary tree node can have?
a) 0
b) 1
c) 2
d) 3
Answer: c
12.A binary tree is a rooted tree but not an ordered tree.
a) true
b) false
Answer: b
13. How many common operations are performed in a binary tree?
a) 1
b) 2
c) 3
d) 4
Answer: c
14. What is the traversal strategy used in the binary tree?
a) depth-first traversal
b) breadth-first traversal
c) random traversal
d) Priority traversal
Answer: b

15. How many types of insertion are performed in a binary tree?


a) 1
b) 2
c) 3
d) 4
Answer: b
16. How many orders of traversal are applicable to a binary tree (In General)?
a) 1
b) 4
c) 2
d) 3
17. The number of edges from the root to the node is called __________ of the tree.
a) Height
b) Depth
c) Length
d) Width

Answer: b

18. The number of edges from the node to the deepest leaf is called _________ of the tree.
a) Height
b) Depth
c) Length
d) Width

Answer: a

19.What is a full binary tree?


a) Each node has exactly zero or two children
b) Each node has exactly two children
c) All the leaves are at the same level
d) Each node has exactly one or two children

Answer: a

20. What is a complete binary tree?


a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the bottom level,
which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the bottom level,
which is filled from left to right
d) A tree In which all nodes have degree 2

Answer: c
UNIT IV Graphs:
Terminology, Sequential and linked Representations of Graphs: Adjacency Matrices, Adjacency
List, Adjacency Multi list, Graph Traversal : Depth First Search and Breadth First Search,
Connected Component, Spanning Trees, Minimum Cost Spanning Trees: Prims and Kruskal
algorithm. Transistive Closure and Shortest Path algorithm: Warshal Algorithm and Dijikstra
Algorithm, Introduction to Activity Networks

1. Which of the following statements for a simple graph is correct?


a) Every path is a trail
b) Every trail is a path
c) Every trail is a path as well as every path is a trail
d) Path and trail have no relation
Answer: a
Explanation: In a walk if the vertices are distinct it is called a path, whereas if the edges are
distinct it is called a trail.

2) 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
Explanation: After removing vertices B and C, the graph becomes disconnected.

3) 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
Explanation: Number of ways in which every vertex can be connected to each other is nC2.

4)  The given Graph is regular.

a) True
b) False
Answer: a
Explanation: In a regular graph, degrees of all the vertices are equal. In the given graph the
degree of every vertex is 3.

5) 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
Explanation: For any connected graph with no cycles the equation holds true.

6) 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
Explanation: The given statement is the definition of regular graphs.

7) Which of the following ways can be used to represent a graph?


a) Adjacency List and Adjacency Matrix
b) Incidence Matrix
c) Adjacency List, Adjacency Matrix as well as Incidence Matrix
d) No way to represent

Answer: c
Explanation: Adjacency Matrix, Adjacency List and Incidence Matrix are used to represent a
graph.

8) The number of elements in the adjacency matrix of a graph having 7 vertices is


__________
a) 7
b) 14
c) 36
d) 49
Answer: d
Explanation: There are n*n elements in the adjacency matrix of a graph with n vertices.

9) What would be the number of zeros in the adjacency matrix of the given graph?

a) 10
b) 6
c) 16
d) 0
Answer: b
Explanation: Total number of values in the matrix is 4*4=16, out of which 6 entries are non zero.
10) Adjacency matrix of all graphs are symmetric.
a) False
b) True
Answer: a
Explanation: Only undirected graphs produce symmetric adjacency matrices.

11) The time complexity to calculate the number of edges in a graph whose information in
stored in form of an adjacency matrix is ____________
a) O(V)
b) O(E2)
c) O(E)
d) O(V2)
Answer: d
Explanation: As V entries are 0, a total of V2-V entries are to be examined.

12) For the adjacency matrix of a directed graph the row sum is the _________ degree and
the column sum is the ________ degree.
a) in, out
b) out, in
c) in, total
d) total, out
Answer: b
Explanation: Row number of the matrix represents the tail, while Column number represents the
head of the edge.

13) 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)
Answer: c
Explanation: Out of n*n possible values for a simple graph the diagonal values will always be
zero.

14 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
Answer: c
Explanation: To check if there is an edge between to vertices i and j, it is enough to see if the
value of A[i][j] is 1 or 0, here A is the adjacency matrix.

15) This set of Data Structures & Algorithms Multiple Choice Questions & Answers
(MCQs) focuses on “Minimum Spanning Tree”.

1. Which of the following is false in the case of a spanning tree of a graph G?


a) It is tree that spans G
b) It is a subgraph of the G
c) It includes every vertex of the G
d) It can be either cyclic or acyclic
Answer: d
Explanation: A graph can have many spanning trees. Each spanning tree of a graph G is a
subgraph of the graph G, and spanning trees include every vertex of the gram. Spanning trees are
always acyclic.

16) Every graph has only one minimum spanning tree.


a) True
b) False
Answer: b
Explanation: Minimum spanning tree is a spanning tree with the lowest cost among all the
spacing trees. Sum of all of the edges in the spanning tree is the cost of the spanning tree. There
can be many minimum spanning trees for a given graph.

17) Consider a complete graph G with 4 vertices. The graph G has ____ spanning trees.
a) 15
b) 8
c) 16
d) 13
Answer: c
Explanation: A graph can have many spanning trees. And a complete graph with n vertices has
n(n-2) spanning trees. So, the complete graph with 4 vertices has 4(4-2) = 16 spanning trees.
18) Consider the graph shown below. Which of the following are the edges in the MST of
the given graph?

a) (a-c)(c-d)(d-b)(d-b)
b) (c-a)(a-d)(d-b)(d-e)
c) (a-d)(d-c)(d-b)(d-e)
d) (c-a)(a-d)(d-c)(d-b)(d-e)
Answer: c
Explanation: The minimum spanning tree of the given graph is shown below. It has cost 56.

19) Which of the following is not the algorithm to find the minimum spanning tree of the
given graph?
a) Boruvka’s algorithm
b) Prim’s algorithm
c) Kruskal’s algorithm
d) Bellman–Ford algorithm
Answer: d
Explanation: Every spanning tree has n – 1 edges if the graph has n edges and has no cycles. The
MST follows the cut property, Edge e belonging to a cut of the graph if has the weight smaller
than any other edge in the same cut, then the edge e is present in all the MSTs of the graph.

20) What approach is being followed in Floyd Warshall Algorithm?


a) Greedy technique
b) Dynamic Programming
c) Linear Programming
d) Backtracking
Answer: b
Explanation: Floyd Warshall Algorithm follows dynamic programming approach because the all
pair shortest paths are computed in bottom up manner.

21) In the given graph

What is the minimum cost to travel from vertex 1 to vertex 3?


a) 3
b) 2
c) 10
d) -3
Answer: d
Explanation: The minimum cost required to travel from node 1 to node 5 is -3.
1-5, cost is -4
5-4, cost is 6
4-3, cost is -5
Hence total cost is -4 + 6 + -5 = -3.

22) What is the time complexity of Dijikstra’s algorithm?


a) O(N)
b) O(N3)
c) O(N2)
d) O(logN)
Answer: c
Explanation: Time complexity of Dijkstra’s algorithm is O(N2) because of the use of doubly
nested for loops. It depends on how the table is manipulated.
23) 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
Answer: b
Explanation: If the total number of edges in all adjacency list is E, then there will be a total of E
number of iterations, hence there will be a total of at most E decrease key operations

24) The running time of Bellmann Ford algorithm is lower than that of Dijkstra’s
Algorithm.
a) True
b) False
Answer: b
Explanation: The number of iterations involved in Bellmann Ford Algorithm is more than that of
Dijkstra’s Algorithm.

25) Dijkstra’s Algorithm is the prime example for ___________


a) Greedy algorithm
b) Branch and bound
c) Back tracking
d) Dynamic programming
Answer: a
Explanation: Dijkstra’s Algorithm is the prime example for greedy algorithms because greedy
algorithms generally solve a problem in stages by doing what appears to be the best thing at each
stage.
UNIT-V
Sequential search, Binary Search, Comparison and Analysis Internal Sorting: Insertion Sort,
Selection, Bubble Sort, Quick Sort, Two Way Merge Sort, Heap Sort, Radix Sort, Practical
consideration for Internal Sorting. (7) Search Trees: Binary Search Trees(BST), Insertion and
Deletion in BST, Complexity of Search Algorithm, AVL trees, Introduction to m-way Search
Trees, B Trees & B+ Trees, Hashing: Hash Function, Collision Resolution Strategies ,Storage
Management: Garbage Collection and Compaction.

1) What is the best case and worst case complexity of ordered linear search?
a) O(nlogn), O(logn)
b) O(logn), O(nlogn)
c) O(n), O(1)
d) O(1), O(n)
Answer: d
Explanation: Although ordered linear search is better than unordered when the element is not
present in the array, the best and worst cases still remain the same, with the key element being
found at first position or at last position.

2) Given an array arr = {45,77,89,90,94,99,100} and key = 99; what are the mid
values(corresponding array elements) in the first and second levels of recursion?
a) 90 and 99
b) 90 and 94
c) 89 and 99
d) 89 and 94
Answer: a
Explanation: At first level key = 90
At second level key= 99
Here 90 and 99 are mid values.

3)  What is the worst case complexity of binary search using recursion?


a) O(nlogn)
b) O(logn)
c) O(n)
d) O(n2)
Answer: b
Explanation: Using the divide and conquer master theorem.

4)  Given an array arr = {5,6,77,88,99} and key = 88; How many iterations are done until
the element is found?
a) 1
b) 3
c) 4
d) 2
Answer: d
Explanation: Iteration1 : mid = 77; Iteration2 : mid = 88;

5) What is an internal sorting algorithm?


a) Algorithm that uses tape or disk during the sort
b) Algorithm that uses main memory during the sort
c) Algorithm that involves swapping
d) Algorithm that are considered ‘in place’
Answer: b
Explanation: As the name suggests, internal sorting algorithm uses internal main memory.

6) The given array is arr = {1, 2, 4, 3}. Bubble sort is used to sort the array elements. How
many iterations will be done to sort the array?
a) 4
b) 2
c) 1
d) 0
Answer: a
Explanation: Even though the first two elements are already sorted, bubble sort needs 4 iterations
to sort the given array.

7) What is the worst case time complexity of the Quick sort?


a) O(nlogn)
b) O(n)
c) O(n3)
d) O(n2)
Answer: d
Explanation: The worst case running time for Quick sort is O(n2). In Quick sort, the worst case
behaviour occurs when the partitioning routine produces two sub-arrays one with n – 1 element
and other with 0 elements.

8) Which one of the following sorting algorithm is best suited to sort an array of 1 million
elements?
a) Bubble sort
b) Insertion sort
c) Merge sort
d) Quick sort
Answer: d
Explanation: The Quick sort is best suited to sort the array of 1 million elements. The practical
implementations of Quick sort use randomised version. In practice randomised Quick sort
algorithms rarely shows worst case behaviour and is almost always O(nlogn). And Quick sort
requires little additional space and exhibits good cache locality.

9)  Merge sort uses which of the following technique to implement sorting?


a) backtracking
b) greedy algorithm
c) divide and conquer
d) dynamic programming
Answer: c
Explanation: Merge sort uses divide and conquer in order to sort a given array. This is because it
divides the array into two halves and applies merge sort algorithm to each half individually after
which the two sorted halves are merged together.

10) Which of the following is correct with regard to insertion sort?


a) insertion sort is stable and it sorts In-place
b) insertion sort is unstable and it sorts In-place
c) insertion sort is stable and it does not sort In-place
d) insertion sort is unstable and it does not sort In-place
Answer: a
Explanation: During insertion sort, the relative order of elements is not changed. Therefore, it is
a stable sorting algorithm. And insertion sort requires only O(1) of additional memory space.
Therefore, it sorts In-place.

11)  Which of the following is good for sorting arrays having less than 100 elements?
a) Quick Sort
b) Selection Sort
c) Merge Sort
d) Insertion Sort
Answer: d
Explanation: The insertion sort is good for sorting small arrays. It sorts smaller arrays faster than
any other sorting algorithm.
12)In insertion sort, the average number of comparisons required to place the 7th element
into its correct position is ____
a) 9
b) 4
c) 7
d) 14
Answer: b
Explanation: On average (k + 1) / 2 comparisons are required to place the kth element into its
correct position. Therefore, average number of comparisons required for 7th element = (7 + 1)/2
= 4.

13) If several elements are competing for the same bucket in the hash table, what is it
called?
a) Diffusion
b) Replication
c) Collision
d) Duplication
Answer: c
Explanation: In a hash table, if sevaral elements are computing for the same bucket then there
will be a clash among elements. This condition is called Collision. The Collision is reduced by
adding elements to a linked list and head address of linked list is placed in hash table.

14) Which of the following is not a technique to avoid a collision?


a) Make the hash function appear random
b) Use the chaining method
c) Use uniform hashing
d) Increasing hash table size
Answer: d
Explanation: On increasing hash table size, space complexity will increase as we need to
reallocate the memory size of hash table for every collision. It is not the best technique to avoid a
collision. We can avoid collision by making hash function random, chaining method and uniform
hashing.

15)  In simple chaining, what data structure is appropriate?


a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Binary trees
Answer: b
Explanation: Deletion becomes easier with doubly linked list, hence it is appropriate.

16) Advantages of linked list representation of binary trees over arrays?


a) dynamic size
b) ease of insertion/deletion
c) ease in randomly accessing a node
d) both dynamic size and ease in insertion/deletion
View Answer
Answer: d
Explanation: It has both dynamic size and ease in insertion and deletion as advantages.

17) Disadvantages of linked list representation of binary trees over arrays?


a) Randomly accessing is not possible
b) Extra memory for a pointer is needed with every element in the list
c) Difficulty in deletion
d) Random access is not possible and extra memory with every element
Answer: d
Explanation: Random access is not possible with linked lists.

18) 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
Explanation: Generally, all nodes in a tree are visited by using preorder, inorder and postorder
traversing algorithms.

19)Level order traversal of a tree is formed with the help of


a) breadth first search
b) depth first search
c) dijkstra’s algorithm
d) prims algorithm
Answer: a
Explanation: Level order is similar to bfs.
20) 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
Explanation: Threaded binary trees are introduced to make the Inorder traversal faster without
using any stack or recursion. Stack and Queue require more space and pointers in the majority of
binary trees are null and difficulties are raised while finding successor nodes. Size constraints are
not taken on threaded binary trees, but they occupy less space than a stack/queue.

21)  What is the maximum height of an AVL tree with p nodes?


a) p
b) log(p)
c) log(p)/2
d) p⁄2
Answer: b
Explanation: Consider height of tree to be ‘he’, then number of nodes which totals to p can be
written in terms of height as N(he)=N(he-1)+1+N(he-2). since N(he) which is p can be written in
terms of height as the beside recurrence relation which on solving gives N(he)= O(logp) as worst
case height.

22)  B-tree of order n is a order-n multiway tree in which each non-root node contains
_____
a) at most (n – 1)/2 keys
b) exact (n – 1)/2 keys
c) at least 2n keys
d) at least (n – 1)/2 keys
Answer: d
Explanation: A non-root node in a B-tree of order n contains at least (n – 1)/2 keys. And contains
a maximum of (n – 1) keys and n sons.

23)  A B-tree of order 4 and of height 3 will have a maximum of _______ keys.
a) 255
b) 63
c) 127
d) 188
Answer: a
Explanation: A B-tree of order m of height h will have the maximum number of keys when all
nodes are completely filled. So, the B-tree will have n = (mh+1 – 1) keys in this situation. So,
required number of maximum keys = 43+1 – 1 = 256 – 1 = 255.

24) Five node splitting operations occurred when an entry is inserted into a B-tree. Then
how many nodes are written?
a) 14
b) 7
c) 11
d) 5
Answer: c
Explanation: If s splits occur in a B-tree, 2s + 1 nodes are written (2 halves of each split and the
parent of the last node split). So, if 5 splits occurred, then 2 * 5 + 1 , i.e. 11 nodes are written.

25) What is the best case height of a B-tree of order n and which has k keys?
a) logn (k+1) – 1
b) nk
c) logk (n+1) – 1
d) klogn
Answer: a
Explanation: B-tree of order n and with height k has best case height h, where h = logn (k+1) – 1.
The best case occurs when all the nodes are completely filled with keys.

---------------------------------------------------------------------------------------------------------------------

You might also like