Sei sulla pagina 1di 29

KNAPSACK

 You are given a knapsack that can carry a maximum weight of 60. There are 4 items
with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the
items you can carry using the knapsack?
The Knapsack problem cannot be solved using the greedy algorithm.
Question A
The Knapsack problem is an example of ____________
a) Greedy algorithm
b) 2D dynamic programming
c) 1D dynamic programming
d) Divide and conquer
Question B
Which of the following methods can be used to solve the Knapsack problem?
a) Brute force algorithm
b) Recursion
c) Dynamic programming
d) Brute force, Recursion and Dynamic Programming
Question C
What is the time complexity of the brute force algorithm used to solve the Knapsack problem?
a) O(n)
b) O(n!)
n
c) O(2 )
3
d) O(n )
Question D
The 0-1 Knapsack problem can be solved using Greedy algorithm.
a) True
b) False

 Question 1
What is the missing number in the following sequence? 2, 12, 60, 240, 720, 1440, .... 0
answer choices
2880
1440
720
0
 Question 2
30 seconds
Q.
The area of a square is ‘d’. What is the area of the circle which has the diagonal of the
square as its diameter?
answer choices
πd
πd2
(1/4) πd2
(1/2)πd
 Question 3
10 seconds
Q.
How many edge are there in MCST generated from graph with 'n' vertices
answer choices
n-1
n/2 - 1
n-2
n/2
 Question 4
20 seconds
Q.
Prim’s & Kruskal’s algorithm run on a graph G and produce MCST TP and TK,
respectively, and TP is different from TK. Find true statement?
answer choices
If e is a minimum cost edge in G, e belongs to both TP and TK
If e is a maximum cost edge in G, e belongs to neither TP nor TK
All edges in G have the same weight
Some pair of edges in G have the same weight
 Question 5
5 seconds
Q.
Dijkstra algorithm is also called the …………………. shortest path problem.
answer choices
multiple source
single source
single destination
multiple destination
 Question 6
5 seconds
Q.
In Greedy method we get ________ Feasible solutions
answer choices
one
more than one
zero
hundred
 Question 7
20 seconds
Q.
Which of the following is true about Huffman Coding.
answer choices
Huffman coding may become lossy in some cases
Huffman Codes may not be optimal lossless codes in some cases
In Huffman coding, no code is prefix of any other code.
All
 Question 8
10 seconds
Q.
The files x1,x2,x3 are 3 files of length 30,20,10 records each. What is the optimal merge
pattern value?
answer choices
110
90
60
50
 Question 9
5 seconds
Q.
Fractional knapsack is based on ____________method
answer choices
Greedy
Branch and Bound
Dynamic Programming
Divide and Conquer
 Question 10
30 seconds
Q.
The output of Kruskal and Prims algorithm is ________________
answer choices
Maximum spanning tree
Spanning tree
Minimum spanning tree
None
 Question 11
30 seconds
Q.
What is a Greedy strategy for Optimal storage on tape
answer choices
Arrange all programs in decreasing order of length
Arrange all programs in First in first come basis
Arrange all programs in increasing order of length
Arrange all programs in random order
 Question 12
5 seconds
Q.
How do you determine the cost of a spanning tree?
answer choices
By the sum of costs of the edges of the tree
By the sum of the costs of the edges and vertices of the tree
By the sum of the costs of the vertices of the tree
By the sum of costs of the edges of the graph
 Question 13
20 seconds
Q.
Which is optimal value in the case of job sequence problem Item : 1 2 3 4 5..
Profit : 20 15 10 5 1
Deadline : 2 2 3 3 3
answer choices
1,3,4
1,2,4
4,2,3
1,5,2
 Question 14
5 seconds
Q.
The committee wrote a ____________ report, extolling only the strengths of the proposal
answer choices
reasonable
supportive
biased
fragmented
 Question 15
30 seconds
Report an issue
Q.
Given the four functions f1(n) = n100 , f2(n) = (1.2)n , f3(n) = 2n/2 , f4(n) = 3n/3..... which
function will have the largest value for sufficiently large values of n
answer choices
f4
f3
f2
f1
This set of Data Structures & Algorithms Multiple Choice Questions &
Answers (MCQs) focuses on “Minimum Spanning Tree”.

