Data Structures Algorithms Mock Test


This section presents you various set of Mock Tests related to Data Structures Algorithms. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.

Questions and Answers

Data Structures Algorithms Mock Test I

Q 1 - What is the worst case time complexity of linear search algorithm?

A - Ο(1)

B - Ο(n)

C - Ο(log n)

D - Ο(n2)

Answer : D

Explanation

Linear search scans sequentially to find the target value. The best case is Ο(1) and average and worst case is Ο(n). Worst case is when data is not in the list, and it has to scan all n elements.

Q 2 - What is the worst case run-time complexity of binary search algorithm?

A - Ο(n2)

B - Ο(nlog n)

C - Ο(n3)

D - Ο(n)

Answer : D

Explanation

In the worst case, binary search will be left or right intended, making it compare all the n values.

Q 3 - Which of the following usees FIFO method

A - Queue

B - Stack

C - Hash Table

D - Binary Search Tree

Answer : A

Explanation

Queue maintains two pointers − front and rear. In queue data structure, the item inserted first will always be removed first, hence FIFO!

Answer : B

Explanation

At maximum, a complete graph can have nn - 1 spanning trees.

Q 5 - Which one of the below is not divide and conquer approach?

A - Insertion Sort

B - Merge Sort

C - Shell Sort

D - Heap Sort

Answer : B

Explanation

Among the options, only Merge sort divides the list in sub-list, sorts and then merges them together

Answer : D

Explanation

Polish Notation

Q 7 - In order traversal of binary search tree will produce −

A - unsorted list

B - reverse of input

C - sorted list

D - none of the above

Answer : C

Explanation

Binary search tree yields a sorted list when traversed in-order.

Answer : A

Explanation

In a min heap, parents always have lesser or equal values than that of their childs.

Q 9 - A procedure that calls itself is called

A - illegal call

B - reverse polish

C - recursive

D - none of the above

Answer : C

Explanation

In recursion, a procedure calls itself, either directly or by calling a procedure which in turn calls it.

Q 10 - For a binary search algorithm to work, it is necessary that the array (list) must be

A - sorted

B - unsorted

C - in a heap

D - popped out of stack

Answer : A

Explanation

As binary search divides the list and selects a the sub-list to extend search based on comparison of values, it becomes necessary that the array (list) must be in sorted form.

Q 11 - push() and pop() functions are found in

A - queues

B - lists

C - stacks

D - trees

Answer : C

Explanation

Stack uses push() to insert an item in stack, and pop() to remove the top item from stack.

Q 12 - Queue data structure works on

A - LIFO

B - FIFO

C - FILO

D - none of the above

Answer : B

Explanation

In queue, data item inserted first, will be available first and data item inserted last will be available in the last. FIFO stands for First In First Out and is a correct answer.

Q 13 - Maximum number of nodes in a binary tree with height k, where root is height 0, is

A - 2k − 1

B - 2k+1 − 1

C - 2k-1 + 1

D - 2k − 1

Answer : B

Explanation

If the root node is at height 0, then a binary tree can have at max 2k+1 − 1 nodes.

For example: a binary tree of height 1, can have maximum 21+1 − 1 = 3 nodes.

   r    --------- 0
  / \
 L   R  --------- 1

Q 14 - Which one of the below mentioned is linear data structure −

A - Queue

B - Stack

C - Arrays

D - All of the above

Answer : D

Explanation

All mentioned data structures are linear in nature.

Q 15 - What data structure is used for depth first traversal of a graph?

A - queue

B - stack

C - list

D - none of the above

Answer : B

Explanation

Stack is used for depth first traversal whereas queue is used for breadth first traversal

Q 16 - What data structure is used for breadth first traversal of a graph?

A - queue

B - stack

C - list

D - none of the above

Answer : A

Explanation

Queue is used for breadth first traversal whereas stack is used for depth first traversal.

Q 17 - What data structure can be used to check if a syntax has balanced paranthesis ?

A - queue

B - tree

C - list

D - stack

Answer : D

Explanation

Stack uses LIFO method which is good for checking matching paranthesis.

Q 18 - Postfix expression is just a reverse of prefix expression.

A - True

B - False

Answer : B

Explanation

Expression notations are not reverse (or so) of each other, rather operators used in the expression have different arrangements.

Answer : C

Explanation

Recursive procedures use stacks to execute the result of last executed procedural call.

Q 20 - A circular linked list can be used for

A - Stack

B - Queue

C - Both Stack & Queue

D - Neither Stack or Queue

Answer : C

Explanation

Both stack and queue data structure can be represented by circular linked-list.

Q 21 - A linked-list is a dynamic structure

A - true

B - false

Answer : A

Explanation

A linked-list is dynamic structure, it can shrink and expand as required by the program.

Q 22 - Minimum number of moves required to solve a Tower of Hanoi puzzle is

A - 2n2

B - 2n-1

C - 2n - 1

D - 2n - 1

Answer : C

Explanation

Minimum number of moves required to solve a Tower of Hanoi puzzle is 2n - 1. Where n is the number of disks. If the number of disks is 3, then minimum number of moves required are 23 - 1 = 7

Q 23 - Which of the following is an example of dynamic programming approach?

A - Fibonacci Series

B - Tower of Hanoi

C - Dijkstra Shortest Path

D - All of the above

Answer : D

Explanation

All mentioned use dynamic programming approach. Before solving the in-hand sub-problem, dynamic algorithm will try to examine the results of previously solved sub-problems. The solutions of sub-problems are combined in order to achieve the best solution.

Q 24 - The following formula will produce

Fn = Fn-1 + Fn-2

A - Armstrong Number

B - Fibonacci Series

C - Euler Number

D - Prime Number

Answer : B

Explanation

Fibonacci Series generates subsequent number by adding two previous numbers.

Q 25 - Minimum number of queues required for priority queue implementation?

A - 5

B - 4

C - 3

D - 2

Answer : D

Explanation

Minimum number of queues required for priority queue implementation is two. One for storing actual data and one for storing priorities.

Answer Sheet

Question Number Answer Key
1 D
2 D
3 A
4 B
5 B
6 D
7 C
8 A
9 C
10 A
11 C
12 B
13 B
14 D
15 B
16 A
17 D
18 B
19 C
20 C
21 A
22 C
23 D
24 B
25 D
data_structures_algorithms_questions_answers.htm
Advertisements