Here, We will see Data Structure GATE Questions from previous year’s papers, and the Syllabus of Data Structure for GATE Exam.
Table of Contents
1. Data Structure in Gate CSE Exam
Data Structures form the backbone of the GATE Computer Science (CSE) exam, testing candidates’ ability to design efficient algorithms and solve real-world computational problems. These questions assess conceptual clarity, problem-solving speed, and application of theoretical knowledge to practical scenarios.
2. Data Structure Syllabus
The syllabus for Data Structures in GATE CSE includes:
- Basic Structures: Arrays, Stacks, Queues, Linked Lists (singly, doubly, circular), and Recursion.
- Trees: Binary Trees, Binary Search Trees (BSTs), AVL Trees, Heaps (min/max), and B/B+ Trees.
- Graphs: Representation (adjacency matrix/list), Traversals (BFS, DFS), Shortest Path Algorithms (Dijkstra, Bellman-Ford), and Minimum Spanning Trees (Prim, Kruskal).
- Hashing: Collision resolution techniques (chaining, open addressing) and hash functions.
- Advanced Topics: Time and space complexity analysis (Big-O notation), Dynamic Programming, and Greedy Algorithms.
Data Structure Gate Questions
1. In a binary tree with n nodes, every node has an odd number of descendants. Every node is considered to be its own descendant. What is the number of nodes in the tree that have exactly one child?
- 0
- 1
- (n − 1)/2
- n – 1
Answer
0
[2010]
2. The following C function takes a singly-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.
typedef struct node { int value; struct node * next; } Node; Node * move_to_front(Node * head) { Node * p, * q; if ((head = = NULL || (head -> next = = NULL)) return head; q = NULL; p = head; while (p -> next != NULL) { q = p; p = p -> next; } return head; }
Choose the correct alternative to replace the blank line.
- q = NULL; p->next = head; head = p;
- q->next = NULL; head = p; p->next =head;
- head = p; p->next = q; q->next = NULL;
- q->next = NULL; p->next = head; head = p;
Answer
q->next = NULL; p->next = head; head = p;
[2010]
3. Consider two binary operators ‘↑’ and ‘↓’ with the precedence of operator ↓ being lower than that of the operator ↑. Operator ↑ is right associative while operator ↓ is left associative. Which one of the following represents the parse tree for expression (7 ↓ 3 ↑ 4 ↑ 3 ↓ 2)?
- (A)
- (B)
- (C)
- (D)
Answer
(B)
[2011]
4. The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode below is invoked as “height(root)” to compute the height of a binary tree rooted at the tree pointer “root”.
int height(treeptr n) { if (n = = NULL) return– 1; if (n→ left == NULL) if (n→ right == NULL) return 0; else return B1; //Box 1 else { h1 = height(n→ left); if (n→ right = = NULL) return (1 + h1); else { h2 = height(n→ right); return B2; //Box 2 } } }
The appropriate expressions for the two boxes B1 and B2 are
- B1 : (1+ height(n→right))
B2 : (1+max(h1,h2)) - B1 : (height(n→right)
B2 : (1+max(h1,h2)) - B1 : height(n→right)
B2 : max(h1,h2) - B1 : (1+height(n→right)
B2 : max(h1,h2)
Answer
B1 : (1+ height(n→right))
B2 : (1+max(h1,h2))
[2012]
5. Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of expression represented by the tree is ––––––––.
- 0
- 1
- 4
- 6
Answer
6
[2014]
6. Consider the pseudocode given below. The function Dosomething() takes as argument a pointer to the root of an arbitrary tree represented by the leftMostChildrightSibling representation. Each node of the tree is of type treenode.
type def struct treeNode * treeptr; struct treeNode { treeptr leftMostChild, rightSibling; }; int Dosomething(treeptr tree { int value = 0; if (tree! = NULL) { if (tree– > leftMostChild = = NULL) value = 1; else value = Dosomething(tree– > leftMostChild); value = value + Dosomething(tree -> right Sibling); } return (value); }
When the pointer to the root of a tree is passed as the argument to DoSomething, the value returned by the function corresponds to the
- Number of internal nodes in the tree
- Height of the tree
- Number of nodes without a right sibling in the tree
- Number of leaf nodes in the tree
Answer
Number of leaf nodes in the tree
[2014]
7. The height of a tree is the length of the longest rootto-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 5 are
- 63 and 6, respectively
- 64 and 5, respectively
- 32 and 6, respectively
- 31 and 5, respectively
Answer
63 and 6, respectively
[2015]
8. Which of the following is/are correct inorder traversal sequence(s) of binary search tree(s)?
I. 3, 5, 7, 8, 15, 19, 25
II. 5, 8, 9, 12, 10, 15, 25
III. 2, 7, 10, 8, 14, 16, 20
IV. 4, 6, 7, 9, 18, 20, 25
- I and IV only
- II and III only
- II and IV only
- II only
Answer
I and IV only
[2015]
9. Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8,
Array Index | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
Value | 40 | 30 | 20 | 10 | 15 | 16 | 17 | 8 | 4 |
Now consider that a value 35 is inserted into this heap. After insertion, the new heap is
- 40, 30, 20, 10, 15, 16, 17, 8, 4, 35
- 40, 35, 20, 10, 30, 16, 17, 8, 4, 15
- 40, 30, 20, 10, 35, 16, 17, 8, 4, 15
- 40, 35, 20, 10, 15, 16, 17, 8, 4, 30
Answer
40, 35, 20, 10, 30, 16, 17, 8, 4, 15
[2015]
10. A binary tree T has 20 leaves. The number of nodes in T having two children is __________ .
- 20
- 19
- 18
- 16
Answer
19
[2015]
11. Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that have exactly two children are ___________.
- 200
- 198
- 190
- 199
Answer
199
[2015]
12. While inserting the elements 71, 65, 84, 69, 67, 83 in an empty binary search tree (BST) in the sequence shown, the element in the lowest level is
- 65
- 67
- 69
- 83
Answer
67
[2015]
13. Consider the following New–order strategy for traversing a binary tree:
• Visit the root;
• Visit the right subtree using New – order;
• Visit the left subtree using New – order;
The New – order traversal of the expression tree corresponding to the reverse polish expression 3 4 * 5 – 2 ∧ 6 7 * 1 + – is given by:
- + – 1 6 7 * 2 ^ 5 – 3 4 *
- – + 1 * 6 7 ^ 2 – 5 * 3 4
- – + 1 * 7 6 ^ 2 – 5 * 4 3
- 1 7 6 * + 2 5 4 3 * – ^ –
Answer
– + 1 * 7 6 ^ 2 – 5 * 4 3
[2016]
14. Let T be a binary search tree with 15 nodes. The minimum and maximum possible heights of T are:
Note: The height of a tree with a single node is 0.
- 4 and 15 respectively
- 3 and 14 respectively
- 4 and 14 respectively
- 3 and 15 respectively
Answer
3 and 14 respectively
[2017]
15. The pre-order traversal of a binary search tree is given by 12,8,6,2,7,9,10,16,15,19,17,20. Then the postorder traversal of this tree is:
- 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20
- 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12
- 7, 2, 6, 8, 9,10, 20, 17, 19, 15, 16, 12
- 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12
Answer
2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12
[2017]
16. The postorder traversal of a binary tree is 8, 9, 6, 7, 4, 5, 2, 3, 1. The inorder traversal of the same tree is 8, 6, 9, 4, 7, 2, 5, 1, 3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is ________.
- 8
- 4
- 6
- 1
Answer
4
[2018]
17. The number of possible min-heaps containing each value from {1, 2, 3, 4, 5, 6, 7} exactly once is ________.
- 20
- 36
- 80
- 336
Answer
80
[2018]
18. An abstract data type (ADT) is
- same as an abstract class.
- a data type that cannot be instantiated.
- a data type for which only the operations defined on it can be used, but none else.
- All of the above
Answer
a data type for which only the operations defined on it can be used, but none else.
[2005]
19. An implementation of a queue Q, using two stacks S1 and S2, is given below:
void insert(Q, x) { push(S1, x); } void delete(Q) { if (stack - empty(S2)) then if (stack - empty(S1)) then { print(“Q is empty”); return; } else while (!(stack - empty(S1))) { x = pop(S1); push(S2, x); } x = pop(S2); }
Let n insert and m (“n) delete operations be performed in an arbitrary order on an empty queue Q. Let x and y be the number of push and pop operations performed respectively in the process. Which one of the following is true for all m and n?
- n + m ” x < 2n and 2m ” y n + m
- n + m ” x < 2n and 2m ” y 2n
- 2m ” x < 2n and 2m ” y n + m
- 2m ” x < 2n and 2m ” y 2n
Answer
[2006]
20. The following postfix expression with single-digit operands is evaluated using a stack:
8 2 3 ∧ / 2 3 ∗ + 5 1 ∗ –
Note that ∧ is the exponentiation operator. The top two elements of the stack after the first ∗ is evaluated are:
- 6 and 1
- 5 and 7
- 3 and 2
- 1 and 5
Answer
6 and 1
[2007]
21. The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1, 2, 3, 4, 5, 6, 7 in the given order. What will be the contents of the list after the function completes execution?
struct node { int value; struct node * next; }; void rearrange(struct node * list) { struct node * p, * q; int temp; if (!list || !list -> next) return; p = list; q = list -> next; while (q) { temp = p -> value; p -> value = q -> value; q -> value = temp; p = q→ next; q = p ? p -> next : 0; } }
- 1, 2, 3, 4, 5, 6, 7
- 2, 1, 4, 3, 6, 5, 7
- 1, 3, 2, 5, 4, 7, 6
- 2, 3, 4, 5, 6, 7, 1
Answer
2, 1, 4, 3, 6, 5, 7
[2008]
22. Suppose a circular queue of capacity (n – 1) elements is implemented with an array of n elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are
- Full: (REAR + 1) mod n = = FRONT
Empty: REAR = = FRONT - Full: (REAR + 1) mod n = = FRONT
Empty: (FRONT + 1) mod n = = REAR - Full: REAR = = FRONT
Empty: (REAR + 1) mod n = = FRONT - Full: (FRONT + 1) mod n = = REAR
Empty: REAR = = FRONT
Answer
Full: (REAR + 1) mod n = = FRONT
Empty: REAR = = FRONT
[2012]
23. Consider the C program below
#include <stdio.h> int * A, stkTop; int stkFunc(int opcode, int val) { static int size = 0, stkTop = 0; switch (opcode) { case -1: size = val; break; case 0: if (stkTop < size) A[stkTop++] = val; break; default: if (stkTop) return A[stkTop]; } return -1; } int main() { int B[20]; A = B; stkTop = -1; stkFunc(-1, 10); stkFunc(0, 5); stkFunc(0, 10); printf(“ % d\ n”, stkFunc(1, 0) + stkFunc(1, 0)); }
The value printed by the above program is ___________ .
- 5
- 10
- 15
- 20
Answer
15
[2015]
24. The result of evaluating the postfix expression 10 5 + 60 6/* 8 – is
- 284
- 213
- 142
- 71
Answer
142
[2015]
25. Let Q denote a queue containing sixteen numbers and S be an empty stack. Head (Q) returns the element at the head of the queue Q without removing it from Q. Similarly Top(S) returns the element at the top of S without removing it from S. Consider the algorithm given below.
while Q is not Empty do if S is Empty OR Top(S)≤ Head(Q) then x: = Dequeue(Q) Push(S, x); else x: = Pop(S); enqueue(Q, x); end end
The maximum possible number of iterations of the while loop in the algorithm is ___________ .
- 64
- 128
- 256
- 518
Answer
256
[2016]
26. The attributes of three arithmetic operators in some programming language are given below.
Operator | Precedence | Associativity | Arity |
+ | High | Left | Binary |
– | Medium | Right | Binary |
* | Low | Left | Binary |
The value of the expression 2 – 5 + 1 – 7 * 3 in this language is _______.
- 6
- 9
- 13
- 12
Answer
9
[2016]
27. A circular queue has been implemented using a singly linked list where each node consists of a value and a single pointer pointing to the next node. We maintain exactly two external pointers FRONT and REAR pointing to the front node and the rear node of the queue, respectively. Which of the following statements is/are CORRECT for such a circular queue, so that insertion and deletion operations can be performed in O (1) time?
I. Next pointer of front node points to the rear node.
II. Next pointer of rear node points to the front node.
- I only
- II only
- Both I and II
- Neither I nor II
Answer
II only
[2017]
28. Consider the following program in C language:
#include < stdio.h> main() { int i; int * pi = & i; scanf(“ % d”, pi); printf(“ % d\ n”, i + 5); }
Which one of the following statement is TRUE?
- Compilation fails
- Execution results in a run-time error
- On execution, the value printed is 5 more than the address of variable i.
- On execution, the value printed is 5 more than the integer value entered.
Answer
On execution, the value printed is 5 more than the integer value entered.
[2014]
29. Consider the following C function in which size is the number of elements in the array E:
int MyX(int * E, unsigned int size) { int Y = 0; int Z; int i, j, k; for (i = 0; i < size; i++) Y = Y + E[i]; for (i = 0; i < size; i++) for (j = 1; j < size; j++) { Z = 0; for (k = i; k < = j; k++) Z = Z + E[k]; if (Z > Y) Y = Z; } return Y; }
The value returned by the function My X is the
- maximum possible sum of elements in any sub -array of array E.
- maximum element in any sub-array of array E.
- sum of the maximum elements in all possible sub-arrays of array E.
- the sum of all the elements in the array E.
Answer
maximum possible sum of elements in any sub -array of array E.
[2014]
30. The output of the following C program is _________
void f1(int a, int b) { int c; c = a; a = b; b = c; } void f2(int * a, int * b) { int c; c = * a;* a = * b;* b = c; } int main() { int a = 4, b = 5, c = 6; f1(a, b); f2( & b, & c); printf(“ % d”, c - a - b); }
- -6
- -5
- 5
- 6
Answer
-5
[2015]
31. What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory.
int main() { unsigned int x[4][3] = { {1,2,3}, {4,5,6}, {7,8,9}, {10,11,12} }; printf(“ % u, % u, % u”, x + 3, *(x + 3), *(x + 2) + 3); }
- 2036, 2036, 2036
- 2012, 4, 2204
- 2036, 10, 10
- 2012, 4, 6
Answer
2036, 2036, 2036
[2015]
32. Consider the following function written in the C programming language.
void foo(char * a { if ( * a && a != ‘‘) { foo(a + 1); putchar(a); } }
The output of the above function on input “ABCD EFGH” is
- ABCD EFGH
- ABCD
- HGFE DCBA
- DCBA
Answer
DCBA
[2015]
33. Consider the following C program segment.
#include <stdio.h> int main() { char s1[7] = “1234”, * p; p = s1 + 2; * p = ‘0’; printf(“ % s”, s1); }
What will be printed by the program?
- 12
- 120400
- 1204
- 1034
Answer
1204
[2015]
34. Consider the following C program
#include <stdio.h> int main() { static int a[] = { 10, 20, 30, 40, 50 }; static int * p[] = { a, a + 3, a + 4, a + 1, a + 2 }; int ** ptr = p; ptr++; printf(“ % d % d”, ptr - p, ** ptr); }
- 140
- 130
- 150
- 155
Answer
140
[2015]
35. Consider the following C program.
void f(int, short); void main() { int i = 100; short s = 12; short * p = & s; _____; // call to f( ) }
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
- f (s,*s)
- i = f (i,s)
- f (i,*s)
- f (i,*p)
Answer
f (i,*p)
[2016]
36. Consider the following C program.
# include < stdio.h > void mystery(int * ptra, int * ptrb) { int * temp; temp = ptrb; ptrb = ptra; ptra = temp; } int main() { int a = 2016, b = 0, c = 4, d = 42; mystery( & a, & b); if (a < c) mystery( & c, & a); mystery( & a, & d); printf(“ % d\ n”, a) }
The output of the program is ________ .
- 2016
- 0
- 4
- 42
Answer
2016
[2016]
37. The following function computes the maximum value contained in an integer array p [ ] of size n (n > = 1).
int max(int * p, int n) { int a = 0, b = n– 1; while (_______) { if (p[a] < = p[b]) { a = a + 1; } else { b = b– 1; } } return p[a]; }
The missing loop condition is
- a ! = n
- b ! = 0
- b > (a +1)
- b ! = a
Answer
b ! = a
[2016]
38. The value printed by the following program is ________ .
void f(int * p, int m) { m = m + 5; * p = * p + m; return; } void main() { int i = 5, j = 10; f( & i, j); print f(“ % d”, i + j); }
- 10
- 20
- 30
- 40
Answer
30
[2016]
39. Consider the following program:
int f(int * p, int n) { if (n < = 1) return 0; else return max(f(p + 1, n– 1), p[0]– p[1]); } int main() { int a[] = { 3, 5, 2, 6, 4 }; printf(“ % d”, f(a, 5)); } Note: max(x, y) returns the maximum of x and y.
The value printed by this program is __________.
- 3
- 5
- 6
- 2
Answer
3
[2016]
40. Consider the following C code:
#include <stdio.h> int * assignval(int * x, int val) { * x = val; return x; } void main() { int * x = malloc(sizeof(int)); if (NULL == x) return; x = assignval(x, 0); if (x) { x = (int * ) malloc(sizeof(int)); if (NULL == x) return; x = assignval(x, 10); } printf(“ % d\ n”, * x); free(x); }
The code suffers from which one of the following problems:
- compiler error as the return of malloc is not typecast appropriately
- compiler error because the comparison should be made as x == NULL and not as shown
- compiles successfully but execution may result in dangling pointer
- compiles successfully but execution may result in memory leak
Answer
compiles successfully but execution may result in memory leak
[2017]
41. Consider the following C program.
#include <stdio.h> #include <string.h> void printlength(char * s, char * t) { unsigned int c = 0; int len = ((strlen(s)− strlen(t)) > c) ? strlen(s) : strlen(t); printf(“ % d\ n”, len); } void main() { char * x = “abc”; char * y = “defgh”; print length(x, y); }
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int. the output of the program is ___________.
- 1
- 2
- 3
- 4
Answer
3
[2017]
42. Given the following binary number in 32-bit (single precision) IEEE-754 format:
00111110011011010000000000000000
The decimal value closest to this floating-point number is
- 1.45 × 101
- 1.45 × 10−1
- 2.27 × 10−1
- 2.27 × 101
Answer
2.27 × 10−1
[2017]
43. Match the following:
(P) static char var; | (i) Sequence of memory locations to store addresses |
(Q) m = malloc (10);m = NULL; | (ii) A variable located in data section of memory |
(R) char *ptr [10]; | (iii) Request to allocate a CPU register to store data |
(S) register int var1; | (iv) A lost memory which cannot be freed |
- P → (ii), Q → (iv), R → (i), S → (iii)
- P → (ii), Q → (i), R → (iv), S → (iii)
- P → (ii), Q → (iv), R → (iii), S → (i)
- P → (iii), Q → (iv), R → (i), S → (ii)
Answer
P → (ii), Q → (iv), R → (i), S → (iii)
[2017]
44. Consider the following function implemented in C:
void printxy(int x, int y) { int ptr; x = 0; ptr = & x; y = ptr; ptr = 1; printf(“ % d, % d” x, y); }
The output of invoking printxy (1, 1) is
- 0, 0
- 0, 1
- 1, 0
- 1, 1
Answer
1, 0
[2017]
45. Consider the following snippet of a C program. Assume that swap (&x, &y) exchanges the contents of x and y.
int main() { int array[] = { 3, 5, 1, 4, 6, 2 }; int done = 0; int i; while (done == 0) { done = 1; for (i = 0; i <= 4; i++) { if (array[i] < array[i + 1]) { swap( & array[i], & array[i + 1]); done = 0; } } for (i = 5; i >= l; i--) { if (array[i] > array[i− l]) { swap( & array[i], & array[i− 1]); done = 0; } } for (i = 5; i >= l; i--) { if (array[i] > array[i− l]) { swap( & array[i], & array[i− 1]); done = 0; } } } printf { “ % d”, array[3]); }
The output of the program is ________.
- 5
- 4
- 3
- 2
Answer
3
[2017]
46. Consider the following C Program.
#include <stdio.h> #include <string.h> int main() { char * c = “GATECSIT2017”; char * p = c; printf { “ % d”, (int) strlen(c + 2[p] - 6[p] - 1)); return 0; }
The output of the program is _________.
- 2
- 0
- 7
- 1
Answer
2
[2017]
47. Consider the following C program.
#include <stdio.h> struct Ournode { char x, y, z; }; Int main() { struct Ournode p = { ‘ 1’, ‘0’, ‘a’ + 2 }; struct Ournode * q = & p; printf(“ % c, % c”, *((char * ) q + 1), ((char * ) q + 2)); return 0; }
The output of this program is:
- 0, c
- 0, a+2
- ‘0’, ‘a+2’
- ‘0’, ‘c’
Answer
0, c
[2018]
48. Consider the following C program:
#include <stdio.h> void fun1(char * s1, char * s2) { char * tmp; tmp = s1; s1 = s2; s2 = tmp; } void fun2(char ** s1, char ** s2) { char * tmp; tmp = * s1; * s1 = * s2; * s2 = tmp; } int main() { char * str1 = “Hi”, * str2 = “Bye”; fun1(str1, str2); printf(“ % s % s“, str1, str2); fun2( & str1, & str2); printf(“ % s % s”, str1, str2); return 0; }
The output of the program above is:
- Hi Bye Bye Hi
- Hi Bye Hi Bye
- Bye Hi Hi Bye
- Bye Hi Bye Hi
Answer
Hi Bye Bye Hi
[2018]
49. The median of n elements can be found in O(n) time. Which one of the following is correct about the complexity of quick sort, in which median is selected as pivot?
- θ(n)
- θ(n log n)
- θ(n2)
- θ(n3)
Answer
θ(n log n)
[2006]
50. Given two arrays of numbers a1… an and b1… bn where each number is 0 or 1, the fastest algorithm to find the largest span (i, j) such that ai + ai+ 1 + … + aj = bi + bi +1 + … + bj, or report that there is not such span.
- Takes O(3n) and Ω(2n) time if hashing is permitted
- Takes O(n3) and Ω(n2.5) time in the key comparison model
- Takes Θ(n) time and space
- Takes O(√n) time only if the sum of the 2n elements is an even number
Answer
Takes Θ(n) time and space
[2006]
51. Consider the following segment of C-code:
int j, n; j = 1; while (j <= n) j = j * 2;
The number of comparisons made in the execution of the loop for any n > 0 is:
- log2n +1
- n
- log2 + n
- log2n +1
Answer
log2n +1
[2007]
52. 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?
- Θ(log)2n
- Ω(n)
- Θ(log2log2n)
- Θ(√n)
Answer
Θ(log2log2n)
[2007]
53. What is the time complexity of the following recursive function:
int DoSomething(int n) { if (n <= 2) return 1; else return (DoSomething(floor(sqrt(n))) + n); }
- Θ(n2)
- Θ(nlog2n)
- Θ(log2n)
- Θ(log2log2n)
Answer
Θ(nlog2n)
[2007]
54. An array of n numbers is given, where n is an even number. The maximum as well as the minimum of these n numbers needs to be determined. Which of the following is TRUE about the number of comparisons needed?
- At least 2n – c comparisons, for some constant c, are needed.
- At most 1.5n − 2 comparisons are needed.
- At least nlog2n comparisons are needed.
- None of the above.
Answer
At most 1.5n − 2 comparisons are needed.
[2007]
55. Consider the following C code segment:
int IsPrime(n) { int i, n; for (i = 2; i <= sqrt(n); i++) if (n % i = = 0) { printf(“Not Prime\ n”); 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?
- T(n) = O(√n) and T(n) = Ω(√n)
- T(n) = O(√n) and T(n) = Ω(1)
- T(n) = O(N) and T(n) = Ω(√n)
- None of the above
Answer
T(n) = O(√n) and T(n) = Ω(1)
[2007]
56. The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity
- Θ(n)
- Θ(m)
- Θ(m + n)
- Θ(mn)
Answer
Θ(m + n)
[2008]
57. Consider the following functions:
f(n) = 2n
g(n) = n!
h(n) = nlogn
Which of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true?
- f(n) = O(g(n)); g(n) = O(h(n))
- f(n) = W(g(n)); g(n) = O(h(n))
- g(n) = O(f(n)); h(n) = O(f(n))
- h(n) = O(f(n)); g(n) = W(f(n))
Answer
h(n) = O(f(n)); g(n) = W(f(n))
[2008]
58. The minimum number of comparisons required to determine if an integer appears more than n/2 times in a sorted array of n integers is
- Θ(n)
- Θ(log n)
- Θ(log * n)
- Θ(1)
Answer
Θ(n)
[2008]
59. We have a binary heap on n elements and wish to insert n more elements (not necessarily one after another) into this heap. The total time required for this is
- Θ(log n)
- Θ(n)
- Θ(n log n)
- Θ(n2)
Answer
Θ(n)
[2008]
60. The running time of an algorithm is represented by the following recurrence relation:
T(n) = {n, n ≤ 3
{T(n/3) = cn, otherwise
Which one of the following represents the time complexity of the algorithm?
- θ(n)
- θ(n log n)
- θ(n2)
- θ(n2 log n)
Answer
θ(n)
[2009]
61. Two alternative packages A and B are available for processing a database having 10k records. Package Arequires 0.0001 n2 time units and package B requires 10n log10n time units to process n records. What is the smallest value of k for which package B will be preferred over A?
- 12
- 10
- 6
- 5
Answer
6
[2010]
62. 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 in the array Initialize Ln-1 = 1, For all i such that 0 ≤ i ≤ n – 2
Li = {1+Li+1, if A[i] < A[i+1],
{0, otherwise
Finally the length of the longest monotonically increasing sequence is Max (L0, L1,…Ln–1)
Which of the following statements is TRUE?
- The algorithm uses dynamic programming paradigm.
- The algorithm has a linear complexity and uses branch and bound paradigm.
- The algorithm has a non-linear polynomial complexity and uses branch and bound paradigm.
- The algorithm uses divide and conquer paradigm.
Answer
The algorithm uses dynamic programming paradigm.
[2011]
63. Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?
f1(n) = 2n
f2(n) = n3/2
f3(n) = n log2n
f4(n) = nlog2n
- f3, f2, f4, f1
- f3, f2, f1, f4
- f2, f3, f1, f4
- f2, f3, f4, f1
Answer
f3, f2, f4, f1
[2011]
64. Let W(n) and A(n) denote respectively, the worstcase and average-case running time of an algorithm executed on input of size n. Which of the following is ALWAYS TRUE?
- A(n) = Ω(W(n))
- A(n) = Θ(W(n))
- A(n) = O(W(n))
- A(n) = o(W(n))
Answer
A(n) = O(W(n))
[2012]
65. The recurrence relation capturing the optimal execution time of the Towers of Hanoi problem with n discs is
- T(n) = 2T(n – 2) + 2
- T(n) = 2T(n – 1) + n
- T(n) = 2T(n/2) + 1
- T(n) = 2T(n – 1) + 1
Answer
T(n) = 2T(n – 1) + 1
[2012]
66. 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
- O(n log n)
- O(n2log n)
- O(n2 + log n)
- O(n2)
Answer
O(n2log n)
[2012]
67. Consider the following function:
int unknown(int n) { int i, j, k = 0; for (i = n / 2; i < = n; i++) for (j = 2; j < = n; j = j * 2) k = k + n / 2; return (k); }
The return value of the function is
- Θ(n2)
- Θ(n2log n)
- Θ(n3)
- Θ(n3log n)
Answer
Θ(n2log n)
[2013]
68. The number of elements that can be sorted in Θ(log n) time using heap sort is
- Θ(1)
- Θ(√log n)
- Θ((logN)/(log logn))
- Θ(log n)
Answer
Θ((logN)/(log logn))
[2013]
69. Which one of the following correctly determines the solution of the recurrence relation with T(1) = 1, T(n) = 2T(n/2) + log n ?
- θ(n)
- θ(n log n)
- θ(n2)
- θ(log n)
Answer
θ(n)
[2014]
70. An algorithm performs (logN)1/2 find operations, Ninsert operations, (logN)1/2 delete operations, and (log N)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?
- Unsorted array
- Min-heap
- Sorted array
- Sorted doubly linked list
Answer
Unsorted array
[2015]
71. Consider the following C function.
int fun1(int n) { int i, j, k, p, q = 0; for (i = 1; i1; 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?
- n3
- n(logn)2
- nlog n
- nlog(logn)
Answer
nlog(logn)
[2015]
72. An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is
- θ(n log n)
- θ(n)
- θ(log n)
- θ(1)
Answer
θ(1)
[2015]
73. 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
- Ω(log n)
- Ω(n)
- Ω(n log n)
- Ω(n2)
Answer
Ω(log n)
[2015]
74. Consider the equality i in n∑i=0 i3= and the following choices for X
1. θ(n4)
2. θ(n5)
3. O(n5)
4. Ω(n3)
The equality above remains correct if X is replaced by
- Only 1
- Only 2
- 1 or 3 or 4 but not 2
- 2 or 3 or 4 but not 1
Answer
1 or 3 or 4 but not 2
[2015]
75. Consider the following array of elements
<89, 19, 50, 17, 12, 15, 2, 5, 7, 11, 6, 9, 100>
The minimum number of interchanges needed to convert it into a max-heap is
- 4
- 5
- 2
- 3
Answer
3
[2015]
76. 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?
I. f(n) = O(g(n))
II. f(n) = Ω(g(n))
- Only I
- Only II
- Both I and II
- Neither I nor II
Answer
Neither I nor II
[2015]
77. A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efficiently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)?
- Both operations can be performed in O(1) time.
- At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω (n).
- The worst case time complexity for both operations will be Ω (n).
- Worst case time complexity for both operations will be Ω (logn).
Answer
Both operations can be performed in O(1) time.
[2016]
78. Consider a carry look-ahead adder for adding two n-bit integers, built using gates of fan – in at most two. The time to perform addition using this adder is
- Θ(1)
- Θ(log(n))
- Θ(√n)
- Θ(n)
Answer
Θ(log(n))
[2016]
79. N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed. An algorithm performs the following operations on the list in this order: Θ(N) delete, O(logN) insert, O(log N) find, and Θ(N) decrease – key. What is the time complexity of all these operations put together?
- O(log2N)
- O(N)
- O(N2)
- Θ(N2logN)
Answer
O(N2)
[2016]
80. 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?
- Θ(n2)
- Θ(n + m)
- Θ(m2)
- Θ(n4)
Answer
Θ(n + m)
[2016]
81. Consider the following functions from positive integers to real numbers:
10, √n, n, log2n, 100/n
The CORRECT arrangement of the above functions in increasing order of asymptotic complexity is:
- log2n, 100/n, 10, √n, n
- 100/n, 10, log2n, √n, n
- 10, 100/n, √n, log2n, n
- 100/n, log2n, 10, √n, n
Answer
100/n, 10, log2n, √n, n
[2017]
82. Consider the recurrence function( )
T(n) = {2T(√n) + 1, n > 2
{2 , 0 < n ≤ 2
Then T(n) in terms of Θ notation is
- Θ(log log n)
- Θ(log n)
- Θ(√n)
- Θ(n)
Answer
Θ(log n)
[2017]
83. Consider the following C function.
int fun(int n) { int i, j; for (i = 1; i <= n; i++) { for (j = l; j < n; j += i) { printf { “ % d % d”, i, j); } } }
Time complexity of fun in terms of Θ notation is
- Θ(n√n)
- Θ(n2)
- Θ(n log n)
- Θ(n2 log n)
Answer
Θ(n log n)
[2017]
84. A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let n denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail. Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?
- θ(1), θ(1)
- θ(1), θ(n)
- θ(n), θ(1)
- θ(n), θ(n)
Answer
θ(1), θ(n)
[2018]
85. Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun(unsigned long int n) { unsigned long int i, j = 0, sum = 0; for (i = n; i > 1. i = i / 2) j++; for (; j > 1; j = j / 2) sum++; return (sum); }
The value returned when we call fun with the input 240 is:
- 4
- 5
- 6
- 40
Answer
5
[2018]
86. What is the number of swaps required to sort n elements using selection sort, in the worst case?
- θ(n)
- θ(n log n)
- θ(n2)
- θ(n2 log n)
Answer
θ(n)
[2009]
87. Which one of the following is the tightest upper bound that represents the number of swaps required to sort n numbers using selection sort?
- O(log n)
- O(n)
- O(n log n)
- O(n2)
Answer
O(n)
[2013]
88. Let P be 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?
- t1 = 5
- t1 < t2
- t1 > t2
- t1 = t2
Answer
t1 > t2
[2014]
89. The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is ________.
- 153
- 148
- 176
- 194
Answer
148
[2014]
90. Suppose P, Q, R, S, T are sorted sequences having lengths 20, 24, 30, 35, 50 respectively. They are to be two sequences at a time. The number of comparisons that will be needed in the worst case by the optimal algorithm for doing this is _______.
- 256
- 346
- 358
- 446
Answer
358
[2014]
91. 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
- O(n2)
- O(n log n)
- θ(n log n)
- O(n3)
Answer
O(n2)
[2014]
92. What are the worst-case complexities of insertion and deletion of a key in a binary search tree?
- θ(log n) for both insertion and deletion
- θ(n) for both insertion and deletion
- θ(n) for insertion and θ(log n) for deletion
- θ(log n) for insertion and θ(n) for deletion
Answer
θ(n) for both insertion and deletion
[2015]
93. The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
- Θ(n log n), Θ(n log n),and Θ(n2)
- Θ(n2), Θ(n2),and Θ(n log n)
- Θ(n2), Θ(n log n),and Θ(n log n)
- Θ(n2), Θ(n log n),and Θ(n2)
Answer
Θ(n2), Θ(n log n),and Θ(n2)
[2016]
94. An operator delete(i) for a binary heap data structure is to be designed to delete the item in the i-th node. Assume that the heap is implemented in an array and i refers to the i-th index of the array. If the heap tree has depth d (number of edges on the path from the root to the farthest leaf), then what is the time complexity to re-fix the heap efficiently after the removal of the element?
- O(1)
- O(d) but not O(1)
- O(2d) but not O(d)
- O(d2d) but not O(2d)
Answer
O(d) but not O(1)
[2016]
95. 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. Quicksort runs in Θ(n2) time
II. Bubblesort runs in Θ(n2) time
III. Mergesort runs in Θ(n) time
IV. Insertion sort runs in Θ(n) time
- I and II only
- I and III only
- II and IV only
- I and IV only
Answer
I and IV only
[2016]
96. A complete binary min – heap is made by including each integer in [1,1023] exactly once. The depth of a node in the heap is the length of the path from the root of the heap to that node. Thus, the root is depth 0. The maximum depth at which integer 9 can appear is __ .
- 4
- 8
- 12
- 16
Answer
8
[2016]
97. 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?
- O(1)
- O(log n)
- O(n)
- O(n log n)
Answer
O(n)
[2013]
98. Consider a rooted n node binary tree represented using pointers. The best upper bound on the time required to determine the number of sub-trees having exactly 4 nodes is O (na logb n). The value of a + 10bis _
- 0
- 1
- 2
- 4
Answer
1
[2014]
99. 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.
- T(n) = 2T(n/2) + cn
- T(n) = T(n – 1) + T(1) + cn
- T(n) = 2T(n – 1) + cn
- T(n) = T(n/2) + cn
Answer
T(n) = T(n – 1) + T(1) + cn
[2015]
100. 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 orall 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.
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 argument lists are respectively
- (a, left_end, k) and (a+left_end+1, n-left_end-1, k-left_end-1)
- (a, left_end, k) and (a, n-left_end-1, k-left_end-1)
- (a+left_end+1, n-left_end-1, k-left_end-1) and (a, left_end, k)
- (a, n-left_end-1, k-left_end-1) and (a, left_end, k)
Answer
(a, left_end, k) and (a+left_end+1, n-left_end-1, k-left_end-1)
[2015]
101. 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 maximum input size of a problem that can be solved in 6 minutes?
- 256
- 512
- 1024
- 2048
Answer
512
[2015]
102. 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 (na), then the least possible value (accurate up to two decimal positions) of α is __.
- 1.2 to 1.4
- 1.6 to 1.8
- 2.2 to 2.4
- 2.6 to 2.8
Answer
2.2 to 2.4
[2016]
103. 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 find the smallest index i such that A[i] is 1 by probing the minimum number of locations in A. The worst-case number of probes performed by an optimal algorithm is ________ .
- 1
- 4
- 5
- 7
Answer
5
[2017]
104. 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) Θ (n log n) |
(R) Heap sort given n numbers at the worst case | (iii) Θ (2n) |
(S) Addition of two n × n matrices | (iv) Θ (log n) |
- P → (iii), Q → (iv), R → (i), S → (ii)
- P → (iv), Q → (iii), R → (i), S → (ii)
- P → (iii), Q → (iv), R → (ii), S → (i)
- P → (iv), Q → (iii), R → (ii), S → (i)
Answer
P → (iii), Q → (iv), R → (ii), S → (i)
[2017]
105. 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 Dith unit of time. What is the maximum profit earned?
Task | T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 | T9 |
Profit | 15 | 20 | 30 | 18 | 18 | 10 | 23 | 16 | 25 |
Deadline | 7 | 2 | 5 | 3 | 4 | 5 | 2 | 7 | 3 |
- 147
- 165
- 167
- 175
Answer
147
[2005]
106. Consider a weighted complete graph G on the vertex set {v1, v2,…, vn} such that the weight of the edge (vi, vj) is 2|i-j|. The weight of the minimum spanning tree is:
- n – 1
- 2n – 2
- n/2
- n2
Answer
2n – 2
[2006]
107. To implement Dijkstra’s shortest path algorithm on unweighted graphs so that it runs in linear time, the data structure to be used is:
- Queue
- Stack
- Heap
- B-Tree
Answer
Heap
[2006]
108. 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 – b), (d – f), (b – f), (d – c), (d – e)
- (a – b), (d – f), (d – c), (b – f), (d – e)
- (d – f), (a – b), (d – c), (b – f), (d – e)
- (d – f), (a – b), (b – f), (d – e), (d – c)
Answer
(d – f), (a – b), (b – f), (d – e), (d – c)
[2006]
109. A 3-ary max-heap is like a binary max-heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], and nodes in the next level, from left to right, are stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Which one of the following is a valid sequence of elements in an array representing 3-ary max-heap?
- 1, 3, 5, 6, 8, 9
- 9, 6, 3, 1, 8, 5
- 9, 3, 6, 8, 5, 1
- 9, 5, 6, 8, 3, 1
Answer
9, 5, 6, 8, 3, 1
[2006]
110. A 3-ary max-heap is like a binary max-heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], and nodes in the next level, from left to right, are stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Suppose the elements 7, 2, 10 and 4 are inserted, in above question. Which one of the following is resultant heap?
- 10, 7, 9, 8, 3, 1, 5, 2, 6, 4
- 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
- 10, 9, 4, 5, 7, 6, 8, 2, 1, 3
- 10, 8, 6, 9, 7, 2, 3, 4, 1, 5
Answer
10, 7, 9, 8, 3, 1, 5, 2, 6, 4
[2006]
111. In an unweighted, undirected connected graph, the shortest path from a node S to every other node is computed most efficiently, in terms of time complexity, by
- Dijkstra’s algorithm starting from S.
- Warshall’s algorithm
- Performing a DFS starting from S.
- Performing a BFS starting from S.
Answer
Performing a BFS starting from S.
[2007]
112. A complete n-ary tree is a tree in which each node has n children or no childern. Let I be the number of internal nodes and L be the number of leaves in a complete n-ary tree. If L = 41, and I = 10, what is the value of n?
- 3
- 4
- 5
- 6
Answer
5
[2007]
113. Consider the following C program segment where CellNode represents a node in a binary tree:
struct CellNode { struct CellNode * leftChild; int element; struct CellNode * rightChild; }; int GetValue(struct CellNode * ptr) { int value = 0; if (ptr != NULL) { if ((ptr -> leftChild == NULL) && (ptr -> rightChild == NULL)) value = 1; else value = value + GetValue(ptr -> leftChild) + GetValue(ptr -> rightChild); } return (value);
The value returned by GetValue when a pointer to the root of a binary tree is passed as its argument is:
- The number of nodes in the tree
- The number of internal nodes in the tree
- The number of leaf nodes in the tree
- The height of the tree
Answer
The number of leaf nodes in the tree
[2007]
114. 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?
- There is a minimum spanning tree containing e.
- 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.
- Every minimum spanning tree has an edge of weight w.
- e is present in every minimum spanning tree.
Answer
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.
[2007]
115. The Breadth-first search algorithm has been implemented using the queue data structure. One possible order of visiting the nodes of the following graph is
- MNOPQR
- NQMPOR
- QMNPRO
- QMNPOR
Answer
QMNPRO
[2008]
116. G is a graph on n vertices and 2n – 2 edges. The edges of G can be partitioned into two edge-disjoint spanning trees. Which of the following is NOT true for G?
- For every subset of k vertices, the induced subgraph has atmost 2k – 2 edges
- The minimum cut in G has atleast two edges
- There are two edge-disjoint paths between every pair of vertices
- There are two vertex-disjoint paths between every pair of vertices
Answer
There are two vertex-disjoint paths between every pair of vertices
[2008]
117. Dijkstra’s single source shortest path algorithm when run from vertex a in the above graph, computes the correct shortest path distance to
- Only vertex a
- Only vertices a, e, f, g, h
- Only vertices a, b, c, d
- all the vertices
Answer
all the vertices
[2008]
118. You are given the post-order traversal, P, of a binary search tree on the n elements 1, 2,…, n. You have to determine the unique binary search tree that has P as its post-order traversal. What is the time complexity of the most efficient algorithm for doing this?
- Θ(log n)
- Θ(n)
- Θ(n log n)
- None of the above, as the tree cannot be uniquely determined
Answer
Θ(n)
[2008]
119. 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.
- P only
- Q only
- Both P and Q
- Neither P nor Q
Answer
Q only
[2009]
120. 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?
- (b, e) (e, f) (a, c) (b, c) (f, g) (c, d)
- (b, e) (e, f) (a, c) (f, g) (b, c) (c, d)
- (b, e) (a, c) (e, f) (b, c) (f, g) (c, d)
- (b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
Answer
(b, e) (e, f) (b, c) (a, c) (f, g) (c, d)
[2009]
121. Consider a binary max-heap implemented using an array. Which one of the following array represents a binary max-heap?
- {25, 12, 16, 13, 10, 8, 14}
- {25, 14, 13, 16, 10, 8, 12}
- {25, 14, 16, 13, 10, 8, 12}
- {25, 14, 12, 13, 10, 8, 16}
Answer
{25, 14, 16, 13, 10, 8, 12}
[2009]
122. Consider a binary max-heap implemented using an array. What is the content of the array after two delete operations on the correct answer to the previous question?
- {14, 13, 12, 10, 8}
- {14, 12, 13, 8, 10}
- {14, 13, 8, 12, 10}
- {14, 13, 12, 8, 10}
Answer
{14, 13, 12, 8, 10}
[2009]
123. 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}. 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?
- 7
- 8
- 9
- 10
Answer
10
[2010]
124. 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}. What is the minimum possible weight of a path P from vertex 1 to vertex 2 in this graph such that P contains at most 3 edges?
- 7
- 8
- 9
- 10
Answer
8
[2010]
125. A hash table of length 10 uses open addressing with hash function h(k) = k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below:
0 | |
1 | |
2 | 42 |
3 | 23 |
4 | 34 |
5 | 52 |
6 | 46 |
7 | 33 |
8 | |
9 |
Which one of the following choices gives a possible order in which the key values could have been inserted in the table?
- 46, 42, 34, 52, 23, 33
- 34, 42, 23, 52, 33, 46
- 46, 34, 42, 23, 52, 33
- 42, 46, 33, 23, 34, 52
Answer
46, 34, 42, 23, 52, 33
[2010]
126. A hash table of length 10 uses open addressing with hash function h(k) = k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below:
0 | |
1 | |
2 | 42 |
3 | 23 |
4 | 34 |
5 | 52 |
6 | 46 |
7 | 33 |
8 | |
9 | |
How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown above?
- 10
- 20
- 30
- 40
Answer
30
[2010]
127. A max-heap is a heap where the value of each parent is greater than or equal to the value of its children. Which of the following is a max-heap?
- [image]
- [image]✔
- [image]
- [image]
[2011]
Answer
128. 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 n nodes?
- 1/12 (11n2 – 5n)
- n2 – n + 1
- 6n – 11
- 2n + 1
Answer
n2 – n + 1
[2011]
129. 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
- 11
- 25
- 31
- 41
Answer
31
[2011]
130. 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.
- SDT
- SBDT
- SACDT
- SACET
Answer
SACET
[2012]
131. Let G be a weighted graph with edge weights greater than one and G1 be the graph constructed by squaring the weights of edges in G. Let T and T1 be the minimum spanning trees of G and G1, respectively, with total weights t and t1. Which of the following statements is TRUE?
- T1 = T with total weight t1 = t2
- T1 = T with total weight t1 < t2
- T1 ≠ T but total weight t1 = t2
- None of the above
Answer
T1 = T with total weight t1 < t2
[2012]
132. What is the time complexity of the Bellman–Ford single source shortest path algorithm on a complete graph of n vertices?
- Θ(n2)
- Θ(n2 log n)
- Θ(n3)
- Θ(n3 log n)
Answer
Θ(n3)
[2013]
133. Consider the following operation along with Enqueue and Dequeue operations on queues, where k is a global parameter.
MultiDequeue(Q) { m = k while (Q is not empty) and(m > 0) { Dequeue(Q) m = m - 1 } }
What is the worst case time complexity of a sequence of n queue operations on an initially empty queue?
- Θ(n)
- Θ(n + k)
- Θ(nk)
- Θ(n2)
Answer
Θ(n)
[2013]
134. 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 post-order traversal sequence of the same tree?
- 10, 20, 15, 23, 25, 35, 42, 39, 30
- 15, 10, 25, 23, 20, 42, 35, 39, 30
- 15, 20, 10, 23, 25, 42, 35, 39, 30
- 15, 10, 23, 25, 20, 35, 42, 39, 30
Answer
15, 10, 23, 25, 20, 35, 42, 39, 30
[2013]
135. Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time of depth first search on G, when G is represented as an adjacency matrix?
- θ(n)
- θ(n + m)
- θ(n2)
- θ(m2)
Answer
θ(n2)
[2014]
136. Consider the directed graph given below.
Which one of the following is TRUE?
- The graph does not have any topological ordering.
- Both PQRS and SRQP are topological orderings.
- Both PSRQ and SPRQ are topological orderings.
- PSRQ is the only topological ordering.
Answer
Both PSRQ and SPRQ are topological orderings.
[2014]
137. There are 5 bags labeled 1 to 5. All the coins in a given bag have the same weight. Some bags have coins of pick 1, 2, 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 _
- 10 to 10
- 11 to 12
- 12 to 12
- 14 to 16
Answer
12 to 12
[2014]
138. A priority queue is implemented as a max-heap. Initially it has 5 elements. The level-order traversal of the heap is : 10, 8, 5, 3, 2. Two new elements 1 and 7 are inserted into the heap in that order. The levelorder traversal of the heap after the insertion of the elements is
- 10, 8, 7, 3, 2, 1, 5
- 10, 8, 7, 2, 3, 1, 5
- 10, 8, 7, 1, 2, 3, 5
- 10, 8, 7, 5, 3, 2, 1
Answer
10, 8, 7, 3, 2, 1, 5
[2014]
139. Consider the tree arcs of a BFS traversal from a source node W in an unweighted, connected, undirected graph. The tree T formed by the tree acrs is a data structure for computing
- The shortest path between every pair of vertices
- The shortest path from W to every vertex in the graph
- The shortest paths from W to only those nodes that are leaves of T.
- The longest path in the graph
Answer
The shortest path from W to every vertex in the graph
[2014]
140. The number of distinct minimum spanning trees for the weighted graph below is _.
- 2 to 4
- 4 to 4
- 4 to 6
- 6 to 6
Answer
6 to 6
[2014]
141. Suppose a 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 _.
- 7
- 13
- 19
- 5
Answer
19
[2014]
142. 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 _______.
- 0
- 10
- 110
- 1110
Answer
110
[2014]
143. 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 shown below. The minimum possible sum of weights of all 8 edges of this graph is _
- 76
- 69
- 73
- 57
Answer
69
[2015]
144. Consider two decision problems Q1, Q2 such that Q1 reduces in polynomial time to 3-SAT and 3-SAT reduces in polynomial time to Q2. Then which one of the following is consistent with the above statement?
- Q1 is in NP, Q2 is NP hard.
- Q2 is in NP, Q1 is NP hard.
- Both Q1 and Q2 are in NP.
- Both Q1 and Q2 are NP hard.
Answer
Q1 is in NP, Q2 is NP hard.
[2015]
145. Given below are some algorithms, and some algorithm design paradigms. Match the belowalgorithms on the left to the corresponding design paradigm they follow.
1. Dijkstra’s Shortest Path | i. Divide and Conquer |
2. Floyd-Warshall algorithm to compute all pairs shortest path | ii. Dynamic Programming |
3. Binary search on a sorted array | iii. Greedy design |
4. Backtracking search on a graph | iv. Depth-first search |
v. Breadth-first search |
- 1–i, 2–iii, 3–i, 4–v
- 1–iii, 2–iii, 3–i, 4–v
- 1–iii, 2–ii, 3–i, 4–iv
- 1–iii, 2–ii, 3–i, 4–v
Answer
1–iii, 2–ii, 3–i, 4–iv
[2015]
146. A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞, and hence there cannot be any entry to the right of, or below a ∞. The following Young tableau consists of unique entries.
1 | 2 | 5 | 14 |
3 | 4 | 6 | 23 |
10 | 12 | 18 | 25 |
31 | ∞ | ∞ | ∞ |
When an element is removed from a Young tableau, the resulting table is still a Young tableau (unfilled entries maybe filled in with a ∞). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is _
- 12
- 23
- 5
- ∞
Answer
5
[2015]
147. Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?
- h(i) = i2 mod 10
- h(i) = i3 mod 10
- h(i) = (11 * i2) mod 10
- h(i) = (12 * i) mod 10
Answer
h(i) = i3 mod 10
[2015]
148. 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.
- P only
- Q only
- Neither P nor Q
- Both P and Q
Answer
P only
[2016]
149. 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 minimum weight spanning tree of G can have is _ .
- 13
- 5
- 7
- 11
Answer
7
[2016]
150. 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
- I only
- II only
- both I and II
- neither I nor II
Answer
II only
[2016]
151. 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 _.
- 23
- 31
- 17
- 19
Answer
31
[2016]
152. 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 statements:
(I) Minimum spanning Tree of G is always unique.
(II) Shortest path between any two vertices of G is always unique.
Which of the above statements is/are necessarily true?
- (I) only
- (II) only
- both (I) and (II)
- neither (I) nor (II)
Answer
(I) only
[2017]
153. The Breadth First Search (BFS) algorithm has been implemented using the queue data structure. Which one of the following is a possible order of visiting the nodes in the graph below?
- MNOPQR
- NQMPOR
- QMNROP
- POQNMR
Answer
POQNMR
[2017]
154. 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:
Character | Probability |
P | 0.22 |
Q | 0.34 |
R | 0.17 |
S | 0.19 |
T | 0.08 |
Total | 1.00 |
If a message of 100 characters over X is encoded using Huffman coding, then the expected length of the encoded message in bits is _.
- 175
- 225
- 250
- 275
Answer
225
[2017]
155. 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 vis at depth j in TB, then |i – j| = 1.
Which of the statements above must necessarily be true?
- I only
- II only
- Both I and II
- Neither I nor II
Answer
I only
[2018]
156. Consider the following undirected graph G:
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 this value of x is __.
- 1
- 2
- 3
- 4
Answer
4
[2018]
157. Consider a hash table of size seven, with starting index zero, and a hash function (3x + 4) mod7. Assuming the hash table is initially empty, which of the following is the contents of the table when the sequence 1, 3, 8, 10 is inserted into the table using closed hashing? Note that − denotes an empty location in the table.
- 8, −, −, −, −, −, 10
- 1, 8, 10, −, −, −, 3
- 1, −, −, −, −, −, 3
- 1, 10, 8, −, −, −, 3
Answer
1, 8, 10, −, −, −, 3
[2007]
158. 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 ?
- 0, 10, 110, 1110, 11110, 11111
- 11, 10, 011, 010, 001, 000
- 11, 10, 01, 001, 0001, 0000
- 110, 100, 010, 000, 001, 111
Answer
0, 10, 110, 1110, 11110, 11111
[2007]
159. 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 correct answer to above question?
- 3
- 2.1875
- 2.25
- 1.9375
Answer
1.9375
[2007]
160. The subset-sum problem is defined as follows: Given a set S of n positive integers and a positive integer W, determine whether there is a subset of S whose elements sum to W. An algorithm Q solves this problem in O(nW) time. Which of the following statements is false?
- Q solves the subset-sum problem in polynomial time when the input is encoded in unary
- Q solves the subset-sum problem in polynomial time when the input is encoded in binary
- The subset sum problem belongs to the class NP
- The subset sum problem is NP-hard
Answer
Q solves the subset-sum problem in polynomial time when the input is encoded in binary
[2008]
161. Let πA be a problem that belongs to the class NP. Then which one of the following is true?
- There is no polynomial time algorithm for πA.
- If πA can be solved deterministically in polynomial time, then P = NP.
- If πA is NP-hard, then it is NP-complete.
- πA may be undecidable.
Answer
If πA is NP-hard, then it is NP-complete.
[2009]
163. 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 subsequence (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:
I(i, j) = 0, if either i = 0 or j = 0
= 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?
- expr1 ≡ I(i – 1, j) + 1
- expr1 ≡ I(i, j – 1)
- expr2 ≡ max(I(i – 1, j), I(i, j – 1))
- expr2 ≡ max(I(i -1, j – 1), I(i, j))
Answer
expr2 ≡ max(I(i – 1, j), I(i, j – 1))
[2009]
164. 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. The values of l(i, j) could be obtained by dynamic programming based on the correct recursive definition of l(i, j) of the form given above, using an array L[M, N], where M = m + 1 and N = n + 1, such that L[i, j] = l(i, j). Which one of the following statements would be TRUE regarding the dynamic programming solution for the recursive definition of l(i, j)?
- All elements of L should be initialized to 0 for the values of l(i, j) to be properly computed.
- The values of l(i, j) may be computed in a row major order or column major order of L(M, N).
- The values of l(i, j) cannot be computed in either row major order or column major order of L(M, N).
- L[p, q] needs to be computed before L[r, s] if either p < r or q < s.
Answer
The values of l(i, j) may be computed in a row major order or column major order of L(M, N).
[2009]
165. The weight of a sequence a0, a1,…, an-1 of real numbers is defined as a0 + a1/2 + … + an-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
- max (Y, a0 + Y)
- max (Y, a0 + Y/2)
- max (Y, a0 + 2Y)
- a0 + Y/2
Answer
max (Y, a0 + 2Y)
[2010]
166. Four matrices M1, M2, M3 and M4 of dimensions p ×q, q × r, r × s and s × t respectively, can be multiplied in several ways with different number of total scalar multiplications. For example when multiplied as ((M1× M2) × (M3 × M4)), the total number of scalar multiplications is pqr + rst + prt. When multiplied (((M1 × M2) × M3) × M4) the total number of scalar multiplications is pqr + prs + pst.If p = 10, q = 100, r = 20, s = 5 and t = 80, then the minimum number of scalar multiplications needed is
- 248000
- 44000
- 19000
- 25000
Answer
44000
[2011]
167. Assuming P ≠ NP, which of the following is TRUE?
- NP-complete = NP
- NP-complete ∩ P = ∅
- NP-hard = NP
- P = NP-complete
Answer
NP-complete ∩ P = ∅
[2012]
168. Which of the following statements are TRUE?
(i) The problem of determining whether there exists a cycle in an undirected graph is in P.
(ii) The problem of determining whether there exists a cycle in an undirected graph is in NP.
(iii) If a problem A is NP-Complete, there exists a nondeterministic polynomial time algorithm to solve A.
- 1, 2 and 3
- 1 and 2 only
- 2 and 3 only
- 1 and 3 only
Answer
1, 2 and 3
[2013]
169. Suppose a polynomial time algorithm is discovered that correctly computes the largest clique in a given graph. In this scenario, which one of the following represents the correct Venn diagram of the complexity classes P, NP and NP-complete (NPC)?
- NP
- NPC
- P = NP
- P = NP = NPC
Answer
P = NP = NPC
[2014]
170. Consider a hash, table with 9 slots. The hash function is h(K) = K mod 9. The collisions are resolved by chaining. The following 9 keys are inserted in the order: 5, 28, 19, 15, 20, 33, 12, 17, 10. The maximum, minimum, and average chain lengths in the hash table, respectively, are
- 3, 0 and 1
- 3, 3 and 3
- 4, 0 and 1
- 3, 0 and 2
Answer
3, 0 and 1
[2014]
171. 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 = _________
- 26
- 29
- 34
- 43
Answer
34
[2014]
172. Suppose you want to move from 0 to 100 on the number line. In each step, you either move right by a unit distance or you take a shortcut. A shortcut is simply a pre-specified pair of integers i, j with i < j. Given a shortcut i, j if you are at position i on the number line, you may directly move to j. Suppose T(k) denotes the smallest number of steps needed to move from k to 100. Suppose further that there is at most 1 shortcut involving any number, and in particular from 9 there is a shortcut to 15. Let y and z be such that T(9) = 1 + min(T(y), T(z)). Then the value of the product yz is _
- 76
- 110
- 150
- 115
Answer
150
[2014]
173. Consider the decision problem 2CNFSAT defined as follows:
{Φ | Φ is a satisfiable propositional formula in CNF with at most two literals per clause} For example, Φ = (x1 ∨ x2) ∧ (x1 ∨ x)) ∧ (x2 ∨ x4) is a Boolean formula and it is in 2CNFSAT. The decision problem 2CNFSAT is
- NP-complete
- Solvable in polynomial time by reduction to directed graph reach ability.
- Solvable in constant time since any input instance is satisfiable.
- NP-hard, but not NP-complete
Answer
Solvable in polynomial time by reduction to directed graph reach ability.
[2014]
174. Consider a hash table with 100 slots. Collisions are resolved using chaining. Assuming simple uniform hashing, what is the probability that the first 3 slots are unfilled after the first 3 insertions?
- (97 × 97 × 97)/1003
- (99 × 98 × 97)/1003
- (97 × 96 × 95)/1003
- (97 × 96 × 95)/(3! × 1003)
Answer
(97 × 97 × 97)/1003
[2014]
175. 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 |
- P–iii, Q–ii, R–iv, S–i
- P–i, Q–ii, R–iv, S–iii
- P–ii, Q–iii, R–iv, S–i
- P–ii, Q–i, R–iii, S–iv
Answer
P–ii, Q–iii, R–iv, S–i
[2014]
176. Given a hash table T with 25 slots that stores 2000 elements, the load factor ∝ for T is _
- 40
- 65
- 80
- 115
Answer
80
[2015]
177. Language L1 is polynomial time reducible to language L2. Language L3 is polynomial time reducible to L2, which in turn is polynomial time reducible to language L4. Which of the following is/are true?
- if L4 ∈ P, then L2 ∈ P
- if L1 ∈ P or L3 ∈ P, then L2 ∈ P
- L1 ∈ P, if and only if L3 ∈ P
- if L4 ∈ P, then L1 ∈ P and L3 ∈ P
Answer
L1 ∈ P, if and only if L3 ∈ P
[2015]
178. The Floyd – Warshall algorithm for all-pair shortest paths computation is based on
- Greedy paradigm
- Divide-and-Conquer paradigm
- Dynamic Programming paradigm
- Neither Greedy nor Divide-and-Conquer nor Dynamic Programming paradigm.
Answer
Dynamic Programming paradigm
[2016]
179. 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 required to find the product A1A2A3A4 using the basic matrix multiplication method is _ .
- 1200
- 1365
- 1495
- 1500
Answer
1500
[2016]
180. Consider the following table:
Algorithms | Design Paradigms |
(P) Kruskal | (i) Divide and Conquer |
(Q) Quicksort | (ii) Greedy |
R) Floyd-Warshall | (iii) Dynamic Programming |
Match the algorithms to the design paradigms they are based on.
- (P) ↔ (ii), (Q) ↔ (iii),(R) ↔ (i)
- (P) ↔ (iii), (Q) ↔ (i), (R) ↔ (ii)
- (P) ↔ (ii), (Q) ↔ (i), (R) ↔ (iii)
- (P) ↔ (i), (Q) ↔ (ii), (R) ↔ (iii)
Answer
(P) ↔ (ii), (Q) ↔ (i), (R) ↔ (iii)
[2017]
181. Assume that multiplying a matrix G1 of dimensions p × q with another matrix G2 of dimension q × r requires pqr scalar multiplications. Computing the product of n matrices G1G2G3, …, Gn can be done by parenthesizing in different ways. Define Gi Gi+1 as an explicitly directly multiplied. For example, in the matrix multiplication chain G1G2G3G4G5G6 using parenthesization (G1(G2G3))(G4(G5G6)), G2G3 and G5G6 are the only explicitly computed pairs. Consider a matrix multiplication chain F1F2F3F4F5, where matrices F1, F2, F3, F4 and F5are of dimensions 2 × 25, 25 × 3, 3 × 16, 16 × 1 and 1 × 1000, respectively. In the parenthesization of F1F2F3F4F5 that minimizes the total number of scalar multiplications, the explicitly computed pairs is/are:
- F1F2 and F3F4 only
- F2F3 only
- F3F4 only
- F1F2 and F4F5 only
Answer
F3F4 only
[2018]
182. Consider the weights and values of items listed below. Note that tehre is only one unit of each item.
Item no. | Weight (in Kgs) | Value (in Rupees) |
1 | 10 | 60 |
2 | 7 | 28 |
3 | 4 | 20 |
4 | 2 | 24 |
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. Morever, 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 __.
- 10
- 16
- 7
- 28
Answer
16
[2018]