1. Which of the following is false in the case of a spanning tree of a graph G?

a) It is tree that spans G

b) It is a subgraph of the G

c) It includes every vertex of the G

d) It can be either cyclic or acyclic

..

2. Every graph has only one minimum spanning tree.

a) True

b) False

..

Explanation: Minimum spanning tree is a spanning tree with the lowest cost among all the
spacing trees. Sum of all of the edges in the spanning tree is the cost of the spanning tree. There
can be many minimum spanning trees for a given graph.

3. Consider a complete graph G with 4 vertices. The graph G has ____ spanning trees.

a) 15

b) 8

c) 16

d) 13

..

4. The travelling salesman problem can be solved using _________

a) A spanning tree

b) A minimum spanning tree


c) Bellman – Ford algorithm

d) DFS traversal

..

5. Consider the graph M with 3 vertices. Its adjacency matrix is shown below. Which of the
following is true?

a) Graph M has no minimum spanning tree

b) Graph M has a unique minimum spanning trees of cost 2

c) Graph M has 3 distinct minimum spanning trees, each of cost 2

d) Graph M has 3 spanning trees of different costs

..

6. Consider a undirected graph G with vertices { A, B, C, D, E}. In graph G, every edge has
distinct weight. Edge CD is edge with minimum weight and edge AB is edge with maximum
weight. Then, which of the following is false?

a) Every minimum spanning tree of G must contain CD

b) If AB is in a minimum spanning tree, then its removal must disconnect G

c) No minimum spanning tree contains AB

d) G has a unique minimum spanning tree

..

7. If all the weights of the graph are positive, then the minimum spanning tree of the graph is a
minimum cost subgraph.

a) True
b) False

..

8. Consider the graph shown below. Which of the following are the edges in the MST of the given
graph?

a) (a-c)(c-d)(d-b)(d-b)

b) (c-a)(a-d)(d-b)(d-e)

c) (a-d)(d-c)(d-b)(d-e)

d) (c-a)(a-d)(d-c)(d-b)(d-e)

..

9. Which of the following is not the algorithm to find the minimum spanning tree of the given
graph?

a) Boruvka’s algorithm

b) Prim’s algorithm

c) Kruskal’s algorithm

d) Bellman–Ford algorithm

..

10. Which of the following is false?

a) The spanning trees do not have any cycles


b) MST have n – 1 edges if the graph has n edges

c) Edge e belonging to a cut of the graph if has the weight smaller than any other edge in the
same cut, then the edge e is present in all the MSTs of the graph

d) Removing one edge from the spanning tree will not make the graph disconnected

..

Kruskal’s Algorithm Multiple Choice Questions and Answers (MCQs)


1. Kruskal’s algorithm is used to ______

a) find minimum spanning tree

b) find single source shortest path

c) find all pair shortest path algorithm

d) traverse the graph

..

2. Kruskal’s algorithm is a ______

a) divide and conquer algorithm

b) dynamic programming algorithm

c) greedy algorithm

d) approximation algorithm

..

3.

What is the weight of the minimum spanning tree using the Kruskal’s algorithm?
a)24
b)23
c)15
d)19
4. What is the time complexity of Kruskal’s algorithm?
a)O(logV)
b)O(ElogV)
c)O(E2)
d) O(V log E)

5. Consider the following graph. Using Kruskal’s algorithm, which edge will be selected first?

a)GF
b)DE
c)BE
d) BG

6. Which of the following edges form minimum spanning tree on the graph using
kruskalsalgorithm?

a) (B-E)(G-E)(E-F)(D-F)

b) (B-E)(G-E)(E-F)(B-G)(D-F)
c) (B-E)(G-E)(E-F)(D-E)
d) (B-E)(G-E)(E-F)(D-F)(D-G)

..

7. Which of the following is true?

a) Prim’s algorithm can also be used for disconnected graphs

b) Kruskal’s algorithm can also run on the disconnected graphs

c) Prim’s algorithm is simpler than Kruskal’s algorithm

d) In Kruskal’s sort edges are added to MST in decreasing order of their weights

..

8. Which of the following is false about the Kruskal’s algorithm?

a) It is a greedy algorithm

b) It constructs MST by selecting edges in increasing order of their weights

c) It can accept cycles in the MST

d) It uses union-find data structure

