Data Structures Algorithms Online Quiz


Following quiz provides Multiple Choice Questions (MCQs) related to Data Structures Algorithms. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.

Questions and Answers

Q 1 - 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 2 - 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 3 - Travelling salesman problem is an example of

A - Dynamic Algorithm

B - Greedy Algorithm

C - Recursive Approach

D - Divide & Conquer

Answer : B

Explanation

Travelling salesman is an example of greedy algorithm. Greedy algorithms tries to find localized optimum solution which may eventually land in globally optimized solutions.

Q 5 - Which method can find if two vertices x & y have path between them?

A - Depth First Search

B - Breadth First Search

C - Both A & B

D - None A or B

Answer : C

Explanation

By using both BFS and DFS, a path between two vertices of a connected graph can be determined.

Q 6 - The number of binary trees with 3 nodes which when traversed in post order gives the sequence A,B,C is ?

A - 3

B - 4

C - 5

D - 6

Answer : C

Explanation

Five binary trees (of 3 nodes) are possible.

Q 7 - Which of the following is not possible with an array in C programming langauge −

A - Declaration

B - Definition

C - Dynamic Allocation

D - Array of strings

Answer : C

Explanation

Array in C are static and cannot be shrinked or expanded in run-time.

Q 8 - Which of the following algorithm cannot be desiged without recursion −

A - Tower of Hanoi

B - Fibonacci Series

C - Tree Traversal

D - None of the above

Answer : D

Explanation

Every problem which can be solved using recursion can also be solved using iterations.

Q 9 - A pivot element to partition unsorted list is used in

A - Merge Sort

B - Quick Sort

C - Insertion Sort

D - Selection Sort

Answer : B

Explanation

The quick sort partitions an array using pivot element and then calls itself recursively twice to sort the resulting two subarray.

Answer : B

Explanation

Project scheduling is an exmaple of dynamic programming.

data_structures_algorithms_questions_answers.htm
Advertisements