G27

Algorithms

151 questions in 7 topics. Try each one before you press "Show answer".

Analysis of algorithms

GATE 2026 · Set 1 · MCQQ1 · page 97 of the book
Consider the following recurrence relations:
For all n>1,
T1(n)=4T1(n/2)+T2(n)
T2(n)=5T2(n/4)+Θ(log2n)
Assume that for all n≤1, T1(n)=1 and T2(n)=1.
Which one of the following options is correct?
  • (a)T1(n)=θ(n2)
  • (b)T1(n)=θ(n2log2n)
  • (c)T1(n)=θ(nlog4 5)
  • (d)T1(n) = Θ(nlog4⁡5log2⁡n)
GATE 2026 · Set 2 · MSQQ2 · page 97 of the book
Which of the following can be recurrence
relation(s) corresponding to an algorithm with time
complexity O(n)?
  • (a)T(n)=T(n-1) +1, T(1)=1
  • (b)T(n)=2T(n/2)+1 , T(1)=1
  • (c)T(n)=2T(n/2)+n , T(1)=1
  • (d)T(n)=T(n-1)+n , T(1)=1
GATE 2026 · Set 2 · MCQ · 1 markQ3 · page 97 of the book
Consider the following functions, where n is a
positive integer.
n1/3 , logn , log(n!) , 2logn
Which one of the following options lists the
functions in increasing order of asymptotic growth
rate? Note: Assume the base of log to be 2.
  • (a)logn , n1/3 , 2logn , log(n!)
  • (b)n1/3 , logn , log(n!) , 2logn
  • (c)logn , n1/3 , log(n!) , 2logn
  • (d)2logn , n1/3 , logn , log(n!)
GATE 2025 · Set 1 · MCQQ4 · page 97 of the book
Consider the following recurrence relation:
T(n)=2T(n-1)+ n2n for n>0, T(0)=1
Which ONE of the following options is CORRECT?
  • (a)T(n)=θ(n22n)
  • (b)T(n)=θ(n2n)
  • (c)T(n)=θ((logn)22n)
  • (d)T(n)=θ(4n) 4
GATE 2024 · Set 1 · MCQQ5 · page 97 of the book
Consider the following recurrence relation:

