Algorithms MCQ Quiz - Objective Question with Answer for Algorithms - Download Free PDF
Last updated on Jun 10, 2025
Latest Algorithms MCQ Objective Questions
Algorithms Question 1:
The weight of minimum spanning tree in graph G, calculated using Kruskal’s algorithm is:
Answer (Detailed Solution Below)
Algorithms Question 1 Detailed Solution
Concept:
A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges(V – 1 ) of a connected, edge-weighted undirected graph G(V, E) that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
Explanation:
Edge set for the given graph = {2, 3, 4, 5, 6, 7, 8}
For 5 vertices, we need 4 edges in MST,
So, edge set for MST = {2, 3, 4, 6}
Minimum spanning tree
Minimum cost 2 + 3 + 4 + 6 = 15
Algorithms Question 2:
Consider the following Statements
Statement 1: Greedy technique solves the problem correctly and always provides an optimized solution to the problem.
Statement 2: Bellman ford, Floyd-warshal, and Prim’s algorithms use the Dynamic Programming technique to solve the Path problems.
Which of the following is true?
Answer (Detailed Solution Below)
Algorithms Question 2 Detailed Solution
Answer: Option 3
Explanation:
Statement 1: Greedy technique solves the problem correctly and always provides an optimized solution to the problem.
This Statement is False. Since the Greedy technique does not always solve a problem correctly.
Statement 2: Bellman ford, Floyd-warshal, and Prim’s algorithms use the Dynamic Programming technique to solve the Path problems.
This Statement is also False Since Prim's algorithm does not use the Dynamic Programming technique.
Prim's algorithm is a greedy algorithm that finds a minimum spanning tree for a weighted undirected graph.
Algorithms Question 3:
Time complexity of Merge Sort Algorithm and Binary Search Algorithm are respectively:
Answer (Detailed Solution Below)
Algorithms Question 3 Detailed Solution
Merge sort
It is based on the divide and conquers approach.
Recurrence relation for merge sort will become:
T(n) = 2T (n/2) + Θ (n)
Using Master’s theorem
T (n) = n × log2n
Therefore, the time complexity of Merge Sort is θ(nlogn).
Binary Search
Search a sorted array by repeatedly dividing the search interval in half.
Recurrence for binary search is T(n) = T(n/2) + θ(1)
Using Master’s theorem
T (n) = log2n
Consider only half of the input list and throw out the other half. Hence time complexity is O(log n).
Algorithms Question 4:
Which of the following algorithm design technique is used in designing quick sort algorithm
Answer (Detailed Solution Below)
Algorithms Question 4 Detailed Solution
- Quicksort is a divide-and-conquer algorithm in which the pivot element is chosen, and this pivot element reduced the given problem into two smaller sets.
- Quick Sort is useful for sorting arrays.
- Inefficient implementations Quick Sort is not a stable sort, meaning that the relative order of equal sort items is not preserved.
- The overall time complexity of Quick Sort is O(nLogn). In the worst case, it makes O(n2) comparisons, though this behavior is rare.
- The space complexity of Quick Sort is O(nLogn). It is an in-place sort (i.e. it doesn’t require any extra storage).
Hence the correct answer is Divide and conquers strategy.
Algorithms Question 5:
Which one of the following properties of an algorithm ensures that each step of the algorithm is properly defined and the actions to be performed are clearly specified?
Answer (Detailed Solution Below)
Algorithms Question 5 Detailed Solution
Definiteness:
Each step must be precisely defined; the actions to be carried out must be rigorously and unambiguously specified for each case. input: An algorithm has zero or more inputs, taken from a specified set of objects. output: An algorithm has one or more outputs, which have a specified relation to the inputs.
Hence the correct answer is Definiteness.
Additional Information
Finiteness:
For any input, the algorithm must terminate after a finite number of steps. Definiteness: All steps of the algorithm must be precisely defined. Effectiveness: It must be possible to perform each step of the algorithm correctly and in a finite amount of time.
Effectiveness:
For an algorithm to be effective, it means that all those steps that are required to get to output must be feasible with the available resources. It should not contain any unnecessary and redundant steps which could make an algorithm ineffective.
input:
An algorithm has zero or more inputs, taken from a specified set of objects.
Output:
An algorithm has one or more outputs, which have a specified relation to the inputs.
Top Algorithms MCQ Objective Questions
A _________ is used to show the processing that takes place in the flowchart.
Answer (Detailed Solution Below)
Algorithms Question 6 Detailed Solution
Download Solution PDFConcept:
Flowcharts use special shapes to represent different types of actions or steps in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols.
Hence Option 4 is correct
What is the time complexity for the following C module? Assume that n > 0;
int module(int n)
{
if(n == 1)
return 1;
else
return (n + module(n-1));
}
Answer (Detailed Solution Below)
Algorithms Question 7 Detailed Solution
Download Solution PDFAnswer: Option 1
Explanation:
f(n) = n + module(n-1); / since return (n + module(n-1));
Here recurrence relation will be
T(n) = T(n-1) + c
≡ T(n-2) + c + c
≡ T(n-3) + 3c
≡ T(n-k) + kc
when n-k = 1 ; k = n-1 and T(1) = 1
≡ T(1) + (n-1)c
≡ (n-1)c
≡ O(n)
Hence Option 1 is correct answer.
Here some of you might have cam up with recurrence relation T(n) = T(n-1) + n, which is incorrect because in function n is just a variable it will have a constant value which will get added to call return value and In recurrence variable n indicate cost.
Consider the recurrence function \(T\left( n \right) = \left\{ {\begin{array}{*{20}{c}} {2T\left( {\sqrt n } \right) + 1,\;\;\;n > 2}\\ {2,\;\;\;0 < n \le 2} \end{array}} \right.\) Then T(n) in terms of Θ notation is
Answer (Detailed Solution Below)
Algorithms Question 8 Detailed Solution
Download Solution PDF\(T\left( n \right) = 2\;T\left( {\sqrt n } \right) + 1\)
Put n= 2m, m = log2n
\(T\left( {{2^m}} \right) = 2T\left( {{2^{\frac{m}{2}}}} \right) + 1\)
\(Put\;T\left( {{2^m}} \right) = S\left( m \right)\)
\(S\left( m \right) = 2\;S\;\left( {\frac{m}{2}} \right) + 1\)
Now, calculate \({n^{log_b^a}}\)
\({m^{log_b^a}} = m\)
S (m) = m + 1
S(m) = m
Put the value of m
Therefore, T(n) in terms of Θ notation is Θ (logn).
Which one of the following correctly determines the solution of the recurrence relation with
T(1) = 1?
\(T\left( n \right) = 2T\left( {\frac{n}{2}} \right) + \log n\)
Answer (Detailed Solution Below)
Algorithms Question 9 Detailed Solution
Download Solution PDF\({\rm{T}}\left( {\rm{n}} \right) = 2{\rm{T}}\left( {\frac{{\rm{n}}}{2}} \right) + \log {\rm{n}}\)
Comparing with:
\({\rm{T}}\left( {\rm{n}} \right) = {\rm{aT}}\left( {\frac{{\rm{n}}}{{\rm{b}}}} \right) + f\left( n \right)\)
a = 2, b = 2, f(n) = log n
\({n^{{{\log }_2}2}} = n\) > f(n)
By Master’s theorem
\(T\left( {\rm{n}} \right) = {\rm{O}}\left( {\rm{n}} \right)\)
Consider the following C function.
int fun1(int n) {
int i, j, k, p, q = 0;
for (i = 1; i < n; ++i) {
p = 0;
for (j = n; j > 1; j = j/2)
++ p;
for (k = 1; k<p; k = k*2)
++ q;
}
return q;
}
Which one of the following most closely approximates the return value of the function fun1?
Answer (Detailed Solution Below)
Algorithms Question 10 Detailed Solution
Download Solution PDF\(\begin{array}{l} \therefore p\; = \;\log n,\;q\; = \;\log p\; = \;\log \left( {\log n} \right)\\ \therefore q\; = \;n.\log \left( {\log n} \right) \end{array}\)
In flowchart representation, which of the following symbols indicates input/output?
Answer (Detailed Solution Below)
Algorithms Question 11 Detailed Solution
Download Solution PDFExplanation:
- An oval represents a start or end point
- A line is a connector that shows relationships between the representative shapes
- A parallelogram represents input and output
- A rectangle represents a process
- A diamond indicates a decision
The given symbol represents the predefined process such as a sub-routine or a module.
Design Element |
Shape |
Design Element |
Shape |
Design Element |
Shape |
Process |
|
Sequential data |
|
Parallel mode |
|
Terminator |
|
Direct data |
|
Loop limit |
|
Decision |
|
Manual input |
|
On-page reference |
|
Document |
|
Card |
|
Off-page reference |
|
Data (input and output) |
|
Paper tape |
|
Yes/No decision indicators |
|
Predefined process (such as subroutine or a module) |
|
Display |
|
Condition |
|
Stored data |
|
Manual operation |
|
Control transfer |
|
Internal storage |
|
Preparation |
|
Annotation |
|
Give asymptotic upper and lower bound for T(n) given below. Assume T(n) is constant for \(n \le 2.\;T\left( n \right) = 4T\left( {\sqrt n } \right) + lo{g^2}n\)
Answer (Detailed Solution Below)
Algorithms Question 12 Detailed Solution
Download Solution PDF\(T\left( n \right) = 4T\left( {√ n } \right) + lo{g^2}n\)
Consider n = 2m
m = log2n
n = 2m
Taking square root
√n = 2m/2
T(2m) = 4T(2m/2) + m2
Put S(m) = T (2m/2)
S(m) = 4 S(m/2) + m2
Comparing with
T(m) = a T(m/k) + cmk
a = 4, b = 2, k = 2
a = bk = 4
Now use master’s theorem :
T(m) = O(mklog m)
So, Time complexity will be O(m2log m)
Put the value of m
Time complexity will be : O (log2n log (logn))
Consider a hash table of size 7, with hash function H (k) = k % 7, and pseudo random i = (i + 5) % 7. We want to insert the following keys one by one from left to right.
15, 11, 25, 16, 9, 8, 12
What will be the position of the key 25, if we use random probing?Answer (Detailed Solution Below)
Algorithms Question 13 Detailed Solution
Download Solution PDFSince we are using random probing:
Insert 15:
(15)%7 = 1
Insert 11:
(11)%7 = 4
Insert 25:
(25)%7 = 4 / collision:
i = 4
i = (i + 5) % 7 / using random function
i = (4 + 5)%7 = 2
Hence 25 position is 2nd
The k-Means algorithm is an ______ algorithm.
Answer (Detailed Solution Below)
Algorithms Question 14 Detailed Solution
Download Solution PDFThe correct answer is Unsupervised Learning.
Key Points
1. Supervised Learning:
- In supervised learning, the algorithm is trained on a labeled dataset, where the input data is paired with corresponding output labels.
- The goal is to learn a mapping function from input to output so that the algorithm can make predictions or classifications on new, unseen data.
2. Unsupervised Learning:
- In unsupervised learning, the algorithm is given data without explicit instructions on what to do with it.
- The algorithm tries to find patterns, relationships, or structures within the data on its own.
- Clustering algorithms, like k-Means, fall under unsupervised learning because they group similar data points together without using labeled output information.
3. Semi-supervised Learning:
- Semi-supervised learning is a combination of supervised and unsupervised learning.
- It involves a dataset that contains both labeled and unlabeled examples.
- The algorithm is trained on the labeled data, and then it tries to make predictions on the unlabeled data by leveraging the patterns learned from the labeled data.
4. Reinforcement Learning:
- Reinforcement learning involves an agent interacting with an environment and learning to make decisions by receiving feedback in the form of rewards or punishments.
- The agent learns to take actions that maximize the cumulative reward over time.
- Unlike supervised learning, where the algorithm is provided with explicit labeled examples, in reinforcement learning, the algorithm learns by trial and error.
In the case of the k-Means algorithm, it is unsupervised learning because it doesn't rely on labeled output data. Instead, it aims to partition the input data into clusters based on similarity, without using predefined class labels.
Consider the following undirected graph with edge weights as shown:
The number of minimum-weight spanning trees of the graph is ______
Answer (Detailed Solution Below) 3
Algorithms Question 15 Detailed Solution
Download Solution PDFAnswer:3 to 3
Concept:
A minimum spanning tree (MST) or minimum weight spanning tree is a subset of the edges(V – 1 ) of a connected, edge-weighted undirected graph G(V, E) that connects all the vertices together, without any cycles and with the minimum possible total edge weight.
Explanation:
The minimum weight in the graph is 0.1 choosing this we get.
Suppose we get two trees T1 and T2.
To connect to those two trees we got 3 possible edges of weight 0.9.
Hence we can choose any one of those 3 edges.
No of Minimum weight spanning tree is 3.