# 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. # 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

### Explanation

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

### Explanation

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

### Explanation

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!

### Explanation

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)

### Explanation

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

### Explanation

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!

### Explanation

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

### Explanation

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

### Explanation

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)

### Explanation

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

### Explanation

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

### Explanation

Θ 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

### Explanation

Greedy approach focuses only on localized optimum solution.

### Explanation

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

### Explanation

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

### Explanation

One pointer variable can not store more than one address values.

### Explanation

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

Q 19 - Linked list search complexity is

A - Ο(1)

B - Ο(n)

C - Ο(log n)

D - Ο(log log n)

### Explanation

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

### Explanation

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.

### Explanation

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

### Explanation

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

### Explanation

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

### Explanation

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.

### Explanation

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

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