T(n) = {√n ⋅ T(√n) + n
for n ≥ 1
1
for n = 1
Which one of the following options is CORRECT?
  • (a)T(n) = θ(nloglogn)
  • (b)T(n) = θ(n2logn)
  • (c)T(n) = θ(nlogn)
  • (d)T(n) = θ(n2loglogn)
GATE 2024 · Set 2 · MCQ · 1 markQ6 · page 97 of the book
Let T(n) be the recurrence relation defined as
follows:
T(0) = 1,
T(1) = 2 and
T(n) = 5T(n - 1) - 6T(n - 2) for n ≥ 2
Which one of the following statement is TRUE?
  • (a)T(n) = θ(n·3n)
  • (b)T(n) = θ(n·2n)
  • (c)T(n) = θ(3n)
  • (d)T(n) = θ(2n) ALGORITHMS b b
GATE 2023 · MSQ · 1 markQ7 · page 98 of the book
Let f and g be functions of natural numbers given
by f(n)=n and g(n)=n2. Which of the following
statements is/are TRUE?
  • (a)f ∈ O(g)
  • (b)f ∈ ω(g)
  • (c)f ∈ o(g)
  • (d)f ∈ θ(g)
GATE 2023 · MSQ · 2 marksQ8 · page 98 of the book
Consider functions Function 1 and Function 2
expressed in pseudocode as follows:Function 1
and Function 2

Function 1
while n > 1 do
for i = 1 to n
do
x = x + 1;
end for
n = ⌊n/2⌋;
end while
Function 2
for i = 1 to 100 * n
do
x = x + 1;
end for
Let f1(n) and f2(n) denote the number of times the
statement x = x + 1; is executed in Function 1 and
Function 2, respectively.
  • (a)f1 (n) ∈⁡θ(f2 (n))
  • (b)f1 (n) ∈⁡o(f2 (n))
  • (c)f2 (n) ∈ ω(f1 (n))
  • (d)f1 (n) ∈ O(n)
GATE 2022 · MCQ · 1 markQ9 · page 98 of the book
Which one of the following statements is TRUE
for all positive functions f(n)?
  • (a)f(n2) = θ(f(n)2), when f(n) is a polynomial
  • (b)f(n2)=o(f(n)2)
  • (c)f(n2) = O(f(n)2), when f(n) is an exponential function
  • (d)f(n2)= Ω (f(n)2) which one of the following options is correct?
  • (a)T(n) = θ((log n) 5/2)
  • (b)T(n) = θ(n)
  • (c)T(n) = θ(nlog n)
  • (d)T(n) = θ(n 5/2) ALGORITHMS
GATE 2021 · Set 2 · MCQ · 2 marksQ10 · page 98 of the book
For constants a ≥ 1 and b > 1, consider the
following recurrence defined on the non-negative
integers:
T(n) = a T (n/b) + f(n)
Which one of the following options is correct about
the recurrence T(n) ?
  • (a)f(n) is O(nlog (a)-∈) for some ∈>0, then T(n) is T(n)=Θ(n log (a))
  • (b)If f(n) is n/log2(n), then T(n) is Θ(log2(n))
  • (c)If f(n) is Θ(nlogb (a)), then T(n) is Θ(nlogb (a))
  • (d)If f(n) is n log2(n), then T(n) is Θ(nlog2(n))
GATE 2021 · Set 1 · MCQQ11 · page 98 of the book
Consider the following three functions.
f1 = 10n
f2 = n logn
f3 = n✓n
Which one of the following options arranges the
function in the increasing order of asymptotic
growth rate?
  • (a)f2, f1, f3
  • (b)f3, f2, f1
  • (c)f2, f3, f1
  • (d)f1, f2, f3
GATE 2021 · Set 1 · MCQ · 1 markQ12 · page 98 of the book
Consider the following recurrence relation.
T(n) = T(n/2) + T(2n/5) + 7n
, if n > 0
{
1 , if n = 0
GATE 2020 · MCQQ13 · page 99 of the book
For parameters a and b, both of which are ω(1),
T(n) = T(n 1/a ) + 1, and T(b)=1. Then T(n) is:
  • (a)θ(log ab n)
  • (b)θ(log a log b n)
  • (c)θ(log 2 log 2 n)
  • (d)θ(log b log a n)
GATE 2017 · Set 1 · MCQ · 2 marksQ14 · page 99 of the book
Consider the following functions from positives
integers to real numbers 10, √n, n, log2n, 100/n. The
CORRECT arrangement of the above functions in
increasing order of asymptotic complexity is:
  • (a)log2n, 100/n, 10, √n, n
  • (b)100/n, 10, log2n, √n, n
  • (c)10, 100/n , √n, log2 n, n
  • (d)100/n, log2n, 10 , √n, n
GATE 2017 · Set 2 · MCQ · 2 marksQ15 · page 99 of the book
Consider the following C function
int fun(int n) {
int i, j;
for(i=1; i<=n; i++) {
for (j=1; j<n; j+=i) {
printf("%d %d", i, j);
}
}
}
Time complexity of fun in terms of θ notation is
  • (a)θ ( n✓n )
  • (b)θ(n2)
  • (c)θ(n log n)
  • (d)θ(n2 log n)
GATE 2017 · Set 2 · MCQ · 2 marksQ16 · page 99 of the book
Consider the recurrence function
2 × T(√n) + 1,
if n > 2
GATE 2016 · Set 2 · NATQ17 · page 99 of the book
The given diagram shows the flowchart for a
recursive function A(n). Assume that all
statements, except for the recursive calls, have
O(1) time complexity. If the worst-case time
complexity of this function is O(nα ), then the least
possible value (accurate up to two decimal
positions) of α is
.
Flowchart for Recursive Function A(n)
GATE 2015 · Set 1 · MCQ · 2 marksQ18 · page 99 of the book
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?
  • (a)n3
  • (b)n(logn)2
  • (c)nlogn
  • (d)nlog(logn)
year not read yetQ19 · page 99 of the book
Let f(n) = n and g(n) = n (1 +sin n)
, where n is a
positive integer. Which of the following statements
is/are correct?
T(n) = {
2,
if 0 < n ≤ 2
I. f(n) = O(g(n))
Then T(n) in terms of θ notation is
  • (a)θ(log logn)
  • (b)θ(log n)
  • (c)θ(√n)
  • (d)θ(n) II. f(n) = Ω(g(n))
  • (a)Only I
  • (b)Only II
  • (c)Both I and II
  • (d)Neither I nor II ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2015 · Set 2 · MCQ · 1 markQ20 · page 100 of the book
Consider a complete binary tree where the left and
the right subtrees of the root are max heaps. The
lower bound for the number of operations to
convert the tree to a heap is
  • (a)Ω(logn)
  • (b)Ω(n)
  • (c)Ω(nlogn)
  • (d)Ω(n2)
GATE 2015 · Set 3 · MCQQ21 · page 100 of the book
Consider the equality X =∑i=0
n i3
following choices for X:
I. Θ(n4)
II. Θ(n5)
III. O(n5)
IV. Ω(n3)
GATE 2014 · Set 3 · NAT · 2 marksQ22 · page 100 of the book
Suppose we have a balanced binary search tree T
holding n numbers. We are given two numbers L
and H and wish to sum up all the numbers in T that
lie between L and H. Suppose there are m such
numbers in T. If the tightest upper bound on the
time to compute the sum is
O(na logb n + mc logd n)
the value of a + 10b + 100c + 1000d is
.
for (j=2; j<=n; j=j*2)
k = k + n/2;
return (k);
}
The return value of the function is
  • (a)Θ(n2)
  • (b)Θ(n2log n)
  • (c)Θ(n3)
  • (d)Θ(n3log n)
GATE 2014 · Set 2 · MCQ · 1 markQ23 · page 100 of the book
Which one of the following correctly
determines the solution of the recurrence relation
with T(1)=1?
T(n)=2T(n/2) + logn
  • (a)θ( n )
  • (b)θ( n log n )
  • (c)θ( n2 )
  • (d)θ( log n )
GATE 2013 · Set 3 · MCQQ24 · page 100 of the book
Consider the following function:
int unknown(int n){
int i, j, k=0;
for (i=n/2; i<=n; i++)
The equality above remains correct if X is
replaced by
  • (a)Only I
  • (b)Only II
  • (c)I or III or IV but not II
  • (d)II or III or IV but not I
GATE 2012 · MCQ · 1 markQ25 · page 100 of the book
Let W(n) and A(n) denote respectively, the worst
case and average case running time of an algorithm
executed on an input of size n. Which of the
following is ALWAYS TRUE?
  • (a)A(n) = Ω (W(n))
  • (b)A(n) = Θ (W(n))
  • (c)A(n) = O (W(n))
  • (d)A(n) = o (W(n)) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank ! 2
GATE 2011 · MCQQ26 · page 101 of the book
Which of the given options provides the
increasing order of asymptotic complexity of
functions f 1 , f 2 , f 3 and f 4 ?
f1(n)=2n , f2(n)=n3/2, f3(n)=nlog2n , f4(n)=nlog n
  • (a)f3, f2, f4, f1
  • (b)f3, f2, f1, f4
  • (c)f2, f3, f1, f4
  • (d)f2, f3, f4, f1
GATE 2009 · MCQ · 1 markQ27 · page 101 of the book
The running time of an algorithm is represented
by the following recurrence relation:
n ; n ≤ 3
T(n) = {
n
T ( ) + cn; otherwise
3
GATE 2008 · MCQQ28 · page 101 of the book
Consider the following functions:
f(n) = 2n
g(n) = n!
h(n) = nlogn
Which of the following statements about the
asymptotic behaviour of f(n), g(n), and h(n) is
true?
  • (a)f(n) = O(g(n)); g(n) = O(h(n))
  • (b)f(n) = Ω(g(n)); g(n) = O(h(n))
  • (c)g(n) = O(f(n)); h(n) = O(f(n))
  • (d)h(n) = O(f(n)); g(n) = Ω(f(n))
GATE 2008 · MCQ · 2 marksQ29 · page 101 of the book
When n = 2(2k) for some k >= 0, the recurrence
relation T(n) = √(2)T(n/2) + √(n), T(1) = 1
evaluates to :
  • (a)(√n)(log n + 1)
  • (b)(√n) log n
  • (c)(√n) log (√n)
  • (d)n log (√n) if(n == 0 || n == 1) return n; else return (2*f1(n-1) + 3*f1(n-2)); } int f2(int n) { int i; int X[N], Y[N], Z[N] ; X[0] = Y[0] = Z[0] = 0; X[1] = 1; Y[1] = 2; Z[1] = 3; for(i = 2; i <= n; i++) { X[i] = Y[i-1] + Z[i-2]; Y[i] = 2*X[i]; Z[i] = 3*X[i]; } return X[n] ; } The running time of f1(n) and f2(n) are
  • (a)Θ(n) and Θ(n)
  • (b)Θ(2n) and Θ(n)
  • (c)Θ(n) and Θ(2n)
  • (d)Θ(2n) and Θ(2n) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2008 · MCQQ30 · page 101 of the book
Arrange the following functions in increasing
asymptotic order:
a. n1/3
b. en
c. n7/4
d. nlog9n
e. 1.0000001n
  • (a)a, d, c, e, b
  • (b)d, a, c, e, b
  • (c)a, c, d, e, b
  • (d)a, c, d, b, e
GATE 2008 · MCQ · 2 marksQ31 · page 101 of the book
Consider the following C functions:int f1(int n)
{
Which one of the following represents the time
complexity of the algorithm?
  • (a)θ (n)
  • (b)θ (n log n)
  • (c)θ (n2)
  • (d)θ (n2logn)
GATE 2007 · MCQ · 1 markQ32 · page 102 of the book
Exponentiation is a heavily used operation in
public key cryptography. Which of the following
options is the tightest upper bound on the number
of multiplications required to compute bnmod
m,0≤b , n≤m?
  • (a)O(logn)
  • (b)O(√n )
  • (c)O(n/logn)
  • (d)O(n)
GATE 2007 · MCQQ33 · page 102 of the book
In the following C function, let n≥m.
int gcd(n,m)
{
if (n%m ==0) return m;
n = n%m;
return gcd(m,n);
}
How many recursive calls are made by this
function?
  • (a)θ(logn)
  • (b)ω(n)
  • (c)θ(loglogn)
  • (d)Θ(√ n )
GATE 2007 · MCQ · 1 markQ34 · page 102 of the book
Consider the following C code segment: int
IsPrime(n)
{
year not read yetQ35 · page 102 of the book
What is the Asymptotic Notation of the following
recursive function:
int DoSomething (int n) {
if (n <= 2)
return 1;
else
return (DoSomething (floor(sqrt(n))) + n); }
  • (a)θ (n2)
  • (b)θ (nlog2n)
  • (c)θ (log2n)
  • (d)θ (log2log2n)
GATE 2006 · MCQ · 1 markQ36 · page 102 of the book
Consider the following C-program fragment in
which i, j, and n are integer variables.
for (i = n, j = 0; i > 0; i/=2, j += i);
Let Val(j) denote the value stored in the variable j
after termination of the for loop. Which one of the
following is true?
  • (a)val(j)= θ (logn)
  • (b)val(j)= θ (sqrt(n))
  • (c)val(j)= θ (n)
  • (d)val(j)= θ (nlogn)
GATE 2006 · MCQ · 1 markQ37 · page 102 of the book
Consider the following recurrence:

T(n) = 2T([√n]) + 1, T(1) = 1
Which one of the following is true?
int i,n;
for(i=2;i<=sqrt(n);i++)
if(n%i == 0)
{printf("Not Primen"); return 0;}
return 1;
} Let T(n)denote the number of times the for
loop is executed by the program on input n.
Which of the following is TRUE?
  • (a)T(n)=O(√n ) and T(n)=Ω(√n )
  • (b)T(n)=O(n) and T(n)=Ω(√n )
  • (c)T(n)=O(√n ) and T(n)=Ω(1)
  • (d)None of the above
  • (a)T(n)= θ (loglogn)
  • (b)T(n)= θ (logn)
  • (c)T(n)= θ (√n)
  • (d)T(n)= θ (n)
GATE 2005 · MCQQ38 · page 102 of the book
Suppose T(n)=2T(n/2)+n,
T(0)=T(1)=1
Which one of the following is FALSE?
  • (a)T(n)=O(n2)
  • (b)T(n)=Θ(n log n)
  • (c)T(n)=Ω(n2)
  • (d)T(n)=O(n log n) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank ! 4 4
GATE 2005 · MCQ · 1 markQ39 · page 103 of the book
The Asymptotic Notation of computing the
transitive closure of a binary relation on a set of n
elements is known to be:
  • (a)O(n)
  • (b)O(nlogn)
  • (c)O(n3/2)
  • (d)O(n3)
GATE 2005 · MCQ · 1 markQ40 · page 103 of the book
Consider the following C-function:
double foo (int n)
{
int i;
double sum;
if (n = = 0) return 1.0;
else
{
sum = 0.0;
for (i = 0; i < n; i++)
sum += foo (i);
return sum;
}
}
Suppose we modify the above function foo() and
store the values of foo (i), 0⁡≤⁡i < n, as and
when they are computed. With this modification,
the time complexity for function foo() is
significantly reduced. The space complexity of
the modified function would be:
  • (a)O(1)
  • (b)O(n)
  • (c)O(n!)
  • (d)O(nn)

Divide and conquer

GATE 2026 · Set 2 · NATQ1 · page 108 of the book
Consider an array A = [10, 7, 8, 19, 41,35, 25, 31].
Suppose the merge sort algorithm is executed on
array A to sort it in increasing order. The merge
sort algorithm will carry out a total of 7 merge
operations.
A merge operation on sorted left array L and
sorted right array R is said to be void if the output
of the merge operation is the elements of array L
followed by the elements of array R.
The number of void merge operations among
these 7 merge operations is
. (answer in
integer)
GATE 2021 · Set 1 · MCQQ2 · page 108 of the book
Let P be an array containing n integers. Let t be the
lowest upper bound on the number of comparisons
of the array elements, required to find the minimum
and maximum values in an arbitrary array of n
elements. Which one of the following choices is
correct?
  • (a)t > 2n – 2
  • (b)t > ⌈ log (n) ⌉ and t <= n
  • (c)t > n and t <= 3 ⌈ n/2 ⌉
  • (d)t > 3 ⌈ n/2 ⌉⁡and t <= 2n – 2
GATE 2021 · Set 1 · MCQ · 1 markQ3 · page 108 of the book
Consider the following array:
23 , 32 , 45 , 69 , 72 , 73 , 89 , 97
Which algorithm out of the following options uses
the least number of comparisons (among the array
elements) to sort the above array in ascending
order?
  • (a)Quicksort using the last element as pivot
  • (b)Selection sort
  • (c)Merge sort
  • (d)Insertion sort
GATE 2020 · NAT · 1 markQ4 · page 108 of the book
An array of 25 distinct elements is to be sorted
using quicksort. Assume that the pivot element is
chosen uniformly at random. The probability that
the pivot element gets placed in the worst possible
location in the first round of partitioning (rounded
off to 2 decimal places) is
GATE 2019 · NAT · 1 markQ5 · page 108 of the book
Consider a sequence of 14
elements:A=[-5,-10,6,3,-1,-2,13,4,-9,-1,4,12,-3
,0].The sequence sum S(i, j) = ∑j k=i
A[k].Determine the maximum of S(i ,j), where 0≤
i≤ j< 14.(Divide and conquer approach may be
used.)
GATE 2019 · MCQ · 2 marksQ6 · page 108 of the book
There are n unsorted arrays: A 1 , A 2 , ..., A n .
Assume that n is odd. Each of A 1 , A 2 , ..., A n
contains n distinct elements. There are no common
elements between any two arrays. The worst-case
time complexity of computing the median of the
medians of A 1 , A 2 , ..., A n is
  • (a)O(n)
  • (b)O(n log n)
  • (c)O(n2)
  • (d)Ω(n2 log n)
GATE 2016 · Set 2 · MCQQ7 · page 108 of the book
Assume that the algorithms considered here sort the
input sequences in ascending order. If the input is
already in ascending order, which of the following are
TRUE?
I. Quick sort runs in Θ(n2) time
II. Bubble sort runs in Θ(n2) time
III. Merge sort runs in Θ(n) time
IV. Insertion sort runs in Θ(n) time
  • (a)I and II only
  • (b)I and III only
  • (c)II and IV only
  • (d)I and IV only ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
  • (a)
GATE 2016 · Set 1 · MCQQ8 · page 109 of the book
The worst-case running time of Insertion sort,
Merge sort and Quick sort, respectively, are:
  • (a)θ(nlogn), θ(nlogn) and θ(n2)
  • (b)θ(n2) , θ(n2) and θ(nlogn)
  • (c)θ(n2), θ(nlogn) and θ(nlogn)
  • (d)θ(n2), θ(nlogn) and θ(n2)
GATE 2015 · Set 2 · MCQ · 1 markQ9 · page 109 of the book
Suppose you are provided with the following
function declaration in the C programming
language.
int partition(int a[ ], int n);
The function treats the first element of a[] as a
pivot, and rearranges the array so that all elements
less than or equal to the pivot is in the left part of
the array, and all elements greater than the pivot
is in the right part. In addition, it moves the pivot
so that the pivot is the last element of the left part.
The return value is the number of elements in the
left part. The following partially given function in
the C programming language is used to find the
k-th smallest element in an array a[ ] of size n
using the partition function. We assume k <= n
C
int kth_smallest(int a[], int n, int k)
{
int left_end = partition(a, n);
if ( left_end+1 == k ){
return a[left_end];
}
if ( left_end+1 > k ){
return kth_smallest(
);
} else {
return kth_smallest(
);
}
}
The missing arguments lists are respectively
  • (a)(a, left_end, k) and (a + left_end +1, n- left_end -1, k-left_end -1)
  • (b)( a, left_end, k ) and ( a, n-left_end -1, k- left_end -1 )
  • (c)( a + left_end +1, n-left_end -1, k- left_end -1 ) and ( a, left_end, k )
  • (d)(a, n-left_end -1, k-left_end -1) and (a, left_end, k)
year not read yetQ10 · page 109 of the book
Which one of the following is the recurrence
equation for the worst case time complexity of the
Quicksort algorithm for sorting n ( >=2) numbers?
In the recurrence equations given in the options
below, c is a constant.
  • (a)T(n)=2T(n/2)+cn
  • (b)T(n)=T(n-1)+T(1)+cn
  • (c)T(n)=2T(n-1)+cn
  • (d)T(n)=T(n/2)+cn
GATE 2014 · Set 3 · MCQ · 2 marksQ11 · page 109 of the book
You have an array of n elements. Suppose you
implement quick sort by always choosing the
central element of the array as the pivot. Then the
tightest upper bound for the worst case
performance is
  • (a)O(n2)
  • (b)O(nlogn)
  • (c)θ(nlogn)
  • (d)O(n3)
GATE 2014 · Set 1 · MCQ · 2 marksQ12 · page 109 of the book
Let P is a quick sort program to sort numbers in
ascending order using the first element as the pivot.
Let t1 and t2 be the number of comparisons made by
P for the inputs [1 2 3 4 5] and [4 1 5 3 2] respectively.
Which one of the following holds?
  • (a)t1 = 5
  • (b)t1 < t2
  • (c)t1 > t2
  • (d)t1 = t2
GATE 2014 · Set 1 · NAT · 2 marksQ13 · page 109 of the book
The minimum number of comparisons required
finding the minimum and the maximum of 100
numbers is
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !

HINTS & SOLUTIONS
GATE 2012 · MCQQ14 · page 110 of the book
A list of n strings, each of length n, is sorted
into lexicographic order using the merge-sort
algorithm. The worst case running time of this
computation is
  • (a)O (n log n)
  • (b)O (n2 log n)
  • (c)O (n2 + log n)
  • (d)O (n2 )
GATE 2009 · MCQ · 1 markQ15 · page 110 of the book
In quick sort, for sorting n elements, the (n/4)th
smallest element is selected as pivot using an
O(n) time algorithm. What is the worst case time
complexity of the quick sort?
  • (a)θ(n)
  • (b)θ(nlogn)
  • (c)θ(n2)
  • (d)θ(n2logn)
GATE 2008 · MCQ · 1 markQ16 · page 110 of the book
The average case and worst case complexities
for Merge sort algorithm are
  • (a)O(n log n),O(n2)
  • (b)O(n2), O(nlog2 n)
  • (c)O(n2logn) ,O(n2)
  • (d)O(nlog2n) , O(nlog2 n)

Greedy method

year not read yetQ1 · page 113 of the book
Let G(V,E) be an undirected, edge-weighted graph
with integer weights. The weight of a path is the
sum of the weights of the edges in that path. The
length of a path is the number of edges in that path.
Let s∈V be a vertex in G. For every u∈V and for
every k ≥0, let dk(u) denote the weight of a shortest
path (in terms of weight) from s to u of length at
most k. If there is no path from s to u of length at
most k, then dk(u)=∞.Consider the statements:
S1: For every k ≥0 and u ∈V, dk+1(u)≤dk(u).
S2: For every (u,v)∈E, if (u,v) is part of a shortest
path (in terms of weight) from s to v, then for every
k≥ 0,dk(u)≤dk(v).
Which one of the following options is correct?
  • (a)Only S1 is true
  • (b)Only S2 is true
  • (c)Both S1 and S2 are true
  • (d)Neither S1 nor S2 is true
GATE 2026 · Set 1 · MSQQ2 · page 113 of the book
Let G(V,E) be a simple, undirected, edge-weighted
graph with unique edge weights. Which of the
following statements about the minimum spanning
trees (MST) of G is/are true?
  • (a)In every cycle C of G, the edge with the largest weight in C is not in any MST
  • (b)In every cycle C of G, the edge with the smallest weight in C is in every MST
  • (c)For every vertex v ∈V, the edge with the largest weight incident on v is not in any MST
  • (d)For every vertex v ∈V, the edge with the smallest weight incident on v is in every MST
GATE 2026 · Set 2 · MCQ · 2 marksQ3 · page 113 of the book
Let G be a weighted directed acyclic graph with m
edges and n vertices. Given G and a source vertex s
in G, which one of the following options gives the
worst case time complexity of the fastest algorithm
to find the lengths of shortest paths from s to all
vertices that are reachable from s in G?
  • (a)Θ(m + n)
  • (b)Θ(m + n log(n))
  • (c)Θ(nm)
  • (d)Θ(n3)
GATE 2025 · Set 1 · MCQ · 1 markQ4 · page 113 of the book
Let G be any undirected graph with positive edge
weights, and T be a minimum spanning tree of G.
For any two vertices, u and v, let d1(u,v) and d2(u,v)
be the shortest distances between u and v in G and
T, respectively. Which ONE of the options is
CORRECT for all possible G, T, u and v?
  • (a)d1 (u, v) = d2 (u, v)
  • (b)d1 (u, v) ≤ d2 (u, v)
  • (c)d1 (u, v) ≥ d2 (u, v)
  • (d)d1 (u, v) != d2 (u, v)
GATE 2025 · Set 2 · MCQQ5 · page 113 of the book
Let G be an edge-weighted undirected graph with
positive edge weights. Suppose a positive constant α
is added to the weight of every edge. Which ONE of
the following statements is TRUE about the
minimum spanning trees (MSTs) and shortest paths
(SPs) in G before and after the edge weight update?
  • (a)Every MST remains an MST, and every SP remains an SP.
  • (b)MSTs need not remain MSTs, and every SP remains an SP.
  • (c)Every MST remains an MST, and SPs need not remain SPs.
  • (d)MSTs need not remain MSTs, and SPs need not remain SPs. ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2025 · Set 1 · NAT · 2 marksQ6 · page 114 of the book
The maximum value of x such that the edge
between the nodes B and C is included in every
minimum spanning tree of the given graph is

. (Answer in integer)
GATE 2025 · Set 1 · MCQQ7 · page 114 of the book
Let G(V, E) be an undirected and unweighted
graph with 100 vertices. Let d(u, v) denote the
number of edges in a shortest path between
vertices u and v in V. Let the maximum value of
d(u, v), u, v ∈⁡V such that u ≠ v, be 30. Let T be
any breadth-first-search tree of G. Which ONE of
the given options is CORRECT for every such
graph G?
  • (a)The height of T is exactly 15.
  • (b)The height of T is exactly 30.
  • (c)The height of T is at least 15.
  • (d)The height of T is at least 30.
year not read yetQ8 · page 114 of the book
The number of spanning tree in complete labelled
graph of 4 vertices labelled A, B, C, and D is......
GATE 2024 · Set 2 · MCQ · 2 marksQ9 · page 114 of the book
Let G be an undirected connected graph in which
every edge has a positive integer weight. Suppose
that every spanning tree in G has even weight.
Which of the following statements is/are TRUE
for every such graph G?
  • (a)All edges in G have even weight.
  • (b)In each cycle C in G, all edges in C have even weight.
  • (c)All edges in G have even weight or all edges in G have odd weight.
  • (d)In each cycle C in G, either all edges in C have even weight OR all edges in C have odd weight.
GATE 2024 · Set 2 · NATQ10 · page 114 of the book
The number of distinct minimum-weight spanning
trees of the following graph is
.
GATE 2022 · NAT · 1 markQ11 · page 114 of the book
"Let G(V, E) be a directed graph, where V = {1, 2,
3, 4, 5} is the set of vertices and E is the set of
directed edges, as defined by the following
adjacency matrix A.

"A[i][j] = 1 indicates a directed edge from node i
to node j."A directed spanning tree of G, rooted at
r ∈⁡V, is defined as "a subgraph T of G such that
the undirected version of T is a tree, and T
contains a directed path from r to every other
vertex in V." The number of such directed
spanning trees rooted at vertex 5 is
.
GATE 2022 · MSQQ12 · page 114 of the book
Consider a simple undirected weighted graph G,
all of whose edge weights are distinct.
Which of the following statements about the
minimum spanning trees of G is/are TRUE?
  • (a)The edge with the second smallest weight is always part of any minimum spanning tree of G.
  • (b)One or both of the edges with the third smallest and the fourth smallest weights are part of any minimum spanning tree of G
  • (c)Suppose S⊆V be such that S != φ and S != V. Consider the edge with the minimum weight such that one of its vertices is in S and the other in V∖S. Such an edge will always be part of any minimum spanning tree of G
  • (d)G can have multiple minimum spanning trees. ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2021 · Set 1 · NAT · 1 markQ13 · page 115 of the book
Consider the following undirected graph with
edge weights as shown:

The number of minimum-spanning trees of the
graph is
.
GATE 2021 · Set 2 · 2 marksQ14 · page 115 of the book
Consider the string abbccddeee. Each letter in
the string must be assigned a binary code
satisfying the following properties:
For any two letters, the code assigned to one
letter must not be a prefix of the code assigned
to the other letter.
For any two letters of the same frequency, the
letter which occurs earlier in the dictionary order
is assigned a code whose length is at most the
length of the code assigned to the other letter.
Among the set of all binary code assignments
which satisfy the above two properties, what is
the minimum length of the encoded string?
  • (a)21
  • (b)23
  • (c)25
  • (d)30
GATE 2021 · Set 2 · MCQ · 2 marksQ15 · page 115 of the book
Let G be a connected undirected weighted graph.
Consider the following two statements.
S1 : There exists a minimum weight edge in G
which is present in every minimum spanning
tree of G.
S2 : If every edge in G has distinct weight, then
G has a unique minimum spanning tree.
Which one of the following options is correct?
  • (a)S 1 is true and S 2 is false.
  • (b)S 1 is false and S 2 is true.
  • (c)Both S 1 and S 2 are true.
  • (d)Both S 1 and S 2 are false.
year not read yetQ16 · page 115 of the book
Let G = (V, E) be a directed, weighed graph with
weight function w : E -> R. For some function f : V -
> R, for each edge (u, v) in E, define w'(u, v) as w(u,
v) + f(u) - f(v).
Which one of the options completes the following
sentence so that it is TRUE?
"The shortest paths in G under w are shortest paths
under w' too,
".
  • (a)for every f : V -> R
  • (b)if and only if for all u in V, f(u) is positive
  • (c)if and only if for all u in V, f(u) is negative
  • (d)if and only if f(u) is the distance from s to u in the graph obtained by adding a new vertex s to G and edges of zero weight from s to every vertex of G
GATE 2020 · MCQ · 2 marksQ17 · page 115 of the book
Let G = (V, E) be a weighted undirected graph and
let T be a Minimum Spanning Tree (MST) of G
maintained using adjacency lists. Suppose a new
weighted edge (u,v) ∈ V × V is added to G. The
worst case time complexity determining if T is still
an MST of the resultant graph is
  • (a)θ(|E| log |V|)
  • (b)θ(|E| + |V|)
  • (c)θ(|E| |V|)
  • (d)θ (|V|)
GATE 2020 · NAT · 2 marksQ18 · page 115 of the book
Consider a graph G = (V, E), where V = {v 1 , v 2 ,
..., v 100 }, E = {(v i , v j ) | 1 <= i <= j <= 100}, and
weight of the edge (v i , v j ) is |i – j|. The weight of
the minimum spanning tree of G is   .
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !
5
GATE 2019 · MCQ · 2 marksQ19 · page 116 of the book
Let G be any connected, weighted, undirected
graph.
I. G has a unique minimum spanning tree, if no
two edges of G have the same weight.
II. G has a unique minimum spanning tree, if, for
every cut of G, there is a unique minimum-
weight edge crossing the cut.
Which of the above two statements is/are
TRUE?
  • (a)I only
  • (b)II only
  • (c)Both I and II
  • (d)Neither I nor II
GATE 2018 · NAT · 2 marksQ20 · page 116 of the book
Consider the following undirected graph G:

Choose a value of x that will maximize the
number of minimum weight spanning trees
(MWSTs) of G. The number of MWSTs of G for
this value of x is
.
GATE 2016 · Set 1 · MCQ · 2 marksQ21 · page 116 of the book
Let G be a complete undirected graph on 4
vertices having 6 edges with weights being 1,2
a minimum weight spanning tree of G can have
is
.
  • (a)4
  • (b)5
  • (c)6
  • (d)7 W= [ 0 2 8 5 2 0 5 8 8 5 0 x 5 8 x 0 ] The largest possible integer value of x, for which at least one shortest path between some pair of vertices will contain the edge with weight x is . ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2016 · Set 1 · MCQQ22 · page 116 of the book
Let G be a weighted connected undirected graph
with distinct positive edge weights. If every edge
weight is increased by the same value, then which
of the following statements is/are TRUE?

P: Minimum spanning tree of G does not change
Q: Shortest path between any pair of vertices does
not change
  • (a)P only
  • (b)Q only
  • (c)Neither P nor Q
  • (d)Both P and Q
GATE 2016 · Set 1 · MCQQ23 · page 116 of the book
G = (V, E) is an undirected simple graph in which
each edge has a distinct weight, and e is a particular
edge of G. Which of the following statements about
the minimum spanning trees (MSTs) of G is/are
TRUE?
I. If e is the lightest edge of some cycle in G, then
every MST of G includes e
II. If e is the heaviest edge of some cycle in G, then
every MST of G excludes e
  • (a)i only
  • (b)ii only
  • (c)both i and ii
  • (d)neither i and ii
GATE 2016 · Set 1 · NAT · 2 marksQ24 · page 116 of the book
Consider the weighted undirected graph with 4
vertices, where the weight of edge {i, j} is given by
the entry W ij in the matrix W.
GATE 2017 · Set 2 · NATQ25 · page 117 of the book
A message is made up entirely of characters from
the set X = {P,Q,R,S,T} . The table of
probabilities of each character is shown below :

Character
Probability
P
0.22
Q
0.17
R
0.34
S
0.19
T
0.08
Total
1.00
A message of 100 characters over X is encoded
using Huffman coding. Then the excepted length
of the encoded message in bits is
GATE 2015 · Set 1 · NAT · 2 marksQ26 · page 117 of the book
The graph shown below has 8 edges with distinct
integer edge weights. The minimum spanning
tree (MST) is of weight 36 and contains the edges:
{(A, C), (B, C), (B, E), (E, F), (D, F)}. The edge
weights of only those edges which are in the MST
are given in the figure shown below. The
minimum possible sum of weights of all 8 edges
of this graph is
GATE 2015 · Set 3 · NAT · 2 marksQ27 · page 117 of the book
Let G be a connected undirected graph of 100
vertices and 300 edges. The weight of a minimum
spanning tree of G is 500. When the weight of
each edge of G is increased by five, the weight of
a minimum spanning tree becomes
.
GATE 2013 · MCQ · 1 markQ28 · page 117 of the book
What is the time complexity of Bellman-Ford
single-source shortest path algorithm on a complete
graph of n vertices?
  • (a)Θ(n2)
  • (b)Θ(n2log n)
  • (c)Θ(n3)
  • (d)Θ(n3log n)
GATE 2012 · MCQ · 2 marksQ29 · page 117 of the book
Let G be a weighted graph with edge weights
greater than one and G' be the graph constructed by
squaring the weights of edges in G. Let T and T' be
the minimum spanning trees of G and G' ,
respectively, with total weights t and t' . Which of
the following statements is TRUE?
  • (a)T' = T with total weight t' = t 2
  • (b)T' = T with total weight t' < t 2
  • (c)T' ≠ T but total weight t' = t2
  • (d)None of the above
GATE 2012 · MCQ · 2 marksQ30 · page 117 of the book
Consider the directed graph shown in the figure
below. There are multiple shortest paths between
vertices S and T. Which one will be reported by
Dijkstra's shortest path algorithm? Assume that, in
any iteration, the shortest path to a vertex v is
updated only when a strictly shorter path to v is
discovered.
  • (a)SDT
  • (b)SBDT
  • (c)SACDT
  • (d)SACET 4 ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
year not read yetQ31 · page 118 of the book
An undirected graph G(V,E) contains n (n > 2)
nodes named v1, v2... vn. Two nodes vi , vj are
connected if and only if 0 < | i- j | < = 2 . Each
edge ( vi, vj )is assigned a weight i + j. A sample
graph with n = 4 is shown below.

What will be the cost of the minimum spanning
tree (MST) of such a graph with 11 nodes?
  • (a)1 / 11 ( 11 n2 - 5n )
  • (b)n2 - n + 1
  • (c)6n – 11
  • (d)2n + 1
GATE 2011 · MCQ · 2 marksQ32 · page 118 of the book
An undirected graph G(V, E) contains n (n > 2)
nodes named v1, v2, . . . , vn. Two nodes vi, vj are
connected if and only if 0 < |i - j| ≤ 2. Each edge
(vi, vj) is assigned a weight i + j. A sample graph
with n = 4 is shown below.

The length of the path from v5 to v6 in the
MST of previous question with n = 10 is
  • (a)11
  • (b)25
  • (c)31
  • (d)41
GATE 2010 · MCQ · 2 marksQ33 · page 118 of the book
Consider a complete undirected graph with vertex
set {0, 1, 2, 3, 4}. Entry Wij in the matrix W below
is the weight of the edge {i, j}.

0
1
8
1 4
l1
0
12
4 9
W = ⎪8 12
0
7 3⎪
1
4
7
0 2
h4
9
3
2 0)
What is the minimum possible weight of a spanning
tree T in this graph such that vertex 0 is a leaf node
in the tree T?
  • (a)7
  • (b)8
  • (c)9
  • (d)10
GATE 2009 · MCQ · 2 marksQ34 · page 118 of the book
Consider the following graph:

Which one of the following is NOT the
sequence of edges added to the minimum
spanning tree using Kruskal's algorithm?
  • (a)(b,e) (e,f) (a,c) (b,c) (f,g) (c,d)
  • (b)(b,e) (e,f) (a,c) (f,g) (b,c) (c,d)
  • (c)(b,e) (a,c) (e,f) (b,c) (f,g) (c,d)
  • (d)(b,e) (e,f) (b,c) (a,c) (f,g) (c,d) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
year not read yetQ35 · page 119 of the book
Which of the following statement(s) is/are
correct regarding Bellman-Ford
shortest path algorithm?
P. Always finds a negative weighted cycle, if
one exists.
Q. Finds whether any negative weighted cycle
is reachable from the source.
  • (a)P only
  • (b)Q only
  • (c)Both P and Q
  • (d)Neither P nor Q
GATE 2008 · MCQ · 2 marksQ36 · page 119 of the book
For the undirected, weighted graph given below,
which of the following sequences of edges
represents a correct execution of Prim's algorithm
to construct a Minimum Spanning Tree?
  • (a)(a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)
  • (b)(c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)
  • (c)(d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)
  • (d)(h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)
GATE 2008 · MCQ · 2 marksQ37 · page 119 of the book
Dijkstra's single source shortest path algorithm
when run from vertex a in the above graph,
computes the correct shortest path distance to
  • (a)only vertex a
  • (b)only vertices a, e, f, g, h
  • (c)only vertices a, b, c, d
  • (d)all the vertices
GATE 2007 · MCQQ38 · page 119 of the book
Consider a weighted, undirected graph with positive
edge weights and let u v be an edge in the graph. It is
known that the shortest path from the source vertex s
to u has weight 53 and the shortest path from s to v
has weight 65. Which one of the following statements
?
  • (a)Weight(u,v)≤12
  • (b)Weight(u,v)=12
  • (c)Weight(u,v)≥12
  • (d)Weight(u,v)>12
GATE 2007 · MCQQ39 · page 119 of the book
Let w be the minimum weight among all edge
weights in an undirected connected graph. Let e be a
specific edge of weight w. Which of the following is
False ?
  • (a)There is a minimum spanning tree containing e.
  • (b)If e is not in a minimum spanning tree T, then in the cycle formed by adding e to T, all edges have the same weight.
  • (c)Every minimum spanning tree has an edge of weight w.
  • (d)e is present in every minimum spanning tree.
GATE 2007 · MCQ · 1 markQ40 · page 119 of the book
Suppose the letters a, b, c, d, e, f have probabilities
1/2, 1/4, 1/8, 1/16, 1/32, 1/32 respectively.
What is the average length of the Huffman code for
the letters a,b,c,d,e,f?
  • (a)3
  • (b)2.1875
  • (c)2.25
  • (d)1.9375
GATE 2007 · MCQ · 1 markQ41 · page 119 of the book
Suppose the letters a, b, c, d, e, f have probabilities
1/2, 1/4, 1/8, 1/16, 1/32, 1/32 respectively.
Which of the following is the Huffman code for
the letter a, b, c, d, e, f?
  • (a)0, 10, 110, 1110, 11110, 11111
  • (b)11, 10, 011, 010, 001, 000
  • (c)11, 10, 01, 001, 0001, 0000
  • (d)110, 100, 010, 000, 001, 111 ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
year not read yetQ42 · page 120 of the book
The characters a to h have the set of frequencies
based on the first 8 Fibonacci numbers as
follows
a:1, b:1, c:2, d:3, e:5, f:8, g:13, h:21
A Huffman code is used to represent the
characters. What is the sequence of characters
corresponding to the following code?
110111100111010
  • (a)fdheg
  • (b)ecgdf
  • (c)dchfg
  • (d)fehdg
GATE 2006 · MCQ · 1 markQ43 · page 120 of the book
Consider the following graph:

Which one of the following cannot be the sequence of
edges added, in that order, to a minimum spanning
tree using Kruskal's algorithm?
  • (a)(a - b), (d - f), (b - f), (d - c), (d - e)
  • (b)(a - b), (d - f), (d - c), (b - f), (d - e)
  • (c)(d - f), (a - b), (d - c), (b - f), (d - e)
  • (d)(d - f), (a - b), (b - f), (d - e), (d - c)
GATE 2005 · MCQ · 1 markQ44 · page 120 of the book
Let s and t be two vertices in a undirected graph
G=(V, E) having distinct positive edge weights.
Let [X, Y] be a partition of V such that s∈ X and
t∈⁡Y. Consider the edge e having the minimum
weight amongst all those edges that have one
vertex in X and one vertex in Y.
The edge e must definitely belong to:
  • (a)the minimum weighted spanning tree of G
  • (b)the weighted shortest path from s to t
  • (c)each path from s to t
  • (d)the weighted longest path from s to t
GATE 2005 · MCQ · 1 markQ45 · page 120 of the book
An undirected graph G has n nodes. Its adjacency
matrix is given by an nxn square matrix whose
(i) diagonal elements are 0's and
(ii) non-diagonal elements are 1's.
which one of the following is TRUE?
  • (a)Graph G has no minimum spanning tree (MST)
  • (b)Graph G has a unique MST of cost n-1
  • (c)Graph G has multiple distinct MSTs, each of cost n-1
  • (d)Graph G has multiple spanning trees of different costs
GATE 2005 · MCQ · 1 markQ46 · page 120 of the book
Let G(V,E) be an undirected graph with positive
edge weights. Dijkstra's single source shortest path
algorithm can be implemented using the binary
heap data structure with time complexity:
  • (a)O(|V|2)
  • (b)O(|E| + |V| log |V|)
  • (c)O(|V| log |V|)
  • (d)O((|E| + |V|) log |V|) ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank ! i i
GATE 2005 · NAT · 1 markQ47 · page 121 of the book
Let G be a directed graph whose vertex set is the
set of numbers from 1 to 100. There is an edge
from a vertex i to a vertex j iff either j = i + 1 or j
= 3i. The minimum number of edges in a path in G
from vertex 1 to vertex 100 is:
  • (a)4
  • (b)7
  • (c)23
  • (d)99
GATE 2005 · MCQ · 1 markQ48 · page 121 of the book
We are given 9 tasks T1, T2... T9. The execution
of each task requires one unit of time. We can
execute one task at a time. Each task Ti has a
profit Pi and a deadline di Profit Pi is earned if the
task is completed before the end of the d th unit of
time.
What is the maximum profit earned?
  • (a)147
  • (b)165
  • (c)167
  • (d)175
GATE 2005 · MCQ · 1 markQ49 · page 121 of the book
We are given 9 tasks T1, T2... T9. The execution
of each task requires one unit of time. We can
execute one task at a time. Each task Ti has a
profit Pi and a deadline di Profit Pi is earned if the
task is completed before the end of the d th unit of
time.
Are all tasks completed in the schedule that
gives maximum profit?
  • (a)All tasks are completed
  • (b)T1 and T6 are left out
  • (c)T1 and T8 are left out
  • (d)T4 and T6 are left out

Dynamic programming

GATE 2026 · Set 2 · MCQ · 2 marksQ1 · page 130 of the book
Consider a table T, where the elements T[i][j],
0 <= i, j <= n, represent the cost of the optimal
solutions of different subproblems of a problem
that is being solved using a dynamic
programming algorithm. The recursive
formulation to compute the table entries is as
follows:
T[0][k] = T[k][0] = 1
for k = 0, 1, 2, ..., n

T[i][j] = 2T[i-1][j]+3T[i][j-1] for 1 ≤ i, j ≤ n

Consider the following two algorithms to
compute entries of T. Assume that for both the
algorithms, for all 0 ≤ i, j ≤ n, T[i][j] has been
initialized to 1.
Algorithm B1:
For i = 1 to n
For j = 1 to n
T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]
Algorithm B2:
For s = 2 to 2n
For i = 1 to n
For j = 1 to n
If (i + j == s)
T[i][j] = 2T[i - 1][j] + 3T[i][j - 1]

