Data Structures Algorithms Online Quiz


Advertisements


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 - 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 2 - 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 3 - 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 4 - Visiting root node after visiting left and right sub-trees is called

A - In-order Traversal

B - Pre-order Traversal

C - Post-order Traveral

Answer : C

Explanation

In Post-order traversal method, the root node is visited last, hence the name.

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 - How many swaps are required to sort the given array using bubble sort - { 2, 5, 1, 3, 4}

A - 4

B - 5

C - 6

D - 7

Answer : A

Explanation

There will be 3 swaps in first iteration and 1 swap in second iteration.

Answer : C

Explanation

Remembering the results of previously calculated solutions is called memoization.

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 - If we choose Prim's Algorithm for uniquely weighted spanning tree instead of Kruskal's Algorithm, then

A - we'll get a different spanning tree.

B - we'll get the same spanning tree.

C - spanning will have less edges.

D - spanning will not cover all vertices.

Answer : B

Explanation

Regardless of which algorithm is used, in a graph with unique weight, resulting spanning tree will be same.

Answer : B

Explanation

A sorting algorithm is said to be adaptive, if it takes advantage of already 'sorted' elements in the list that is to be sorted.


data_structures_algorithms_questions_answers.htm

Advertisements