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 III

Q 1 - What will be the running-time of Dijkstra's single source shortest path algorithm, if the graph G(V,E) is stored in form of adjacency list and binary heap is used −

A - Ο(|V|2)

B - Ο(|V| log |V|)

C - Ο(|E|+|V| log |V|)

D - None of these

Answer : C


The runing time will be Ο(|E|+|V| log |V|) when we use adjacency list and binary heap.

Q 2 - 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


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

Q 3 - Match the following −

(1) Bubble Sort(A) Ο(n)
(2) Shell Sort(B) Ο(n2)
(3) Selection Sort(C) Ο(n log n)

A - 1 → A,  2 → B,  3 → C

B - 1 → B,  2 → C,  3 → A

C - 1 → A,  2 → C,  3 → B

D - 1 → B,  2 → A,  3 → C

Answer : B


Answer : D


Binary heap heapify operation has time-complexity of Ο(n), while other operations have time-complexity of Ο(1) only.

Q 5 - In binary heap, whenever the root is removed then the rightmost element of last level is replaced by the root. Why?

A - It is the easiest possible way.

B - To make sure that it is still complete binary tree.

C - Because left and right subtree might be missing.

D - None of the above!

Answer : B


A binary heap (whether max or min) has to satisfy the property of complete binary tree at all times.

Q 6 - Time required to merge two sorted lists of size m and n, is

A - Ο(m | n)

B - Ο(m + n)

C - Ο(m log n)

D - Ο(n log m)

Answer : B


The time required to merge two sorted list is Ο(m + n).

Q 7 - 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


Five binary trees (of 3 nodes) are possible.

Q 8 - Quick sort running time depends on the selection of

A - size of array

B - pivot element

C - sequence of values

D - none of the above!

Answer : B


If the pivot element is balanced, quick sort running time will be less.

Q 9 - Which of the below given sorting techniques has highest best-case runtime complexity −

A - quick sort

B - selection sort

C - insertion sort

D - bubble sort

Answer : B


Selection sort best case time complexity is Ο(n2)

Q 10 - Which of the below mentioned sorting algorithms are not stable?

A - Selection Sort

B - Bubble Sort

C - Merge Sort

D - Insertion Sort

Answer : A


Except selection sort, all other soring algorithms are stable.

Q 11 - 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


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

Q 12 - A queue data-structure can be used for −

A - expression parsing

B - recursion

C - resource allocation

D - all of the above

Answer : C


Queues can be used for limited resource allocation. For other operations, stacks are used.

Q 13 - The Θ notation in asymptotic evaluation represents −

A - Base case

B - Average case

C - Worst case

D - NULL case

Answer : A


Θ represents average case. Ο represents worst case and Ω represents base case.

Q 14 - Which of these alogrithmic approach tries to achieve localized optimum solution −

A - Greedy approach

B - Divide and conquer approach

C - Dynamic approach

D - All of the above

Answer : A


Greedy approach focuses only on localized optimum solution.

Answer : C


Remembering the results of previously calculated solutions is called memoization.

Q 16 - Index of arrays in C programming langauge starts from

A - 0

B - 1

C - either 0 or 1

D - undefined

Answer : A


Arrays, in C, starts from 0 which is mapped to its base address.

Answer : A


After applying ->; we will not have stored anywhere if not explicitly mentioned.

Q 19 - Linked list search complexity is

A - Ο(1)

B - Ο(n)

C - Ο(log n)

D - Ο(log log n)

Answer : B


Linked lists has search complexity of Ο(n).

Q 20 - 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


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

Q 21 - In C programming, when we remove an item from bottom of the stack, then −

A - The stack will fall down.

B - Stack will rearranged items.

C - It will convert to LIFO

D - This operation is not allowed.

Answer : B


Stack can only be accessed from top of it.

Q 22 - Program with highest run-time complexity is

A - Tower of Hanoi

B - Fibonacci Series

C - Prime Number Series

D - None of the above

Answer : A


Tower of hanoi has the highest run time complexity

Q 23 - Tower of hanoi is a classic example of

A - divide and conquer

B - recursive approach

C - B but not A

D - Both A & B

Answer : D


The recursive approach of tower of hanoi uses divide and conquer method.

Q 24 - 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


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

Q 25 - If there's no base criteria in a recursive program, the program will

A - not be executed.

B - execute until all conditions match.

C - execute infinitely.

D - obtain progressive approach.

Answer : C


Without a base criteria and progressive approach, a recursion is just an infinite iteration.

Answer Sheet

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