Algorithm Bk, k ∈ {1, 2}, is said to be correct if
and only if it calculates the correct values of
T[i][j], for all 0 ≤ i, j ≤ n, as per the recursive
formulation, at the end of the execution of the
algorithm Bk.
Which one of the following statements is true?
  • (a)Both algorithms B1 and B2 are correct
  • (b)Algorithm B1 is correct, but algorithm B2 is incorrect
  • (c)Algorithm B2 is correct, but algorithm B1 is incorrect
  • (d)Both algorithms B1 and B2 are incorrect
GATE 2021 · Set 1 · MSQQ2 · page 130 of the book
Define Rn to be the maximum amount earned by
cutting a rod of length n meters into one or more
pieces of integer length and selling them. For i >
0, let p[i] denote the selling prices of a rod whose
length is i meters. Consider the array of prices :
p[1] = 1, p[2] = 5, p[3] = 8, p[4] = 9, p[5] = 10,
p[6] = 17, p[7] = 18

Which of the following statements is/are correct
about R 7 ?
  • (a)R7 cannot be achieved by a solution consisting of three pieces.
  • (b)R7 = 19
  • (c)R7 = 18
  • (d)R7 is achieved by three different solutions.
GATE 2018 · MCQ · 2 marksQ3 · page 130 of the book
Assume that multiplying a matrix G 1 of
dimension p×q with another matrix G 2 of
dimension q × r requires scalar multiplications.
Computing the product of matrices
G1 G2 G3 ......Gn can be done by
parenthesizing in different ways. Define Gi
Gi+1 as an explicitly computed pair for a given
parenthesization if they are directly multiplied.
For example, in the matrix multiplication chain
G1 G2 G3 G4 G5 G6 using parenthesization
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !

