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.

Answer : C

Explanation

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

Answer : D

Explanation

Quick sort divides the list using pivot and then sorts in recursive manner. It uses divide and conquer approach.

Q 4 - Which of the following algorithm is not stable?

A - Bubble Sort

B - Quick Sort

C - Merge Sort

D - Insertion Sort

Answer : B

Explanation

Among the given, only quick sort is not stable that is it may re-arrange the already sorted items.

Answer : A

Explanation

In one iteration of Bubble sort, the maximum of the set in hand is moved at the end of the unsorted list. Hence one less comparison.

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 - If queue is implemented using arrays, what would be the worst run time complexity of queue and dequeue operations?

A - Ο(n), Ο(n)

B - Ο(n), Ο(1)

C - Ο(1), Ο(n)

D - Ο(1), Ο(1)

Answer : D

Explanation

As queue is maintained by two separate pointers for queue and dequeue operations, the run time for both is Ο(1).

Answer : D

Explanation

Regardless of being min heap or max heap, root is always replaced by last element of the last level.

Q 9 - Re-balancing of AVL tree costs

A - Ο(1)

B - Ο(log n)

C - Ο(n)

D - Ο(n2)

Answer : B

Explanation

AVL rotations have complexity of Ο(log n)

Answer : C

Explanation

A stable sorting algorithm like bubble sort, does not change the sequence of appearance of similar element in the sorted list.

data_structures_algorithms_questions_answers.htm
Advertisements