Data Structure MCQ
Data Structure MCQ
Explanation: O(1) means computing time 16. The upper bound on the time
is Constant. complexity of the nondeterministic sorting
algorithm is?
12. Which data structure allows deleting A. O(n)
data elements from front and inserting at B. O(n log n)
rear? C. O(1)
A. Stacks D. O( log n)
B. Queues Ans : A
C. Deques
D. Binary search tree Explanation: The upper bound on the time
Ans : B complexity of the nondeterministic sorting
algorithm is O(n)
17. In analysis of algorithm, approximate Ans : D
relationship between the size of the job
and the amount of work required to do is Explanation: An algorithm should have 1
expressed by using _________. or more well-defined outputs, and should
A. Central tendency match the desired output.
B. Differential equation
C. Order of magnitude 22. __________ of an algorithm
D. Order of execution represents the amount of memory space
Ans : D required by the algorithm in its life cycle.
A. Space complexity
Explanation: In analysis of algorithm, B. Time Complexity
approximate relationship between the size C. Quadratic Complexity
of the job and the amount of work required D. Exponential Complexity
to do is expressed by using Order of Ans : A
execution
Explanation: Space complexity of an
18. What is the type of the algorithm used algorithm represents the amount of
in solving the 8 Queens problem? memory space required by the algorithm in
A. Backtracking its life cycle.
B. Dynamic
C. Branch and Bound 23. The space required by an algorithm is
D. Both A and B equal to the sum of the following _______
Ans : A components.
A. 1
Explanation: Backtracking algorithm used B. 2
in solving the 8 Queens problem. C. 3
D. 4
19. Which of the following belongs to the Ans : B
algorithm paradigm?
A. Minimum & Maximum problem Explanation: The space required by an
B. Knapsack problem algorithm is equal to the sum of the
C. Selection problem following two components : A fixed part
D. Merge sort that is a space required to store certain
Ans : B data and variables and A variable part is a
space required by variables.
Explanation: Knapsack problem belongs to
the algorithm paradigm. 24. Which is the formal way to express the
upper bound of an algorithm's running
20. The [] notation is time.
A. Symmetric A. Big Oh Notation
B. Reflexive B. Omega Notation
C. Transitive C. Theta Notation
D. All of the above D. None of the above
Ans : D Ans : A
8. Which of the following concepts make 12. The extra key inserted at the end of
extensive use of arrays? the array is called a,
A. Binary trees A. End key.
B. Scheduling of processes B. Stop key.
C. Caching C. Sentinel.
D. Spatial locality D. Transposition.
Ans : D Ans : C
9.Let A[1...n] be an array of n distinct 14. Each array declaration need not give,
numbers. If i < j and A[i] > A[j], then the implicitly or explicitly, the information about
pair (i, j) is called an inversion of A. What A. the name of array
is the expected number of inversions in B. the data type of array
any permutation on n elements ? C. the first data from the set to be stored
A. θ(n) D. the index set of the array
B. θ(lgn) Ans : C
C. θ(nlgn)
D. θ(n2) 15. The elements of an array are stored
Ans : D successively in memory cells because
A. by this way computer can keep track
Explanation:The expected number of only the address of the first element and
inversions in any permutation on n the addresses of other elements can be
elements is θ(n2). calculated
B. the architecture of computer memory
10. Which of the following operations is does not allow arrays to store other than
not O(1) for an array of sorted data. You serially
may assume that array elements are C. both of above
distinct. D. none of above
A. Find the ith largest element Ans : A
B. Delete an element
Complexity {
1. Which of the following case does not a = a + i + j;
exist in complexity theory? }
A. Best case }
B. Worst case A. O(N)
C. Average case B. O(N*log(N))
D. Null case C. O(N * Sqrt(N))
Ans : D D. O(N*N)
Ans : D
Explanation:Null case does not exist in
complexity Theory. Explanation:= N + (N – 1) + (N – 2) + … 1
+0
2. What is the time, space complexity of = N * (N + 1) / 2
following code: = 1/2 * N^2 + 1/2 * N
int a = 0, b = 0; O(N^2) times.
for (i = 0; i < N; i++)
{ 5. The Worst case occur in linear search
a = a + rand(); algorithm when
} A. Item is somewhere in the middle of the
for (j = 0; j < M; j++) array
{ B. Item is not in the array at all
b = b + rand(); C. Item is the last element in the array
} D. Item is the last element in the array or
A. O(N * M) time, O(1) space is not there at all
B. O(N + M) time, O(N + M) space Ans : D
C. O(N + M) time, O(1) space
D. O(N * M) time, O(N + M) space Explanation:The Worst case occur in
Ans : C linear search algorithm when Item is the
last element in the array or is not there at
Explanation:The first loop is O(N) and the all.
second loop is O(M). Since we don’t know
which is bigger, we say this is O(N + M). 6. What is the time complexity of following
This can also be written as O(max(N, M)). code:
Since there is no additional space being int i, j, k = 0;
utilized, the space complexity is constant / for (i = n / 2; i <= n; i++)
O(1). {
for (j = 2; j <= n; j = j * 2)
3. The complexity of linear search {
algorithm is k = k + n / 2;
A. O(n) }
B. O(log n) }
C. O(n2) A. O(n)
D. O(n log n) B. O(nLogn)
Ans : A C. O(n^2)
D. O(n^2Logn)
Explanation: The worst case complexity of Ans : B
linear search is O(n).
Explanation:Let’s take the examples here.
4.What is the time complexity of following for n = 16, j = 2, 4, 8, 16
code: for n = 32, j = 2, 4, 8, 16, 32
int a = 0; So, j would run for O(log n) steps.
for (i = 0; i < N; i++) i runs for n/2 steps.
{ So, total steps = O(n/ 2 * log (n)) =
for (j = N; j > i; j--) O(n*logn)
C. O(N / 2)
7. The worst case occur in quick sort when D. O(log N)
A. Pivot is the median of the array Ans : D
B. Pivot is the smallest element
C. Pivot is the middle element Explanation:We have to find the smallest x
D. None of the mentioned such that N / 2^x N x = log(N).
Ans : B
11. What is the time complexity of
Explanation:This happens when the pivot following code:
is the smallest (or the largest) element. int a = 0, i = N;
Then one of the partitions is empty, and while (i > 0)
we repeat recursively the procedure for N- {
1 elements. a += i;
i /= 2;
8. What does it mean when we say that an }
algorithm X is asymptotically more efficient A. O(N)
than Y? B. O(Sqrt(N))
A. X will always be a better choice for C. O(N / 2)
small inputs D. O(log N)
B. X will always be a better choice for Ans : D
large inputs
C. Y will always be a better choice for Explanation: We have to find the smallest
small inputs x such that N / 2^x N x = log(N)
D. X will always be a better choice for all
inputs 12. The complexity of Binary search
Ans : B algorithm is
A. O(n)
Explanation: An algorithm X is said to be B. O(log )
asymptotically better than Y if X takes C. O(n2)
smaller time than y for all input sizes n D. O(n log n)
larger than a value n0 where n0 > 0. Ans : B
10. What is the time complexity of Explanation: The worst case complexity
following code: for merge sort is O(nlogn)..
int a = 0, i = N;
while (i > 0) 14. The complexity of Bubble sort
{ algorithm is
a += i; A. O(n)
i /= 2; B. O(log n)
} C. O(n2)
A. O(N) D. O(n log n)
B. O(Sqrt(N)) Ans : C
Explanation: The worst case complexity 19.If for an algorithm time complexity is
for Bubble sort is O(n2)ans best case is given by O(log2n) then complexity will:
O(n)/. A. constant
B. polynomial
15. The worst case complexity for insertion C. exponential
sort is D. none of the mentioned
A. O(n) Ans : D
B. O(log n)
C. O(n2) Explanation: The growth rate of that
D. O(n log n) function will be logarithmic therefore
Ans : C complexity will be logarithmic.
Explanation: In worst case nth comparison 20. If for an algorithm time complexity is
are required to insert the nth element into given by O(n) then complexityof it is:
correct position. A. constant
B. linear
16. The worst case complexity of quick C. exponential
sort is D. none of the mentioned
A. O(n) Ans : B
B. O(log n)
C. O(n2) Explanation: The growth rate of that
D. O(n log n) function will be linear.
Ans : C
21. if for an algorithm time complexity is
Explanation: The worst case complexity of given by O(n2) then complexity will:
quick sort is O(n2). A. constant
B. quardratic
17. To measure Time complexity of an C. exponential
algorithm Big O notation is used which: D. none of the mentioned
A. describes limiting behaviour of the Ans : B
function
B. characterises a function based on Explanation: The growth rate of that
growth of function function will be quadratic therefore
C. upper bound on growth rate of the complexity will be quardratic..
function
D. all of the mentioned 22. If for an algorithm time complexity is
Ans : D given by O((3/2)^n) then complexity will:
A. constant
Explanation: Big O notation describes B. quardratic
limiting behaviour, and also gives upper C. exponential
bound on growth rate of a function. D. none of the mentioned
Ans : C
18. If for an algorithm time complexity is
given by O(1) then complexityof it is: Explanation: The growth rate of that
A. constant function will be exponential therefore
B. polynomial complexity will be exponential.
C. exponential
D. none of the mentioned 23. the time complexity of binary search is
Ans : A given by:
A. constant
Explanation: The growth rate of that B. quardratic
function will be constant. C. exponential
D. none of the mentioned
Ans : D 29. Which algorithm is having highest
space complexity?
Explanation: It is O(log2n), therefore A. Bubble sort
complexity will be logarithmic. B. Insertion Sort
C. Quick Sort
24. The time complexity of linear search is D. Merge Sort
given by: Ans : D
A. O(log2n)
B. O(1) 30. If the array is already sorted, then the
C. exponential running time for merge sort is: ?
D. none of the mentioned A. O(1)
Ans : D B. O(n*log n)
C. O(n)
Explanation: It is O(n), therefore D. O(n^2)
complexity will be linear. Ans : B
⋀ E) is -A/B*C⋀DE.
Explanation: The prefix form of A-B/ (C * D 12.Pushing an element into stack already
having five elements and stack size of 5 ,
then stack becomes
9.Following is an incorrect pseudocode for A. Overflow
the algorithm which is supposed to B. Crash
determine whether a sequence of C.Underflow
parentheses is balanced: Which of these D. User flow
unbalanced sequences does the above Ans : C
code think is balanced?
13. Which of the following applications
declare a character stack may use a stack?
while ( more input is available) A. A parentheses balancing program
{ B. Tracking of local variables at run time
read a character C. Compiler Syntax Analyzer
if ( the character is a '(' ) D. All of the mentioned
push it on the stack Ans : D
else if ( the character is a ')' and the stack
is not empty ) Explanation: All are applications of stack.
pop a character off the stack
else 14.Consider the usual algorithm for
print "unbalanced" and exit determining whether a sequence of
} parentheses is balanced.
print "balanced" The maximum number of parentheses that
appear on the stack AT ANY ONE TIME
A. ((()) when the algorithm analyzes: (()(())(()))
B. ())(() are:
C. (()())) A. 1
D. (()))() B. 2
Ans : A C. 3
D. 4 or more
Explanation: At the end of while loop, we Ans : C
must check whether the stack is empty or
not. For input ((()), the stack doesn't Explanation: Applying the postfix
remain empty after the loop. expression evaluation.
10.What is the value of the postfix 15.Consider the usual algorithm for
expression 6 3 2 4 + – *: determining whether a sequence of
A. Something between -5 and -15 parentheses is balanced.
B. Something between 5 and -5 Suppose that you run the algorithm on a
C. Something between 5 and 15 sequence that contains 2 left parentheses
D. Something between 15 and 100 and 3 right parentheses (in some order).
Ans : D The maximum number of parentheses that
appear on the stack AT ANY ONE TIME
Explanation:On solving the postfix during the computation?
expression the answer comes out to 18. A. 1
B. 2
11. Process of removing an element from C. 3
stack is called __________ D. 4 or more
A. Create Ans : C
B. Push
C. Evaluation Explanation: Applying the postfix
D. Pod expression evaluation.
16. The data structure required to check 21. Which data structure is needed to
whether an expression contains balanced convert infix notation to postfix notation?
parenthesis is? A. Branch
A. Stack B. Tree
B. Queue C. Queue
C. Array D. Stack
D. Tree Ans : D
Ans : A
22. The prefix form of A-B/ (C * D ^ E) is?
17. Here is an infix expression: 4 + 3*(6*3- A. -/*^ACBDE
12). Suppose that we are using the usual B. -ABCD*^DE
stack algorithm to convert the expression C. -A/B*C^DE
from infix to postfix notation. D. -A/BC*^DE
The maximum number of symbols that will Ans : B
appear on the stack AT ONE TIME during
the conversion of this expression? Explanation: Process of inserting an
A. 1 element in stack is called Push.
B. 2
C. 3 23. The postfix form of A*B+C/D is?
D. 4 A. *AB/CD+
Ans : D B. AB*CD/+
C. A*BC+/D
18. What data structure would you mostly D. ABCD+/*
likely see in a non recursive Ans : C
implementation of a recursive algorithm?
A. Linked List Explanation: Applying the prefix
B. Stack expression evaluation..
C. Queue
D. Tree 24.What is the result of the following
Ans : B operation
Top (Push (S, X))
19.The process of accessing data stored A. X
in a serial access memory is similar to B. Null
manipulating data on a C. S
A. Heap D. None of the mentioned
B. Binary Tree Ans : A
C. Array
D. Stack 25.The prefix form of an infix expression p
Ans : D + q – r * t is?
A. + pq – *rt
20.The postfix form of A*B+C/D is? B. – +pqr * t
A. *AB/CD+ C. – +pq * rt
B. AB*CD/+ D. – + * pqrt
C. A*BC+/D Ans : C
D. ABCD+/*
Ans : B Explanation: Applying the prefix
expression evaluation.
Explanation: Applying the postfix
expression evaluation.
QUEUE Explanation: A queue can be implemented
1. Which one of the following is an using two stacks.
application of Queue Data Structure?
A. When a resource is shared among 5.In a Queue, if a user tries to remove an
multiple consumers. element from empty Queue it is called
B. When data is transferred A. Underflow
asynchronously (data not necessarily B. Empty collection
received at same rate as sent) between C. Overflow
two processes D. Garbage Collection
C. Load Balancing Ans : A
D. All of the above
Ans : D Explanation:In a Queue, if a user tries to
remove an element from empty Queue it is
2. In linked list implementation of queue, if called Underflow.
only front pointer is maintained, which of
the following operation take worst case 6. If the elements "A", "B", "C" and "D" are
linear time? placed in a queue and are deleted one at
A. Insertion a time, in what order will they be
B. Deletion removed?
C. To empty a queue A. ABCD
D. Both Insertion and To empty a queue B. DCBA
Ans : D C. DCAB
D. ABCD
Explanation: Since front pointer is used for Ans : A
deletion, so worst time for the other two
cases. Explanation: Because Queue follow FIFO
rule.
3. Let the following circular queue can
accommodate maximum six elements with 7.A priority queue can efficiently
the following data.What will happen after implemented using which of the following
ADD O operation takes place? data structures? Assume that the number
front = 2 rear = 4 of insert and peek (operation to see the
queue = _______; L, M, N, ___, ___ current highest priority item) and extraction
A. front = 2 rear = 5 (remove the highest priority item)
queue = ______; L, M, N, O, ___ operations are almost same
B. front = 3 rear = 5 A. Array
queue = L, M, N, O, ___ B. Linked List
C. front = 3 rear = 4 C. Heap Data Structures like Binary Heap,
queue = ______; L, M, N, O, ___ Fibonacci Heap
D. front = 2 rear = 4 D. None of the above
queue = L, M, N, O, ___ Ans : C
Ans : A
8. In case of insertion into a linked queue,
4.How many stacks are needed to a node borrowed from the __________ list
implement a queue. Consider the situation is inserted in the queue.
where no other data structure like arrays, A. AVAIL
linked list is available to you. B. FRONT
A. 1 C. REAR
B. 2 D. None of the mentioned
C. 3 Ans : A
D. 4
Ans : B Explanation: All the nodes are collected in
AVAIL list.
9.If the MAX_SIZE is the size of the array 14. In Breadth First Search of Graph,
used in the implementation of circular which of the following data structure is
queue. How is rear manipulated while used?
inserting an element in the queue? A. Stack
A. rear=(rear%1)+MAX_SIZE B. Queue
B. rear=rear%(MAX_SIZE+1) C. Linked list
C. rear=(rear+1)%MAX_SIZE D. None of the mentioned
D. rear=rear+(1%MAX_SIZE) Ans : B
Ans : C
15. A data structure in which elements can
10.Suppose a circular queue of capacity (n be inserted or deleted at/from both the
– 1) elements is implemented with an ends but not in the middle is?
array of n elements. Assume that the A. Queue
insertion and deletion operation are B. Circular queue
carried out using REAR and FRONT as C. Dequeue
array index variables, respectively. Initially, D. Priority queue
REAR = FRONT = 0. The conditions to Ans : C
detect queue full and queue empty are
A. Full: (REAR+1) mod n == FRONT, 16. A normal queue, if implemented using
empty: REAR == FRONT an array of size MAX_SIZE, gets full when
B. Full: (REAR+1) mod n == FRONT, A. Rear = MAX_SIZE – 1
empty: (FRONT+1) mod n == REAR B Front = (rear + 1)mod MAX_SIZE
C. Full: REAR == FRONT, empty: C. Front = rear + 1
(REAR+1) mod n == FRONT D> Rear = front
D. Full: (FRONT+1) mod n == REAR, Ans : C
empty: REAR == FRONT
Ans : A Explanation: Condition for size of queue.
11. A linear list of elements in which 17. Queues serve major role in
deletion can be done from one end (front) A. Simulation of recursion
and insertion can take place only at the B. Simulation of arbitrary linked list
other end (rear) is known as a ? C. Simulation of limited resource allocation
A Queue D. All of the mentioned
B Stack Ans : C
C. Tree
D. Linked list Explanation: Rest all are implemented
Ans : A using other data structures.
12. The data structure required for Breadth 18. Which of the following is not the type
First Traversal on a graph is? of queue?
A. Stack A. Ordinary queue
B. Array B. Single ended queue
C. Queue C. Circular queue
D. Tree D. Priority queue
Ans : C Ans : B
A. Dequeue
B. Enqueue
C. Return the front element
D. None of the mentioned
Ans : C
Explanation: A full binary tree (sometimes Explanation: For an k-ary tree where each
proper binary tree or 2-tree or strictly node has k children or no children,
binary tree) is a tree in which every node following relation holds L = (k-1)*n + 1
other than the leaves has two children. A Where L is the number of leaf nodes and n
complete binary tree is a binary tree in is the number of internal nodes.
which every level, except possibly the last,
is completely filled, and all nodes are as 7.Height of Height of a binary tree is
far left as possible. A) is incorrect. A. MAX( Height of left Subtree, Height of
right subtree)+1
3. A Binary Tree can have B. MAX( Height of left Subtree, Height of
A. Can have 2 children right subtree)
B. Can have 1 children C. MAX( Height of left Subtree, Height of
C. Can have 0 children right subtree)-1
D. All of the above D. None of the above
Ans : D Ans : A
18.What is the best case complexity of 22. The given array is arr = {1,2,4,3}.
selection sort? Bubble sort is used to sort the array
A. O(nlogn) elements. How many iterations will be
B. O(logn) done to sort the array?
C. O(n) A. 4
D. O(n2) B. 2
Ans : D C. 1
D. 0
Explanation: The best, average and worst Ans : A
case complexities of selection sort is
O(n2). Explanation: Even though the first two
(n-1) + (n-2) + (n-3) + …. + 1 = (n(n-1))/2 ~ elements are already sorted, bubble sort
(n2)/2. needs 4 iterations to sort the given array.
19. What is an internal sorting algorithm? 23.What is the best case efficiency of
A. Algorithm that uses tape or disk during bubble sort in the improvised version?
the sort A. O(nlogn)
B. Algorithm that uses main memory B. O(logn)
during the sort C. O(n)
C. Algorithm that involves swapping D. O(n2)
D. Algorithm that are considered ‘in place’ Ans : B
Ans : B
Explanation: Only 2 elements in the given
array are not sorted, hence only 2
iterations are required to sort them.
24. QuickSort can be categorized into
which of the following?
A. Brute Force technique
B. Divide and conquer
C. Greedy algorithm
D. Dynamic programming
Ans : B