(G1(G2G3)) (G4(G5G6)).G2 G3 and G5 G6 are
the only explicitly computed pairs. Consider a
matrix multiplication chain F1 F2 F3 F4 F5 ,
where matrices F1 F2 F3 F4 F5 are of
dimensions 2 × 25, 25 × 3, 3 × 16, 16 × 1 and
1×1000, respectively.In the parenthesization of
F1 F2 F3 F4 F5 that minimizes the total number
of
scalar
multiplications,
the
explicitly
computed pairs is/are:
GATE 2018 · NAT · 2 marksQ4 · page 131 of the book
Consider the weights and values of items listed
below. Note that there is only one unit of each item.
The task is to pick a subset of these items such that
their total weight is no more than 11 Kgs and their
total value is maximized. Moreover, no item may be
split. The total value of items picked by an optimal
algorithm is denoted by Vopt. A greedy algorithm
sorts the items by their value-to-weight ratios in
descending order and packs them greedily, starting
from the first item in the ordered list. The total value
of items picked by the greedy algorithm is denoted
by Vgreedy.
The value of Vopt - Vgreedy is
GATE 2016 · Set 2 · NAT · 2 marksQ5 · page 131 of the book
Let A 1 , A 2 , A 3 , and A 4 be four matrices of
dimensions 10 × 5, 5 × 20, 20 × 10, and 10 × 5,
respectively. The minimum number of scalar
multiplications required to find the product
A1A2A3A4
using
the
basic
matrix
multiplication method is   .
GATE 2014 · Set 2 · NAT · 2 marksQ6 · page 131 of the book
Consider two strings A = {"qpqrr"} and B =
"pqprqrp". Let x be the length of the longest
common
subsequence
(not
necessarily
contiguous) between A and B and let y be the
number of such longest common subsequences
between A and B. Then x+10y =
.
  • (a)248000
  • (b)44000
  • (b)19000
  • (d)25000 1 otherwise Finally the length of the longest monotonically increasing sequence is Max (L0 , L1 ,....,L n-1 ). Which of the following statements is TRUE?
  • (a)The algorithm uses dynamic programming paradigm
  • (b)The algorithm has a linear complexity and uses branch and bound paradigm
  • (c)The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm.
  • (d)The algorithm uses divide and conquer paradigm.