..

9. Kruskal’s algorithm is best suited for the dense graphs than the prim’s algorithm.

a) True

b) False

..

10. Consider the following statements.

S1. Kruskal’s algorithm might produce a non-minimal spanning tree.

S2. Kruskal’s algorithm can efficiently implemented using the disjoint-set data structure.

a) S1 is true but S2 is false


b) Both S1 and S2 are false

c) Both S1 and S2 are true

d) S2 is true but S1 is false

Prim’s Algorithm Multiple Choice Questions and Answers (MCQs)

1. Which of the following is true?

a) Prim’s algorithm initialises with a vertex

b) Prim’s algorithm initialises with a edge

c) Prim’s algorithm initialises with a vertex which has smallest edge

d) Prim’s algorithm initialises with a forest

..

2. Consider the given graph.


.

What is the weight of the minimum spanning tree using the Prim’s algorithm,starting from
vertex a?

a) 23

b) 28

c) 27

d) 11

..

3. Worst case is the worst case time complexity of Prim’s algorithm if adjacency matrix is used?

a) O(log V)

b) O(V2)

c) O(E2)

d) O(V log E)

..

4. Prim’s algorithm is a ______

a) Divide and conquer algorithm

b) Greedy algorithm
c) Dynamic Programming

d) Approximation algorithm

..

5. Prim’s algorithm resembles Dijkstra’s algorithm.

a) True

b) False

..

6. Kruskal’s algorithm is best suited for the sparse graphs than the prim’s algorithm.

a) True

b) False

..

7. Consider the graph shown below.

Which of the following edges form the MST of the given graph using Prim’a algorithm, starting
from vertex 4.
a) (4-3)(5-3)(2-3)(1-2)

b) (4-3)(3-5)(5-1)(1-2)

c) (4-3)(3-5)(5-2)(1-5)

d) (4-3)(3-2)(2-1)(1-5)

..

8. Prim’s algorithm is also known as __________

a) Dijkstra–Scholten algorithm

b) Borůvka’s algorithm

c) Floyd–Warshall algorithm

d) DJP Algorithm

..

9. Prim’s algorithm can be efficiently implemented using _____ for graphs with greater density.

a) d-ary heap

b) linear search

c) fibonacci heap

d) binary search

View Answer

10. Which of the following is false about Prim’s algorithm?

a) It is a greedy algorithm

b) It constructs MST by selecting edges in increasing order of their weights

c) It never accepts cycles in the MST

d) It can be implemented using the Fibonacci heap


Dijkstra’s Algorithm Multiple Choice Questions and Answers
(MCQs)

1. Dijkstra’s Algorithm is used to solve _____________ problems.

a) All pair shortest path

b) Single source shortest path

c) Network flow

d) Sorting
..

2. Which of the following is the most commonly used data structure for implementing Dijkstra’s
Algorithm?

a) Max priority queue

b) Stack

c) Circular queue

d) Min priority queue

..

3. What is the time complexity of Dijikstra’s algorithm?

a) O(N)

b) O(N3)

c) O(N2)

d) O(logN)

..

4. Dijkstra’s Algorithm cannot be applied on ______________

a) Directed and weighted graphs

b) Graphs having negative weight function

c) Unweighted graphs

d) Undirected and unweighted graphs

..

5. What is the pseudo code to compute the shortest path in Dijkstra’s algorithm?

a)
if(!T[w].Known)

if(T[v].Dist + C(v,w) < T[w].Dist) {

Decrease(T[w].Dist to T[v].Dist +C(v,w));

T[w].path=v; }

b)

if(T[w].Known)

if(T[v].Dist + C(v,w) < T[w].Dist) {

Increase (T[w].Dist to T[v].Dist +C(v,w));

T[w].path=v; }

c)

if(!T[w].Known)

if(T[v].Dist + C(v,w) > T[w].Dist) {

Decrease(T[w].Dist to T[v].Dist +C(v,w);

T[w].path=v; }

d)

if(T[w].Known)

if(T[v].Dist + C(v,w) < T[w].Dist) {

Increase(T[w].Dist to T[v].Dist);

T[w].path=v; }

..
6. How many priority queue operations are involved in Dijkstra’s Algorithm?

a) 1

b) 3

c) 2

d) 4

..

