Algorithm Questions
Algorithm Questions
Algorithms
Question 1
Consider a sequence of 14 elements: A = [-5, -10, 6, 3, -1, -2, 13, 4, -9, -1, 4, 12, -3, 0]. The subsequence sum . Determine the ma
where 0 ≤ i ≤ j < 14. (Divide and conquer approach may be used)
A 19
B 39
C 29
D 09
Algorithms GATE 2019
Question 2
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 th
gets placed in the worst possible location in the rst round of partitioning (rounded o to 2 decimal places) is _____.
A 0.08
B 0.01
C 1
D 8
Algorithms GATE 2019
Question 3
A I, II and III
I, III and IV
gate.solutionsadda.in/subject/?cs=Algorithms 1/34
2/25/2020 subject – RBR
C
D I, II and IV
Algorithms GATE 2019
Question 4
There are n unsorted arrays: A1, A2, ..., An. Assume that n is odd. Each of A1, A2, ..., An contains n distinct elements. There are no common elements b
arrays. The worst-case time complexity of computing the median of the medians of A1, A2, ..., An is
A O(n)
B O(n log n)
C Ω(n2 log n)
D O(n2)
Algorithms GATE 2019
Question 5
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.
A I only
B II only
C Both I and II
D Neither I nor II
Algorithms GATE 2019
Question 6
Choose a value for x that will maximize the number of minimum weight spanning trees (MWSTs) of G. The number of MWSTs of G for th
_________.
gate.solutionsadda.in/subject/?cs=Algorithms 2/34
2/25/2020 subject – RBR
4
A
B 5
C 6
D 7
Algorithms Minimum-Spanning-Tree Gate 2018
Question 7
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 m
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 desce
packs them greedily, starting from the rst item in the ordered list. The total value of items picked by the greedy algorithm is denoted by Vgreedy.
A 16
B 17
C 18
D 19
Algorithms 0/1-Knapsack-and-fractional-knapsack Gate 2018
Question 8
The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
A
B
C
D
Algorithms Asymptotic-Complexity Gate 2017 set-01
gate.solutionsadda.in/subject/?cs=Algorithms 3/34
2/25/2020 subject – RBR
Question 9
Question 10
Let G = (V, E) be any connected undirected edge-weighted graph. The weights of the edges in E are positive and distinct. Consider the following statem
A (I) only
B (II) only
Question 11
Let A be an array of 31 numbers consisting of a sequence of 0’s followed by a sequence of 1’s. The problem is to nd the smallest index i such that A[
the minimum number of locations in A. The worst case number of probes performed by an optimal algorithm is _________.
A 5
B 6
C 7
D 8
gate.solutionsadda.in/subject/?cs=Algorithms 4/34
2/25/2020 subject – RBR
Question 12
Match the algorithms with their time complexities:
Algorithms Match-the-Following GATE 2017(set-02)
Question 13
A Θ(loglogn)
B Θ(logn)
C Θ(√n)
D Θ(n)
Algorithms Time-Complexity GATE 2017(set-02)
Question 14
gate.solutionsadda.in/subject/?cs=Algorithms 5/34
2/25/2020 subject – RBR
A Θ(n√n)
B Θ(n2 )
C Θ(n logn)
D Θ(n2 logn)
Algorithms Time-Complexity GATE 2017(set-02)
Question 15
A message is made up entirely of characters from the set X = {P, Q, R, S, T}. The table of probabilities for each of the characters is shown below:
If a message of 100 characters over X is encoded using Hu man coding, then the expected length of the encoded message in bits is __________.
A 225
B 226
C 227
D 228
Question 16
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Algorithms Sorting 2016 set-01
Question 17
Let G be a complete undirected graph on 4 vertices, having 6 edges with weights being 1, 2, 3, 4, 5, and 6. The maximum possible weight that a m
spanning tree of G can have is __________.
A 7
gate.solutionsadda.in/subject/?cs=Algorithms 6/34
2/25/2020 subject – RBR
8
B
C 9
D 10
Algorithms Minimum-Spanning-Tree 2016 set-01
Question 18
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 abo
spanning trees (MSTs) of G is/are TRUE?
A I only
B II only
C both I and II
D neither I nor II
Algorithms Minimum-Spanning-Tree 2016 set-01
Question 19
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the follow
A I and II only
C II and IV only
D I and IV only
Question 20
A Greedy paradigm.
B Divide-and-Conquer paradigm.
gate.solutionsadda.in/subject/?cs=Algorithms 7/34
2/25/2020 subject – RBR
Neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.
D
Algorithms Floyd-Warshall-Algorithm GATE 2016 set-2
Question 21
Let A1, A2, A3 and A4 be four matrices of dimensions 10 × 5, 5 × 20, 20 × 10, and 10 × 5, respectively. The minimum number of scalar multiplications req
product A1A2A3A4 using the basic matrix multiplication method is _________.
A 1500
B 1501
C 1502
D 1503
Question 22
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 co
worst case time complexity of this function is O(nα), then the least possible value (accurate upto two decimal positions) of α is _________.
A 2.3219280
B 2.3219281
C 2.3219282
D 2.3219283
Question 23
Which one of the following is the recurrence equation for the worst case time complexity of the Quicksort algorithm for sorting n(≥ 2) numbers? I
equations given in the options below, c is a constant.
A T(n) = 2T(n/2) + cn
gate.solutionsadda.in/subject/?cs=Algorithms 8/34
2/25/2020 subject – RBR
D T(n) = T(n/2) + cn
Question 24
Question 25
An algorithm performs (log N)1/2 nd operations, N insert operations, (log N)1/2 delete operations, and (log N)1/2 decrease-key operations on a set of
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 opera
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
best total asymptotic complexity considering all the operations?
A Unsorted array
B Min-heap
C Sorted array
Question 26
gate.solutionsadda.in/subject/?cs=Algorithms 9/34
2/25/2020 subject – RBR
A 69
B 70
C 71
D 72
Question 27
gate.solutionsadda.in/subject/?cs=Algorithms 10/34
2/25/2020 subject – RBR
(a, n – left_end – 1, k – left_end – 1) and (a, left_end, k)
D
Algorithms Partitioning-Algorithm GATE 2015 -(Set-2)
Question 28
Consider a typical disk that rotates at 15000 rotations per minute (RPM) and has a transfer rate of 50×106 bytes/sec. If the average seek time of the dis
average rotational delay and the controller’s transfer time is 10 times the disk transfer time, the average time (in milliseconds) to read or write a 512-
the disk is _____________.
A 6
B 6.1
C 6.2
D 6.3
Question 29
Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. Which of the following most closely approximates the m
size of a problem that can be solved in 6 minutes?
A 256
B 512
C 1024
D 2048
Algorithms Merge-Sort GATE 2015(Set-03)
Question 30
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 edg
increased by ve, the weight of a minimum spanning tree becomes __________.
A 995
B 996
C 997
D 998
Algorithms Minimum-Spanning-Tree GATE 2015(Set-03)
Question 31
There are 5 bags labeled 1 to 5. All the coins in a given bag have the same weight. Some bags have coins of weight 10 gm, others have coins of weight 1
4, 8, 16 coins respectively from bags 1 to 5. Their total weight comes out to 323 gm. Then the product of the labels of the bags having 11 gm coins is _
A 12
13
gate.solutionsadda.in/subject/?cs=Algorithms 11/34
2/25/2020 subject – RBR
B
C 14
D 15
Algorithms General GATE 2014(Set-01)
Question 32
Suppose a polynomial time algorithm is discovered that correctly computes the largest clique in a given graph. In this scenario, which one of the follo
the correct Venn diagram of the complexity classes P, NP and NP Complete (NPC)?
Algorithms P-NP GATE 2014(Set-01)
Question 33
The minimum number of comparisons required to nd the minimum and the maximum of 100 numbers is _________________.
A 148
B 149
C 150
D 151
Algorithms General GATE 2014(Set-01)
Question 34
gate.solutionsadda.in/subject/?cs=Algorithms 12/34
2/25/2020 subject – RBR
A Θ(n)
B Θ(nlog n)
C Θ(n2)
D Θ(logn)
Question 35
Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest common subsequence (not necessarily contiguous) between A
be the number of such longest common subsequences between A and B. Then x+10y = _________.
A 34
B 35
C 36
D 37
Question 36
Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be merged into a single sequence by merging tog
sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is ______.
A 358
B 359
C 360
D 361
Question 37
gate.solutionsadda.in/subject/?cs=Algorithms 13/34
2/25/2020 subject – RBR
A 6
B 7
C 8
D 9
Question 38
A SQPTRWUV
B SQPTUWRV
C SQPTWUVR
D SQPTRUWV
Question 39
gate.solutionsadda.in/subject/?cs=Algorithms 14/34
2/25/2020 subject – RBR
A 19
B 20
C 21
D 22
Question 40
You have an array of n elements. Suppose you implement quicksort by always choosing the central element of the array as the pivot. Then the tightest
for the worst case performance is
A O(n2)
B O(n log n)
C Θ(n logn)
D O(n3)
Question 41
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
and H. Suppose there are m such numbers in T. If the tightest upper bound on the time to compute the sum is O(nalogbn + mclogdn), the value of a + 1
1000d is ____.
A 110
B 111
C 112
D 113
Question 42
Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the rst 3
un lled after the rst 3 insertions?
A (97×97×97)/1003
gate.solutionsadda.in/subject/?cs=Algorithms 15/34
2/25/2020 subject – RBR
B (99×98×97)/1003
C (97×96×95)/1003
D (97×96×95)/(3!×1003)
Question 43
Question 44
gate.solutionsadda.in/subject/?cs=Algorithms 16/34
2/25/2020 subject – RBR
Question 45
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)
Algorithms Sorting Gate 2013
Question 46
Which one of the following is the tightest upper bound that represents the time complexity of inserting an object into a binary search tree of n nodes?
A O(1)
B O(log n)
O(n)
gate.solutionsadda.in/subject/?cs=Algorithms 17/34
2/25/2020 subject – RBR
C
D O(n log n)
Algorithms Sorting Gate 2013
Question 47
Consider the languages L1 = ϕ and L2 = {a}. Which one of the following represents L1L2* ∪ L1*?
A {є}
B ϕ
C a*
D {є,a}
Question 48
What is the time complexity of Bellman-Ford single-source shortest path algorithm on a complete graph of n vertices?
A Θ(n2)
B Θ(n2 log n)
C Θ(n3)
D Θ(n3 log n)
Algorithms Sorting Gate 2013
Question 49
Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected num
unordered cycles of length three?
A 1/8
B 1
C 7
D 8
Algorithms Graph-Theory Gate 2013
Question 50
A P only
gate.solutionsadda.in/subject/?cs=Algorithms 18/34
2/25/2020 subject – RBR
Q only
B
C Both P and Q
D Neither P nor Q
Algorithms Graph-Theory Gate 2013
Question 51
A P only
B P and R only
C R only
D P, Q and S only
Algorithms Graph-Theory Gate 2013
Question 52
The number of elements that can be sorted in Θ(log n) time using heap sort is
A Θ(1)
B Θ(√logn)
C Θ (logn/loglogn)
D Θ(log n)
Algorithms Sorting Gate 2013
Question 53
gate.solutionsadda.in/subject/?cs=Algorithms 19/34
2/25/2020 subject – RBR
A 3024
B 6561
C 55440
D 161051
Algorithms Pass-by-value Gate 2013
Question 54
The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequen
tree?
Question 55
A Θ(n)
B Θ(n + k)
C Θ(nk)
gate.solutionsadda.in/subject/?cs=Algorithms 20/34
2/25/2020 subject – RBR
D Θ(n2)
Algorithms Time-Complexity Gate 2013
Question 56
A NP-complete = NP
B NP-complete ∩ P = ∅
C NP-hard = NP
D P = NP-complete
Algorithms P-NP Gate 2012
Question 57
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 foll
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 Time-Complexity Gate 2012
Question 58
Consider the Quicksort algorithm. Suppose there is a procedure for nding a pivot element which splits the list into two sub-lists each of which conta
fth of the elements. Let T(n) be the number of comparisons required to sort n elements. Then
A T(n) ≤ 2T(n/5) + n
C T(n) ≤ 2T(4n/5) + n
D T(n) ≤ 2T(n/2) + n
Algorithms Sorting Gate-2008
Question 59
Q solves the subset-sum problem in polynomial time when the input is encoded in unary
A
gate.solutionsadda.in/subject/?cs=Algorithms 21/34
2/25/2020 subject – RBR
B Q solves the subset-sum problem in polynomial time when the input is encoded in binary
Algorithms P-NP Gate-2008
Question 60
A only vertex a
B only vertices a, e, f, g, h
C only vertices a, b, c, d
Algorithms Shortest-Path Gate-2008
Question 61
The numbers 1, 2, .... n are inserted in a binary search tree in some order. In the resulting tree, the right subtree of the root contains p nodes. The rst
inserted in the tree must be
A p
B p+1
C n-p
D n-p+1
Question 62
In a depth- rst traversal of a graph G with n vertices, k edges are marked as tree edges. The number of connected components in G is
A k
B k+1
gate.solutionsadda.in/subject/?cs=Algorithms 22/34
2/25/2020 subject – RBR
n-k-1
C
D n-k
Algorithms Graph-Traversal Gate 2005-IT
Question 63
A 1→ C, 2 → A, 3 → B, 4 → D
B 1→ B, 2 → D, 3 → C, 4 → A
C 1→ C, 2 → D, 3 → A, 4 → B
D 1→ B, 2 → A, 3 → C, 4 → D
Algorithms General Gate 2005-IT
Question 64
A hash table contains 10 buckets and uses linear probing to resolve collisions. The key values are integers and the hash function used is key % 10. If th
62, 123, 142 are inserted in the table, in what location would the key value 142 be inserted?
A 2
B 3
C 4
D 6
Algorithms Sorting-and-Searching Gate 2005-IT
Question 65
In a binary tree, for every node the di erence between the number of nodes in the left and right subtrees is at most 2. If the height of the tree is
minimum number of nodes in the tree is:
A 2h-1
B 2h-1 + 1
C 2h - 1
D 2h
gate.solutionsadda.in/subject/?cs=Algorithms 23/34
2/25/2020 subject – RBR
Algorithms Tree Traversals Gate 2005-IT
Question 66
A T(n) = θ(log n)
B T(n) = θ(√n)
C T(n) = θ(n)
Algorithms Recursion Gate 2005-IT
Question 67
Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G contai
Which of the following statements is always TRUE?
Algorithms Graph-Theory Gate 2005-IT
Question 68
A binary search tree contains the numbers 1, 2, 3, 4, 5, 6, 7, 8. When the tree is traversed in pre-order and the values in each node printed out, the se
obtained is 5, 3, 1, 2, 4, 6, 8, 7. If the tree is traversed in post-order, the sequence obtained would be
A 8, 7, 6, 5, 4, 3, 2, 1
B 1, 2, 3, 4, 8, 7, 6, 5
C 2, 1, 4, 3, 6, 7, 8, 5
D 2, 1, 4, 3, 7, 8, 6, 5
Question 69
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 i either j = i + 1 or j = 3i. Th
number of edges in a path in G from vertex 1 to vertex 100 is
A 4
gate.solutionsadda.in/subject/?cs=Algorithms 24/34
2/25/2020 subject – RBR
7
B
C 23
D 99
Algorithms Graph-Theory Gate 2005-IT
Question 70
A 5
B 4
C 3
D 2
Algorithms Cyclomatic-Complexity Gate 2005-IT
Question 71
An array of integers of size n can be converted into a heap by adjusting the heaps rooted at each internal node of the complete binary tree starting at
/2⌋, and doing this adjustment up to the root node (root node is at index 0) in the order ⌊(n - 1)/2⌋, ⌊(n - 3)/2⌋, ....., 0. The time required to constru
manner is
A O(log n)
B O(n)
D O(n log n)
Algorithms Binary-Trees Gate 2004-IT
Question 72
Which one of the following binary trees has its inorder and preorder traversals as BCAD and ABCD, respectively?
Question 73
B f(n) = O(h(n))
C fh(n) ≠ O(f(n))
D f(n)h(n) ≠ O(g(n)h(n))
Algorithms Time-Complexity Gate 2004-IT
Question 74
gate.solutionsadda.in/subject/?cs=Algorithms 26/34
2/25/2020 subject – RBR
A (E, G), (C, F), (F, G), (A, D), (A, B), (A, C)
B (A, D), (A, B), (A, C), (C, F), (G, E), (F, G)
C (A, B), (A, D), (D, F), (F, G), (G, E), (F, C)
D (A, D), (A, B), (D, F), (F, C), (F, G), (G, E)
Algorithms Greedy-Method Gate 2004-IT
Question 75
gate.solutionsadda.in/subject/?cs=Algorithms 27/34
2/25/2020 subject – RBR
D
Algorithms General Gate 2004-IT
Question 76
B Backtracking approach
C Heuristic search
D Heuristic search
Algorithms Sorting Gate-1995
Question 77
For merging two sorted lists of sizes m and n into a sorted list of size m+n, we required comparisons of
A O(m)
B O(n)
C O(m+n)
D O(logm+logn)
Algorithms Sorting Gate-1995
Question 78
A + B * (C+D)/ F + D * E is:
A AB + CD + *F/D + E*
B ABCD + *F/DE*++
C A *B + CD/F *DE++
D A + *BCD/F* DE++
Question 79
I. As the number of entries in a hash table increases, the number of collisions increases.
II. Recursive programs are e cient
III. The worst case complexity for Quicksort is O(n2)
IV. Binary search using a linear linked list is e cient.
gate.solutionsadda.in/subject/?cs=Algorithms 28/34
2/25/2020 subject – RBR
A I and II
B II and III
C I and IV
D I and III
Algorithms General Gate-1995
Question 80
Algorithms Recursions Gate-1994
Question 81
The recurrence relation that arises in relation with the complexity of binary search is:
A
B
C
D
Algorithms Time-Complexity Gate-1994
Question 82
A Dynamic programming
B Backtracking
D Greedy method
Algorithms Quick-Sort Gate-1994
Question 83
gate.solutionsadda.in/subject/?cs=Algorithms 29/34
2/25/2020 subject – RBR
Which one of the following statements is false?
A Optimal binary search tree construction can be performed e ciently using dynamic programming.
C Given the pre x and post x walks over a binary tree, the binary tree cannot be uniquely constructed.
Algorithms Searching Gate-1994
Question 84
A g1(n) is O(g2(n))
B g1 (n) is O(3)
D g2 (n) is O(n)
E Both A and B
Algorithms Asymptotic-Notations Gate-1994
Question 85
Algorithms Gate-1993
Question 86
Consider a simple connected graph G with n vertices and n-edges (n>2). Then, which of the following statements are true?
gate.solutionsadda.in/subject/?cs=Algorithms 30/34
2/25/2020 subject – RBR
G has no cycles.
A
B The graph obtained by removing any edge from G is not connected.
D The graph obtained by removing any two edges from G is not connected.
E Both C and D.
Algorithms Graphs Gate-1993
Question 87
A O(n)
B O(n2)
C O(n3)
D O(3n2)
E O(1.5n2)
F B, C, D and E
Algorithms Time-Complexity Gate-1993
Question 88
Complexity of Kruskal’s algorithm for nding the minimum spanning tree of an undirected graph containing n vertices and m edges if the edges are s
__________
A O(m log n)
Algorithms Krushkal's-Algorithm Gate-1992
Question 89
Following algorithm(s) can be used to sort n integers in the range [1...n3] in O(n) time
A Heapsort
B Quicksort
C Mergesort
D Radixsort
Algorithms Sorting Gate-1992
Question 90
gate.solutionsadda.in/subject/?cs=Algorithms 31/34
2/25/2020 subject – RBR
Assume that the last element of the set is used as partition element in Quicksort. If n distinct elements from the set [1…..n] are to be sorted, give an
Quicksort takes maximum time.
A n
Algorithms Quick-Sort Gate-1992
Question 91
A 7
Algorithms Sorting Gate-1991
Question 92
The weighted external path length of the binary tree in gure is _____
A 144
Algorithms Binary-Trees Gate-1991
Question 93
If the binary tree in gure is traversed in inorder, then the order in which the nodes will be visited is ______
A 4, 1, 6, 7, 3, 2, 5, 8
Algorithms Tree Traversals Gate-1991
Question 94
Match the pairs in the following questions by writing the corresponding letters only.
gate.solutionsadda.in/subject/?cs=Algorithms 32/34
2/25/2020 subject – RBR
Algorithms General Gate-1991
Question 95
Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
Kruskal’s algorithm for nding a minimum spanning tree of a weighted graph G with vertices and m edges has the time complexity of:
A O(n2)
B O(mn)
C O(m+n)
D O(m logn)
E O(m2)
F B, D and E
Algorithms Time-Complexity Gate-1991
Question 96
Choose the correct alternatives (more than one may be correct) and write the corresponding letters only:
PUSH (10), PUSH (20), POP, PUSH (10), PUSH (20), POP, POP, POP, PUSH (20), POP
Algorithms Stacks Gate-1991
gate.solutionsadda.in/subject/?cs=Algorithms 33/34
2/25/2020 subject – RBR
Question 97
Algorithms Match-the-Following Gate-1990
There are 97 questions to complete.
© 2019 Solutions Adda. All Rights Reserved. Developed by Raudra Eduservices Pvt Ltd
gate.solutionsadda.in/subject/?cs=Algorithms 34/34