GATE 2011 · MCQ · 1 markQ7 · page 131 of the book
An algorithm to find the length of the longest
monotonically increasing sequence of numbers
in an array A[0: n - 1] is given below. Let L;
denote the length of the longest monotonically
increasing sequence starting at index i in the
array. Initialize L n-1 = 1. For all i such that 0 ≤
i ≤ n – 2
b) F2 F3 only
L = 1 + Li+1
if A[i] < A[i + 1]
i
{
c) F3 F4 only
d) F1,F2 and F4
GATE 2011 · MCQ · 2 marksQ8 · page 131 of the book
Four matrices M1, M2, M3 and M4 of
dimensions pxq, qxr, rxs and sxt respectively
can be multiplied is several ways with different
number of total scalar multiplications. For
example, when multiplied as ((M1 X M2) X (M3
X M4)), the total number of multiplications is
pqr + rst + prt. If p = 10, q = 100, r = 20, s = 5
and t = 80, then the number of scalar
multiplications needed is:
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2010 · MCQ · 2 marksQ9 · page 132 of the book
The weight of a sequence a0 , a1 , ..., an–1 of real
numbers is defined as a0 + a1 / 2 + ...+ a n–1 /2n–1 .
A subsequence of a sequence is obtained by
deleting some elements from the sequence,
keeping the order of the remaining elements the
same. Let X denote the maximum possible weight
of a subsequence of a0 , a1 ,..., an-1 . Then X is equal
to
  • (a)max(Y, a0 + Y)
  • (b)max(Y, a0 + Y/2)
  • (c)max(Y, a0 + 2Y)
  • (d)a0 + Y/2