7. How many times the insert and extract min operations are invoked per vertex?

a) 1

b) 2

c) 3

d) 0

..

8. The maximum number of times the decrease key operation performed in Dijkstra’s algorithm
will be equal to ___________

a) Total number of vertices

b) Total number of edges

c) Number of vertices – 1

d) Number of edges – 1

..

9. What is running time of Dijkstra’s algorithm using Binary min- heap method?

a) O(V)

b) O(VlogV)

c) O(E)
d) O(ElogV)

..

10. The running time of Bellmann Ford algorithm is lower than that of Dijkstra’s Algorithm.

a) True

b) False

..

11. Dijkstra’s Algorithm run on a weighted, directed graph G={V,E} with non-negative weight
function w and source s, terminates with d[u]=delta(s,u) for all vertices u in V.

a) True

b) False

..

12. Given pseudo code of Dijkstra’s Algorithm.

1. //Initialise single source(G,s)

2. S=0

3. Q=V[G]

4. While Q != 0

5. Do u=extract-min(Q)

6. S=S union {u}

7. For each vertex v in adj[u]

8. Do relax(u,v,w)

What happens when while loop in line 4 is changed to while Q>1?

a) While loop gets executed for v times


b) While loop gets executed for v-1 times

c) While loop gets executed only once

d) While loop does not get executed

..

13. Consider the following graph.

If b is the source vertex, what is the minimum cost to reach f vertex?

a) 8

b) 9

c) 4

d) 6

..

14. In the given graph:


Identify the shortest path having minimum cost to reach vertex E if A is the source vertex

a) a-b-e

b) a-c-e

c) a-c-d-e

d) a-c-d-b-e

..

15. Dijkstra’s Algorithm is the prime example for ___________

a) Greedy algorithm

b) Branch and bound

c) Back tracking

d) Dynamic programming

16.Consider the following graph:


:

What is the minimum cost to travel from node A to node C

a) 5

b) 2

c) 1

d) 3

17. In the given graph:


Identify the path that has minimum cost to travel from node a to node f

a) a-b-c-f

b) a-d-e-f

c) a-d-b-c-f

d) a-d-b-c-e-f

What is the space complexity of the recursive implementation used to find the nth fibonacci
term?

a) O(1)

b) O(n)

c) O(n2)

d) O(n3)

What is the time complexity of the recursive implementation used to find the nth fibonacci
term?
a) O(1)
b) O(n2)
c) O(n!)
d) Exponential
Data Structure Questions and Answers – Hash Tables
This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Hash
Tables”.

1. What is a hash table?

a) A structure that maps values to keys

b) A structure that maps keys to values

c) A structure used for storage

d) A structure used to implement stack and queue

..

2. If several elements are competing for the same bucket in the hash table, what is it called?

a) Diffusion

b) Replication

c) Collision

d) Duplication

..

3. What is direct addressing?

a) Distinct array position for every possible key

b) Fewer array positions than keys

c) Fewer keys than array positions

d) Same array position for all keys

..
4. What is the search complexity in direct addressing?

a) O(n)

b) O(logn)

c) O(nlogn)

d) O(1)

..

5. What is a hash function?

a) A function has allocated memory to keys

b) A function that computes the location of the key in the array

c) A function that creates an array

d) A function that computes the location of the values in the array

..

6. Which of the following is not a technique to avoid a collision?

a) Make the hash function appear random

b) Use the chaining method

c) Use uniform hashing

d) Increasing hash table size

..

7. What is the load factor?

a) Average array size

b) Average key size

c) Average chain length


d) Average hash table length

..

8. What is simple uniform hashing?

a) Every element has equal probability of hashing into any of the slots

b) A weighted probabilistic method is used to hash elements into the slots

c) Elements has Random probability of hashing into array slots

d) Elements are hashed based on priority

..

9. In simple uniform hashing, what is the search complexity?

a) O(n)

b) O(logn)

c) O(nlogn)

d) O(1)

10. In simple chaining, what data structure is appropriate?

a) Singly linked list

b) Doubly linked list

c) Circular linked list

d) Binary trees

11. What is the hash function used in the division method?


a) h(k) = k/m
b) h(k) = k mod m
c) h(k) = m/k
d) h(k) = m mod k

Potrebbero piacerti anche