GATE 2009 · MCQ · 2 marksQ10 · page 132 of the book
A sub-sequence of a given sequence is just the
given sequence with some elements (possibly
none or all) left out. We are given two sequences
X[m] and Y[n] of lengths m and n, respectively,
with indexes of X and Y starting from 0.
We wish to find the length of the longest
common sub-sequence (LCS) of x[m] and Y[n]
as l(m,n), where an incomplete recursive
definition for the function l(i,j) to compute the
length of the LCS of x[m] and Y[n] is given
below:

0, if either i = 0 or j = 0
l(i, j) = { expr1, if i, j > 0 and x [i⁡-⁡1] = Y [j -⁡1]⁡
expr2, if i, j > 0 and x [i - 1] ! = Y [j - 1]
Which one of the following options is correct?
  • (a)expr1 = l(i-1, j) + 1
  • (b)expr1 = l(i, j-1)
  • (c)expr2 = max (l(i-1, j), l(i,j-1))
  • (d)expr2 = max(l(i-1, j-1), l(i,j))
year not read yetQ11 · page 132 of the book
The subset-sum problem is defined as follows.
Given
a
set
of
n
positive
integers,
S={a1,a2,...,an} and positive integer W, is there
a subset of S whose elements sum to W? A
dynamic program for solving this problem uses
a 2-dimensional Boolean array, X, with n rows
and W+1 columns. X[i,j], 1≤i≤n, 0≤j≤W, is
TRUE if and only if there is a subset of
{a1,a2,...,ai }whose elements sum to j.
Which entry of the array X, if TRUE, implies
that there is a subset whose elements sum to W?
  • (a)X[1,W]
  • (b)X[n,0]
  • (c)X[n,W]
  • (d)X[n-1,n]
GATE 2008 · MCQ · 2 marksQ12 · page 132 of the book
The subset-sum problem is defined as follows.
Given a set of n positive integers, S={a1,a2,...,an
} and positive integer W, is there a subset of S
whose elements sum to W? A dynamic program
for solving this problem uses a 2-dimensional
Boolean array, X, with n rows and W+1
columns. X[i,j], 1≤i≤n, 0≤j≤W, is TRUE if and
only if there is a subset of {a1,a2,...,ai }whose
elements sum to j.Which of the following is
valid for 2≤i≤n and ai≤j≤W?
  • (a)X[i,j]=X[i-1,j]∨X[i,j-ai ]
  • (b)X[i,j]=X[i-1,j]∨X[i-1,j-ai ]
  • (c)X[i,j]=X[i-1,j]∧X[i,j-ai ]
  • (d)X[i,j]=X[i-1,j]∧X[i-1,j-ai ] ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !

Graph techniques

GATE 2026 · Set 1 · MSQ · 2 marksQ1 · page 136 of the book
Consider the following pseudocode for depth-first
search (DFS) algorithm which takes a directed
graph G(V,E) as input, where d[v] and f[v] are the
discovery time and finishing time, respectively, of
the vertex v ∈V.

DFS(G) :
unmark all v ∈ V
t ← 0
for each v ∈ V
if v is unmarked
t ← Explore
(G, v, t )
end if
end for
Explore ( G, v, t ):
mark v
t ← t + 1
d[v] ← t
for each (v, w) ∈ E
if w is unmarked
t ← Explore (G, w, t)
end if
end for
t ← t + 1
f[v] ← t
return t
Suppose that the input directed graph G(V,E) is a
directed acyclic graph (DAG). For an edge
(u,v)∈E, which of the following options will
NEVER be correct?
  • (a)d[u]<d[v]<f[v]<f[u]
  • (b)d[v]<d[u]<f[u]<f[v]
  • (c)d[v]<f[v]<d[u]<f[u]
  • (d)d[u]<d[v]<f[u]<f[v]
GATE 2026 · Set 1 · MSQ · 2 marksQ2 · page 136 of the book
An undirected, unweighted, simple graph G(V, E) is
said to be 2 -colorable if there exists a function c: V →
{0,1} such that for every (u, v) ∈ E, c(u) ≠ c(v).
Which of the following statements about 2-
colorable graphs is/are true?
  • (a)If G is 2-colorable, then G may contain cycles of odd length
  • (b)If G is 2-colorable, then G may contain cycles of even length
  • (c)An optimal algorithm for testing whether G is 2-colorable runs in time Θ(|V|+|E|), if G is represented as an adjacency list
  • (d)An optimal algorithm for testing whether G is 2-colorable runs in time Θ(|E|log|V|), if G is represented as an adjacency list.
GATE 2025 · Set 2 · NAT · 2 marksQ3 · page 136 of the book
Consider the following algorithm someAlgo that
takes an undirected graph G as input.
someAlgo(G) :
1. Let v be any vertex in G. Run BFS on G starting
at v. Let u be a vertex in G at maximum distance
from v as given by the BFS.

2. Run BFS on G again with u as the starting vertex.
Let z be the vertex at maximum distance from u as
given by the BFS.
3. Output the distance between u and z in G.
The output of someAlgo(T) for the tree shown in the
given figure is
. (Answer in integer)

5 5
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2025 · Set 2 · MSQ · 1 markQ4 · page 137 of the book
Which of the following statements regarding
Breadth First Search (BFS) and Depth First Search
(DFS) on an undirected simple graph G is/are
TRUE?
  • (a)A DFS tree of G is a Shortest Path tree of G.
  • (b)Every non-tree edge of G with respect to a DFS tree is a forward/back edge.
  • (c)If (u, v) is a non-tree edge of G with respect to a BFS tree, then the distances from the source vertex s to u and v in the BFS tree are within ±1 of each other.
  • (d)Both BFS and DFS can be used to find the connected components of G.
GATE 2024 · Set 1 · MCQQ5 · page 137 of the book
Let G be a directed graph and T a depth first search
(DFS) spanning tree in G that is rooted at a vertex
GATE 2024 · Set 1 · NATQ6 · page 137 of the book
The number of edges present in the forest
generated by the DFS traversal of an undirected
graph G with 100 vertices is 40. The number of
connected components in G is
Which one of the following statements is true?
  • (a)⌈⁡diam (G) / 2⌉ < diam (G 2 ) < diam(G)
  • (b)diam(G 2 ) = diam(G)
  • (c)diam(G) = diam(G 2 ) <= 2 diam(G)
  • (d)diam(G 2 ) <= ⌈⁡diam (G) / 2 ⌉
GATE 2023 · NAT · 2 marksQ7 · page 137 of the book
Let U = {1, 2, 3}. Let 2U denote the powerset of U.
Consider an undirected graph G whose vertex set is
2U. For any A, B in 2U, (A, B) is an edge in G if and
only if (i) A != B, and (ii) either A ⊆⁡B or B ⊆⁡A.
For any vertex A in G, the set of all possible orderings
in which the vertices of G can be visited in a Breadth
First Search (BFS) starting from A is denoted by
B(A).
If Φ denotes the empty set, then the cardinality of
B(Φ) is   .
GATE 2021 · Set 1 · MCQQ8 · page 137 of the book
Let G = (V, E) be an undirected unweighted
connected graph. The diameter of G is defined as:
diam(G)=max{" the length of shortest path
between " u" and " v}
Let M be the adjacency matrix of G. Define graph
G2 on the same set of vertices with adjacency
matrix N, where
v. Suppose T is also a breadth first search (BFS)
N
1
if Mij > 0 or Pij > 0
tree in G, rooted at v. Which of the following
statements is/are TRUE for every such graph G and
ij = {0
where P = M2.
otherwise
tree T?
  • (a)The only edges in G are the edges in T
  • (b)There are no cross-edges in G with respect to the tree T
  • (c)There are no back-edges in G with respect to the tree T
  • (d)There are no forward-edges in G with respect to the tree T
GATE 2018 · MCQ · 2 marksQ9 · page 137 of the book
Match Let G be a simple undirected graph. Let TD be
a depth first search tree of G. Let TB be a breadth
first search tree of G. Consider the following
statements.
(I) No edge of G is a cross edge with respect to TD.
(A cross edge in G is between two nodes neither of
which is an ancestor of the other in TD.)
(II) For every edge (u,v) of G, if u is at depth i and v
is at depth j in TB, then |i - j| = 1.
Which of the statements above must necessarily be
true?
  • (a)I only
  • (b)II only
  • (c)Both I and II
  • (d)Neither I nor II ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2016 · Set 2 · NATQ10 · page 138 of the book
Breadth First Search (BFS) is started on a binary
tree beginning from the root vertex. There is a
vertex t at a distance four from the root. If t is the
n-th vertex in this BFS traversal, then the
maximum possible value of n is  .
GATE 2016 · Set 2 · MCQ · 2 marksQ11 · page 138 of the book
In an adjacency list representation of an
undirected simple graph G = (V,E), each edge
(u,v) has two adjacency list entries: [v] in the
adjacency list of u, and [u] in the adjacency list of
v. These are called twins of each other. A twin
pointer is a pointer from an adjacency list entry to
its twin. If |E|=m and |V|=n, and the memory size
is not a constraint, what is the Time Complexity
of the most efficient algorithm to set the twin
pointer in each entry in each adjacency list?
  • (a)θ (n2)
  • (b)θ (n+m)
  • (c)θ (m2)
  • (d)θ (n4)
GATE 2015 · Set 1 · MCQ · 1 markQ12 · page 138 of the book
Let G= (V,E) be a simple undirected graph, and s
be a particular vertex in it called the source. For x
∈ V, let d (x) denote the shortest distance in G
from s to x. A breadth first search (BFS) is
performed starting at s. Let T be the resultant BFS
tree. If (u, v) is an edge of G that is not in T, then
which one of the following CANNOT be the
value of d (u) - d (v)?
  • (a)-1
  • (b)0
  • (c)1
  • (d)2
GATE 2014 · Set 3 · NAT · 1 markQ13 · page 138 of the book
Suppose depth first search is executed on the graph
below starting at some unknown vertex. Assume
that a recursive call to visit a vertex is made only
after first checking that the vertex has not been
visited earlier. Then the maximum possible
recursion depth (including the initial call) is
.
GATE 2008 · MCQQ14 · page 138 of the book
Consider the following sequence of nodes for the
undirected graph given below:
1.a b e f d g c
2.a b e f c g d
3.a d g e b c f
4.a d b c g e f
A Depth First Search (DFS) is started at node a. The
nodes are listed in the order they are first visited.
Which of the above is/are possible output(s)?
  • (a)1 and 3 only
  • (b)2 and 3 only
  • (c)2,3 and 4 only
  • (d)1,2 and 3 only
GATE 2007 · MCQ · 1 markQ15 · page 138 of the book
A depth-first search is performed on a directed
acyclic graph. Let d[u] denote the time at which
vertex u is visited for the first time and f[u] the time
at which the DFS call to the vertex u terminates.
Which of the following statements is always TRUE
for all edges (u, v) in the graph ?
  • (a)d[u] < d[v]
  • (b)d[u] < f[v]
  • (c)f[u] < f[v]
  • (d)f[u] > f[v] ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2007 · MCQ · 1 markQ16 · page 139 of the book
Consider the DAG with V = {1,2,3,4,5,6}, shown
below

Which of the following is NOT a topological
ordering?
  • (a)1 2 3 4 5 6
  • (b)1 3 2 4 5 6
  • (c)1 3 2 4 6 5
  • (d)3 2 4 1 6 5
GATE 2006 · MCQQ17 · page 139 of the book
Consider the depth-first-search of an undirected
graph with 3 vertices P, Q, and R. Let discovery
time d(u) represent the time instant when the
vertex u is first visited, and finish time f(u)
represent the time instant when the vertex u is last
visited. Given that
d(P)=5 units f(P)=12 units
d(Q)=6 units f(Q)=10 units
d(R)=14 unitf(R)=18 units
Which one of the following statements is TRUE
about the graph?
  • (a)There is only one connected component
  • (b)There are two connected components, and P and R are connected
  • (c)There are two connected components, and Q and R are connected
  • (d)There are two connected components, and P and Q are connected
GATE 2006 · MCQ · 1 markQ18 · page 139 of the book
Let T be a depth first search tree in a undirected
graph G. Vertices u and v are leaves of this tree T.
The degrees of both u and v in G are at least 2.
Which one of the following statements is true?
  • (a)There must exist a vertex w adjacent to both u and v in G
  • (b)There must exist a vertex w whose removal disconnects u and v in G
  • (c)There must be exist a cycle in G containing u and v
  • (d)There must exist a cycle in G containing u and all its neighbours in G

Searching and sorting

GATE 2026 · Set 2 · MCQ · 2 marksQ1 · page 144 of the book
Consider an array A of integers of size n. The
indices of A run from 1 to n. An algorithm is to
be designed to check whether A satisfies the
condition given below.
for all i, j {1, ..., n - 1} such that i > j,
( A[i + 1] - A[i] ) > ( A[j + 1] - A[j] )
Which one of the following gives the worst case
time complexity of the fastest algorithm that can
be designed for the problem?
  • (a)Θ(n)
  • (b)Θ(logn)
  • (c)Θ(nlogn)
  • (d)Θ(n2)
GATE 2024 · Set 2 · NATQ2 · page 144 of the book
Let A be an array containing integer values. The
distance of A is defined as the minimum number of
elements in A that must be replaced with another
integer so that the resulting array is sorted in non-
decreasing order. The distance of the array [2, 5, 3,
1, 4, 2, 6] is
.
GATE 2024 · Set 1 · MCQ · 1 markQ3 · page 144 of the book
Given an integer array of size N, we want to check
if the array is sorted (in either ascending or
descending order). An algorithm solves this
problem by making a single pass through the array
and comparing each element of the array only with
its adjacent elements. The worst-case time
complexity of this algorithm is
  • (a)Both O(n)and Ω (n)
  • (b)O(n) but not Ω (n)
  • (c)Ω (n) but not O(n)
  • (d)Neither O(n) nor Ω (n) v Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2021 · Set 2 · MCQ · 1 markQ4 · page 144 of the book
What is the worst-case number of arithmetic
operations performed by recursive binary search
on a sorted array of size n
  • (a)O(n)
  • (b)O(n2)
  • (c)O(√n )
  • (d)O(log2n)]
GATE 2017 · Set 1 · NAT · 2 marksQ5 · page 144 of the book
Let A be an array of 31 numbers consisting of
sequence of 0's followed by a sequence of 1's. The
problem is to find the smallest index i that A[i] is 1
by probing the minimum numbers of locations in A.
The worst case number of probes performed by an
optimal algorithm is   .
GATE 2013 · MCQ · 1 markQ6 · page 144 of the book
Which one of the following is the tightest upper
bound that represents the number of swaps
required to sort n numbers using selection sort?
  • (a)O(log n)
  • (b)O(n)
  • (c)O(n log n)
  • (d)O(n2)

Heaps and miscellaneous

GATE 2025 · Set 2 · MCQ · 2 marksQ1 · page 146 of the book
A meld operation on two instances of a data
structure combines them into one single instance of
the same data structure. Consider the following
data structures:
P: Unsorted doubly linked list with pointers to the
head node and tail node of the list.
Q: Min-heap implemented using an array.
R: Binary Search Tree.
Which ONE of the following options gives the
worst-case time complexities for meld operation on
instances of size n of these data structures?
  • (a)P: θ(1), Q: θ(n), R: θ(n)
  • (b)P: θ(1), Q: θ(nlogn), R: θ(n)
  • (c)P: θ(n), Q: θ(nlogn), R: θ(n2)
  • (d)P: θ(1), Q: θ(n), R: θ(nlogn)
GATE 2023 · MCQ · 2 marksQ2 · page 146 of the book
Let A be a priority queue for maintaining a set
of elements. Suppose A is implemented using a
max-heap data structure. The operation Extract-
Max(A) extracts and deletes the maximum
element from A. The operation Insert(A, key)
inserts a new element key in A. The properties
of a max-heap are preserved at the end of each
of these operations. When A contains n
elements, which one of the following statements
about the worst case running time of these two
operations is TRUE?
  • (a)Both Extract-Max(A) and Insert(A, key) run in O(1)
  • (b)Both Extract-Max(A) and Insert(A, key) run in O(log n)
  • (c)Extract-Max(A) runs in O(1) whereas Insert(A, key) runs in O(n)
  • (d)Extract-Max(A) runs in O(1) whereas Insert(A, key) runs in O(log n).
GATE 2023 · MCQQ3 · page 146 of the book
Which one of the following sequences when
stored in an array at locations A[1], ..., A[10]
forms a max-heap?
  • (a)23, 17, 10, 6, 13, 14, 1, 5, 7, 12
  • (b)23, 17, 14, 7, 13, 10, 1, 5, 6, 12
  • (c)23, 17, 14, 6, 13, 10, 1, 5, 7, 15
  • (d)23, 14, 17, 1, 10, 13, 16, 12, 7, 5
GATE 2017 · Set 1 · MCQ · 2 marksQ4 · page 146 of the book
Consider the following table:

Algorithms
Design
Paradigms
P
Kruskal
i
Divide and
Conquer
Q
Quicksort
ii
Greedy
R
Floyd-
Warshall
iii Dynamic
Programming
  • (a)P-(ii), Q-(iii), R-(i)
  • (b)P-(iii), Q-(i), R-(ii)
  • (c)P-(ii), Q-(i), R-(iii)
  • (d)P-(i), Q-(ii), R-(iii)
GATE 2017 · Set 2 · MCQ · 2 marksQ5 · page 146 of the book
Match the algorithms with their time complexities:
Algorithm
Time
complexity
P Towers of Hanoi with
n disks
i
Θ(n2 )
Q Binary search given n
sorted numbers
ii
Θ(nlog n)
R Heap sort given n
numbers at the worst
case
iii
Θ(2n )
S
Addition of two n × n
matrices
iv
Θ(logn)
ALGORITHMS

Check Out Our Gate Courses & Secure Your Dream Rank !
  • (a)P-(iii), Q-(iv), R-(i), S-(ii)
  • (b)P-(iv), Q-(iii), R-(i), S-(ii)
  • (c)P-(iii), Q-(iv), R-(ii), S-(i)
  • (d)P-(iv), Q-(iii), R-(ii), S-(i)
GATE 2015 · Set 2 · MCQ · 1 markQ6 · page 147 of the book
Given below are some algorithms, and some
algorithm design paradigms.
List - I
P. Dijkstra's Shortest Path
Q. Floyd-Warshall algorithm to compute all
pairs shortest path
R. Binary search on a sorted array
S. Backtracking search on a graph
List – II
i. Divide and Conquer
ii. Dynamic Programming
iii. Greedy design
iv. Depth-first search
v. Breadth-first search
Match the above algorithms on the left to the
corresponding design paradigm they follow.
  • (a)P-i, Q-iii, R-i, S-v.
  • (b)P-iii, Q-iii, R-i, S-v.
  • (c)P-iii, Q-ii, R-i, S-iv.
  • (d)P-iii, Q-ii, R-i, S-v.
GATE 2015 · Set 1 · MCQQ7 · page 147 of the book
Match the following:

(P) Prim's algorithm for
minimum spanning tree
(i) Backtracking
(Q) Floyd-Warshall
algorithm for all pairs
shortest paths
(ii) Greedy
method
(R) Mergesort
(iii) Dynamic
programming
(S) Hamiltonian circuit
(iv) Divide and
conquer
  • (a)P-iii, Q-ii, R-iv, S-i
  • (b)P-i, Q-ii, R-iv, S-iii
  • (c)P-ii, Q-iii, R-iv, S-i
  • (d)P-ii, Q-i, R-iii, S-iv
GATE 2015 · Set 1 · MCQ · 2 marksQ8 · page 147 of the book
An algorithm performs (logN)1/2 find operations, N
insert operations, (logN)1/2 delete operations, and
(logN)1/2 decrease-key operations on a set of data
items with keys drawn from a linearly ordered set .
For a delete operation, a pointer is provided to the
record that must be deleted. For the decrease-key
operation, a pointer is provided to the record that
has its key decreased. Which one of the following
data structures is the most suited for the algorithm
to use, if the goal is to achieve the best total
asymptotic
complexity
considering
all
the
operations?
  • (a)Unsorted array
  • (b)Min - heap
  • (c)Sorted array
  • (d)Sorted doubly linked list ALGORITHMS Check Out Our Gate Courses & Secure Your Dream Rank !
GATE 2013 · MCQ · 1 markQ9 · page 148 of the book
The number of elements that can be sorted in
Θ(log n) time using heap sort is
  • (a)θ(1)
  • (b)θ(√log n)
  • (c)θ(log n / (loglog n))
  • (d)θ(log n)
GATE 2010 · MCQQ10 · page 148 of the book
Two alternative packages A and B are available
for processing a database having 10k records.
Package A requires 0.0001n2 time units and
package B requires 10n log10 n time units to
process n records. What is the smallest value of
k for which package B will be preferred over A?
  • (a)12
  • (b)10
  • (c)6
  • (d)5