**data structures gate previous year questions with solutions**

Q1➡ | GATE 2021 Set-1 Consider the following statements. S1:The sequence of procedure calls corresponds to a preorder traversal of the activation tree. S2:The sequence of procedure returns corresponds to a postorder traversal of the activation tree. Which one of the following options is correct? |

i ➥ S1 is false and S2 is true |

ii ➥ S1 is false and S2 is false |

iii ➥ S1 is true and S2 is false |

iv ➥ S1 is true and S2 is true |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Graph and Tree | Help-Line |

Q2➡ | GATE 2021 Set-1 A binary search tree T contains n distinct elements. What is the time complexity of picking an element in T that is smaller than the maximum element in T? |

i ➥ Θ(logn) |

ii ➥ Θ(nlogn) |

iii ➥ Θ(1) |

iv ➥ Θ(n) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Search Tree | Help-Line |

Q3➡ | GATE 2021 Set-1 Consider a dynamic hashing approach for 4-bit integer keys: 1. There is a main hash table of size 4. 2. The 2 least significant bits of a key is used to index into the main hash table. 3. Initially, the main hash table entries are empty. 4. Thereafter, when more keys are hashed into it, to resolve collisions, the set of all keys corresponding to a main hash table entry is organized as a binary tree that grows on demand. 5. First, the 3rd least significant bit is used to divide the keys into left and right subtrees. 6. To resolve more collisions, each node of the binary tree is further sub-divided into left and right subtrees based on the 4th least significant bit. 7. A split is done only if it is needed, i.e., only when there is a collison. Consider the following state of the hash table. Which of the following sequences of key insertions can cause the above state of the hash table (assume the keys are in decimal notation)? |

i ➥ 9, 5, 13, 6, 10, 14 |

ii ➥ 10, 9, 6, 7, 5, 13 |

iii ➥ 5, 9, 4, 13, 10, 7 |

iv ➥ 9, 5, 10, 6, 7, 1 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Hashing | Help-Line |

Q4➡ | GATE 2021 Set-1 Consider the following sequence of operations on an empty stack. push(54); push(52); pop(); push(55); push(62); s=pop(); Consider the following sequence of operations on an empty queue. enqueue(21); enqueue(24); dequeue(); enqueue(28); enqueue(32); q = dequeue(); The value of s + q is __ |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Queues and stacks | Help-Line |

Q5➡ | GATE 2021 Set-1 |

i ➥ The program will compile successfully and output 8 when executed. |

ii ➥ The program will not compile successfully. |

iii ➥ The program will compile successfully and output 13 when executed. |

iv ➥ The program will compile successfully and output 10 when executed. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C Programming | Help-Line |

Q6➡ | 2 GATE 2021 Set- |

i ➥ 24 |

ii ➥ 14 |

iii ➥ 30 |

iv ➥ 20 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C programming | Help-Line |

Q7➡ | 2GATE 2021 Set-Let be a binary min-heap consisting of n elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in H?H |

i ➥ |

ii ➥ |

iii ➥ |

iv ➥ |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap | Help-Line |

Q8➡ | 2GATE 2021 Set-Consider a complete binary tree with 7 nodes, Let A denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let B denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root. The value of |A – B| is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Tree | Help-Line |

Q9➡ | 2GATE 2021 Set- |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C Programming | Help-Line |

Q10➡ | 2GATE 2021 Set-Assume that the variable y points to a struct (allocated on the head) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and de-reference operations (of the form y->f1 or y->f2) in the optimized code, respectively, are: |

i ➥ 303 and 2 |

ii ➥ 403 and 102 |

iii ➥ 203 and 2 |

iv ➥ 303 and 102 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C Programming | Help-Line |

Q11➡ | 2GATE 2021 Set- |

i ➥ Upon execution, the program goes into an infinite loop. |

ii ➥ It dereferences an uninitialized pointer that may result in a run-time error. |

iii ➥ Upon execution, the program creates a linked-list of five nodes. |

iv ➥ It has a missing return which will be reported as an error by the compiler. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C Programming | Help-Line |

Q12➡ | 2GATE 2021 Set- |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C Programming | Help-Line |

Q13➡ | 0 GATE 202What is the worst case time complexity of inserting n ^{2} elements into an AVL-tree with n elements initially? |

i ➥ θ(n^{2} log n) |

ii ➥ θ(n^{3}) |

iii ➥ θ(n^{2}) |

iv ➥ θ(n^{4}) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q14➡ | 0GATE 202The preorder traversal of a binary search tree is 15, 10, 12, 11, 20, 18, 16, 19. Which one of the following is the postorder traversal of the tree? |

i ➥ 10, 11, 12, 15, 16, 18, 19, 20 |

ii ➥ 20, 19, 18, 16, 15, 12, 11, 10 |

iii ➥ 11, 12, 10, 16, 19, 18, 20, 15 |

iv ➥ 19, 16, 18, 20, 11, 12, 10, 15 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q15➡ | 0GATE 202What is the worst case time complexity of inserting n elements into an empty linked list, if the linked list needs to be maintained in sorted order? |

i ➥ θ(n) |

ii ➥ θ(n log n) |

iii ➥ θ(1) |

iv ➥ θ(n^{2}) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Linked List | Help-Line |

Q16➡ | 0GATE 202Consider a double hashing scheme in which the primary hash function is h _{1}(k) = k mod 23, and the secondary hash function is h _{2}(k) = 1 + (k mod 19). Assume that the table size is 23. Then the address returned by probe 1 in the probe sequence (assume that the probe sequence begins at probe 0) for key value k=90 is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Hashing | Help-Line |

Q17➡ | 0GATE 202Consider the following C program. The output of the program is ______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Arrays | Help-Line |

Q18➡ | 0GATE 202In a balanced binary search tree with n elements, what is the worst case time complexity of reporting all elements in range [a,b]? Assume that the number of reported elements is k. |

i ➥ θ(k log n) |

ii ➥ θ(log n) |

iii ➥ θ(n log k) |

iv ➥ θ(log n + k) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q19➡ | 0GATE 202Let G = (V,E) be a directed, weighted graph with weight function w:E → R. For some function f:V → R, for each edge (u,v) ∈ E, define w'(u,v) as w(u,v) + f(u) – f(v). Which one of the options completes the following sentence so that it is TRUE? “The shortest paths in G under w are shortest paths under w’ too, _________”. |

i ➥ if and only if ∀u ∈ V, f(u) is negative |

ii ➥ for every f: V→R |

iii ➥ if and only if ∀u ∈ V, f(u) is positive |

iv ➥ if and only if f(u) is the distance from s to u in the graph obtained by adding a new vertex s to G and edges of zero weight from s to every vertex of G |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Graph and Tree | Help-Line |

Q20➡ | 0GATE 202Consider the array representation of a binary min-heap containing 1023 elements. The minimum number of comparisons required to find the maximum in the heap is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap Tree | Help-Line |

Q21➡ | 0GATE 202Consider the following C functions: The return value of fun2 (5) is ______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q22➡ | 0GATE 202Consider the following C functions: The value returned by pp(3,4) is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q23➡ | GATE 2019The value printed by the program is __. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Functions | Help-Line |

Q24➡ | GATE 2019Consider the following C program: Which one of the following values will be displayed on execution of the programs? |

i ➥ 52 |

ii ➥ 630 |

iii ➥ 41 |

iv ➥ 63 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | For Loop | Help-Line |

Q25➡ | GATE 2019Consider the following C function: Which one of the following will happen when the function convert is called with any positive integer n as argument? |

i ➥ It will print the binary representation of n and terminate. |

ii ➥ It will print the binary representation of n in the reverse order and terminate. |

iii ➥ It will print the binary representation of n but will not terminate. |

iv ➥ It will not print anything and will not terminate. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Functions | Help-Line |

Q26➡ | GATE 2019Consider the following statements: I. The smallest element in a max-heap is always at a leaf node. II. The second largest element in a max-heap is always a child of the root node. III. A max-heap can be constructed from a binary search tree in Θ(n) time. IV. A binary search tree can be constructed from a max-heap in Θ(n) time. Which of the above statements are TRUE? |

i ➥ I, II and III |

ii ➥ I, III and IV |

iii ➥ II, III and IV |

iv ➥ I, II and IV |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q27➡ | GATE 2019Let T be a full binary tree with 8 leaves. (A full binary tree has every level full). Suppose two leaves a and b of T are chosen uniformly and independently at random. The expected value of the distance between a and b in T (i.e., the number of edges in the unique path between a and b) is (rounded off to 2 decimal places) __________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q28➡ | GATE 2019Consider the following C program: The output of the above C program is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Control Statement | Help-Line |

Q29➡ | GATE 2019Consider the following C program: The number of times the variable sum will be printed, when the above program is executed, is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Control Statement | Help-Line |

Q30➡ | GATE 2018A 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? |

i ➥ θ(n), θ(1) |

ii ➥ θ(n), θ(n) |

iii ➥ θ(1), θ(1) |

iv ➥ θ(1), θ(n) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Queue | Help-Line |

Q31➡ | GATE 2018 |

i ➥ ‘0’, ‘a+2’ |

ii ➥ ‘0’, ‘c’ |

iii ➥ 0, c |

iv ➥ 0, a+2 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Programming in C | Help-Line |

Q32➡ | GATE 2018The 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_____. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Trees Traversal | Help-Line |

Q33➡ | GATE 2018Consider the following C program: The output of this program is __. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | C program | Help-Line |

Q34➡ | GATE 2018 Consider the following C code. Assume that unsigned long int type length is 64 bits. The value returned when we call fun with the input 2 is^{40} |

i ➥ 4 |

ii ➥ 5 |

iii ➥ 6 |

iv ➥ 40 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | For Loop | Help-Line |

Q35➡ | GATE 2018Consider the following C program: The output of the program above is. |

i ➥ Hi Bye Bye Hi |

ii ➥ Hi Bye Hi Bye |

iii ➥ Bye Hi Hi Bye |

iv ➥ Bye Hi Bye Hi |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q36➡ | GATE 2018 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q37➡ | GATE 2018The number of possible min-heaps containing each value from {1, 2, 3, 4, 5, 6, 7} exactly once is_______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap-Tree | Help-Line |

Q38➡ | GATE 2017 Set-1Let 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. |

i ➥ 4 and 14 respectively |

ii ➥ 3 and 15 respectively |

iii ➥ 3 and 14 respectively |

iv ➥ 4 and 15 respectively |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q39➡ | GATE 2017 Set-1Consider the C code fragment given below. Assuming that m and n point to valid NULL-terminated linked lists, invocation of join will |

i ➥ either cause a null pointer dereference or append list m to the end of list n. |

ii ➥ cause a null pointer dereference for all inputs. |

iii ➥ append list n to the end of list m for all inputs. |

iv ➥ append list m to the end of list n for all inputs. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Linked List | Help-Line |

Q40➡ | GATE 2017 Set-1Consider the following C code: The code suffers from which one of the following problems: |

i ➥ compiles successfully but execution may result in memory leak |

ii ➥ compiles successfully but execution may result in dangling pointer |

iii ➥ compiler error as the return of malloc is not typecast approximately |

iv ➥ compiler error because the comparison should be made as x==NULL and not as shown |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | malloc Function | Help-Line |

Q41➡ | GATE 2017 Set-1Let T be a tree with 10 vertices. The sum of the degrees of all the vertices in T is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Tree | Help-Line |

Q42➡ | GATE 2017 Set-1Consider the C functions foo and bar given below: Invocations of foo(3) and bar(3) will result in: |

i ➥ Abnormal termination and infinite loop respectively. |

ii ➥ Both terminating abnormally. |

iii ➥ Return of 6 and 6 respectively. |

iv ➥ Infinite loop and abnormal termination respectively. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q43➡ | GATE 2017 Set-1Consider the following two functions: The output printed when fun1(5) is called is |

i ➥ 53423122132435 |

ii ➥ 53423122233445 |

iii ➥ 53423120112233 |

iv ➥ 53423120213243 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q44➡ | GATE 2017 Set-1Consider the following C program: 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 _________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q45➡ | GATE 2017 Set-1The output of executing the following C program is _________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Function | Help-Line |

Q46➡ | GATE 2017 Set-2Match the following: |

i ➥ P→(iii), Q→(iv), R→(i), S→(ii) |

ii ➥ P→(ii), Q→(iv), R→(iii), S→(i) |

iii ➥ P→(ii), Q→(i), R→(iv), S→(iii) |

iv ➥ P→(ii), Q→(iv), R→(i), S→(iii) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Programming concept | Help-Line |

Q47➡ | GATE 2017 Set-2The 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? |

i ➥ NQMPOR |

ii ➥ MNOPQR |

iii ➥ QMNROP |

iv ➥ POQNMR |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Network Security | Help-Line |

Q48➡ | GATE 2017 Set-2Consider the following function implemented in C: The output of invoking printxy(1, 1) is |

i ➥ 1, 1 |

ii ➥ 1, 0 |

iii ➥ 0, 1 |

iv ➥ 0, 0 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Pointer | Help-Line |

Q49➡ | GATE 2017 Set-2A 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 ➥ Neither I nor II |

ii ➥ Both I and II |

iii ➥ II only |

iv ➥ I only |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Queue and Linked List | Help-Line |

Q50➡ | GATE 2017 Set-2Consider the C program fragment below which is meant to divide x and y using repeated subtractions. The variables x, y, q and r are all unsigned int. Which of the following conditions on the variables x, y, q and r before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)? |

i ➥ (q == 0) && (y > 0) |

ii ➥ (q == 0) && (r == x) && (y > 0) |

iii ➥ (x > 0) && (r == x) && (y > 0) |

iv ➥ (q == r) && (r == 0) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q51➡ | GATE 2017 Set-2The 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 post-order traversal of this tree is: |

i ➥ 7, 6, 2, 10, 9, 8, 15, 16, 17, 20, 19, 12 |

ii ➥ 7, 2, 6, 8, 9, 10, 20, 17, 19, 15, 16, 12 |

iii ➥ 2, 7, 6, 10, 9, 8, 15, 17, 20, 19, 16, 12 |

iv ➥ 2, 6, 7, 8, 9, 10, 12, 15, 16, 17, 19, 20 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Trees | Help-Line |

Q52➡ | GATE 2017 Set-2Consider the following snippet of a C program. Assume that swap(&x, &y) exchanges the contents of x and y. The output of the program is _______. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q53➡ | GATE 2017 Set-2Consider the following C program: The output of the program is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q54➡ | GATE 2017 Set-2Consider the following C program. The output of the program is _________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q55➡ | GATE 2016 Set-1A queue is implemented using an array such that ENQUEUE and DEQUEUE operations are performed efﬁciently. Which one of the following statements is CORRECT (n refers to the number of items in the queue)? |

i ➥ Both operations can be performed in O(1) time |

ii ➥ At most one operation can be performed in O(1) time but the worst case time for the other operation will be Ω(n) |

iii ➥ The worst case time complexity for both operations will be Ω(n) |

iv ➥ Worst case time complexity for both operations will be Ω(logn) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Queue | Help-Line |

Q56➡ | GATE 2016 Set-1Consider the following directed graph: The number of different topological orderings of the vertices of the graph is ___________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Topological Ordering | Help-Line |

Q57➡ | GATE 2016 Set-1Consider the following C program: Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error? |

i ➥ f(i, *p) |

ii ➥ f(i, *s) |

iii ➥ i = f(i, s) |

iv ➥ f(s, *s) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q58➡ | GATE 2016 Set-1Let 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 |

i ➥ Both P and Q |

ii ➥ Neither P nor Q |

iii ➥ Q only |

iv ➥ P only |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Graph | Help-Line |

Q59➡ | GATE 2016 Set-1Consider the following C program. The output of the program is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q60➡ | GATE 2016 Set-1The following function computes the maximum value contained in an integer array p[] of size n (n >= 1). The missing loop condition is |

i ➥ a != n |

ii ➥ b != 0 |

iii ➥ b > (a + 1) |

iv ➥ b != a |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q61➡ | GATE 2016 Set-1What will be the output of the following C program? |

i ➥ 3 1 2 2 1 3 4 4 4 |

ii ➥ 3 1 2 1 1 1 2 2 2 |

iii ➥ 3 1 2 2 1 3 4 |

iv ➥ 3 1 2 1 1 1 2 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q62➡ | GATE 2016 Set-1What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed? |

i ➥ 6, 2 |

ii ➥ 6, 6 |

iii ➥ 4, 2 |

iv ➥ 4, 4 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q63➡ | GATE 2016 Set-1 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-ﬁx the heap efﬁciently after the removal of the element? |

i ➥ O(1) |

ii ➥ O(d) but not O(1) |

iii ➥ O(2^{d}) but not O(d) |

iii ➥ O(d 2^{d}) but not O(2^{d}) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Heap | Help-Line |

Q64➡ | GATE 2016 Set-1Consider the weighted undirected graph with 4 vertices, where the weight of edge {i,j} is given by the entry W _{ij} in the matrix W.The largest possible integer value of x, for which at least one shortest path between some pair of vertices will contain the edge with weight x is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Graph | Help-Line |

Q65➡ | GATE 2016 Set-1Let 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. The maximum possible number of iterations of the while loop in the algorithm is ___________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Queue and Stack | Help-Line |

Q66➡ | GATE 2016 Set-1 Let X be a recursive language and Y be a recursively enumerable but not recursive language. Let W and Z be two languages such that Y’ reduces to W, and Z reduces to X’ (reduction means the standard many-one reduction). Which one of the following statements is TRUE? |

i ➥ W can be recursively enumerable and Z is recursive. |

ii ➥ W can be recursive and Z is recursively enumerable. |

iii ➥ W is not recursively enumerable and Z is recursive. |

iv ➥ W is not recursively enumerable and Z is not recursive. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Trees | Help-Line |

Q67➡ | GATE 2016 Set-2Breadth 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 _________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | BFS | Help-Line |

Q68➡ | GATE 2016 Set-2The value printed by the following program is _________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q69➡ | GATE 2016 Set-2N 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(logN) ﬁnd, and Θ(N) decrease-key. What is the time complexity of all these operations put together? |

i ➥ O(log_{2} N) |

ii ➥ O(N) |

iii ➥ O(N^{2}) |

iv ➥ Θ(N^{2} logN) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Linked List | Help-Line |

Q70➡ | GATE 2016 Set-2A 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 at depth 0. The maximum depth at which integer 9 can appear is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap Tree | Help-Line |

Q71➡ | GATE 2016 Set-2 The following function computes XY for positive integers X and Y. Which one of the following conditions is TRUE before every iteration of the loop? |

i ➥ X^{Y} = a^{b} |

ii ➥ (res * a)^{Y} = (res * X)^{b} |

iii ➥ X^{Y} = res * a^{b} |

iv ➥ X^{Y} = (res * a)^{b} |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q72➡ | GATE 2016 Set-2Consider 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: |

i ➥ – 1 6 7 * 2 ˆ 5 – 3 4 * |

ii ➥ + 1 * 6 7 ˆ 2 – 5 * 3 4 |

iii ➥ + 1 * 7 6 ˆ 2 – 5 * 4 3 |

iv ➥ 1 7 6 * + 2 5 4 3 * – ˆ – |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q73➡ | GATE 2016 Set-2Consider the following program: Note: max(x,y) returns the maximum of x and y.The value printed by this program is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q74➡ | GATE 2016 Set-2The number of ways in which the numbers 1, 2, 3, 4, 5, 6, 7 can be inserted in an empty binary search tree, such that the resulting tree has height 6, is __________. Note: The height of a tree with a single node is 0. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Trees | Help-Line |

Q75➡ | GATE 2016 Set-2In 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 efﬁcient algorithm to set the twin pointer in each entry in each adjacency list? |

i ➥ Θ(n^{2}) |

ii ➥ Θ(n+m) |

iii ➥ Θ(m^{2}) |

iv ➥ Θ(n^{4}) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Graph | Help-Line |

Q76➡ | GATE 2015 Set-1The height of a tree is the length of the longest root-to-leaf path in it. The maximum and minimum number of nodes in a binary tree of height 5 are |

i ➥ 63 and 6, respectively |

ii ➥ 64 and 5, respectively |

iii ➥ 32 and 6, respectively |

iv ➥ 31 and 5, respectively |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Tree | Help-Line |

Q77➡ | GATE 2015 Set-1Which of the following is/are correct inorder traversal sequence(s) of binary search tree(s) I. 3,5,7,8,15,19,25II. 5,8,12,10,15,25 III. 2,7,10,8,14,16,20 IV. 4,6,7,9,18,20,25 |

i ➥ I and VI only |

ii ➥ II and III only |

iii ➥ II and IV only |

iv ➥ II only |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Search Tree | Help-Line |

Q78➡ | GATE 2015 Set-1The output of the following C program is __________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q79➡ | GATE 2015 Set-1 What are the worst-case complexities of insertion and deletion of a key in a binary search tree? |

i ➥ Θ(logn) for both insertion and deletion |

ii ➥ Θ(n) for both insertion and deletion |

iii ➥ Θ(n) for insertion and Θ(logn) for deletion |

iv ➥ Θ(logn) for insertion and Θ(n) for deletion |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Search Tree | Help-Line |

Q80➡ | GATE 2015 Set-1Consider a max heap, represented by the array: 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 |

i ➥ 40, 30, 20, 10, 15, 16, 17, 8, 4, 35 |

ii ➥ 40, 35, 20, 10, 30, 16, 17, 8, 4, 15 |

iii ➥ 40, 30, 20, 10, 35, 16, 17, 8, 4, 15 |

iv ➥ 40, 35, 20, 10, 15, 16, 17, 8, 4, 30 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap | Help-Line |

Q81➡ | GATE 2015 Set-1What 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); } |

i ➥ 2036, 2036, 2036 |

ii ➥ 2012, 4, 2204 |

iii ➥ 2036, 10, 10 |

iv ➥ 2012, 4, 6 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q82➡ | GATE 2015 Set-1Consider the following C function. Which one of the following most closely approximates the return value of the function fun1? |

i ➥ n^{3} |

ii ➥ n(log n)^{2} |

iii ➥ nlog n |

iv ➥ nlog (log n) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q83➡ | GATE 2015 Set-1Consider the following pseudo code, where x and y are positive integers. begin q := 0 r := x while r >= y do begin r := r – y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is |

i ➥ {r = qx + y ∧ r< y} |

ii ➥ {x = qy + r ∧ r<y} |

iii ➥ {y = qx + r ∧ 0<r< y} |

iv ➥ {q +1 < r – y ∧ y > 0} |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q84➡ | GATE 2015 Set-2An unordered list contains n distinct elements. The number of comparisons to find an element in this list that is neither maximum nor minimum is |

i ➥ Θ(nlog n) |

ii ➥ Θ(n) |

iii ➥ Θ(log n) |

iv ➥ Θ(1) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Array | Help-Line |

Q85➡ | GATE 2015 Set-2Consider the following function written the C programming language. The output of the above function on input “ABCD EFGH” is |

i ➥ ABCD EFGH |

ii ➥ ABCD |

iii ➥ HGFE DCBA |

iv ➥ DCBA |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q86➡ | GATE 2015 Set-2Consider 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 |

i ➥ Ω(logn) |

ii ➥ Ω(n) |

iii ➥ Ω(nlog n) |

iv ➥ Ω(n^{2}) |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap Tree | Help-Line |

Q87➡ | GATE 2015 Set-2A binary tree T has 20 leaves. The number of nodes in T having two children is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q88➡ | GATE 2015 Set-2Consider the following C functions The return value of fun(5) is ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q89➡ | GATE 2015 Set-2A 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. When an element is removed from a Young tableau, other elements should be moved into its place so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is __________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Array | Help-Line |

Q90➡ | GATE 2015 Set-2Which 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? |

i ➥ h(i) = i^{2} mod 10 |

ii ➥ h(i) = i^{3} mod 10 |

iii ➥ h(i) = (11 *i^{2}) mod 10 |

iv ➥ h(i) = (12 * i) mod 10 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Hashing | Help-Line |

Q91➡ | GATE 2015 Set-2 Consider the C program below. The value printed by the above program is __________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q92➡ | GATE 2015 Set-3Consider the following C program segment. What will be printed by the program? |

i ➥ 12 |

ii ➥ 120400 |

iii ➥ 1204 |

iv ➥ 1034 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Program | Help-Line |

Q93➡ | GATE 2015 Set-3Consider a binary tree T that has 200 leaf nodes. Then, the number of nodes in T that have exactly two children are ________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Binary Tree | Help-Line |

Q94➡ | GATE 2015 Set-3Given a hash table T with 25 slots that stores 2000 elements, the load factor α for T is ___________. |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Hashing | Help-Line |

Q95➡ | GATE 2015 Set-3While 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 |

i ➥ 65 |

ii ➥ 67 |

iii ➥ 69 |

iv ➥ 83 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Heap Tree | Help-Line |

Q96➡ | GATE 2015 Set-3The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is |

i ➥ 284 |

ii ➥ 213 |

iii ➥ 142 |

iv ➥ 71 |

#### Show Answer With Best Explanation

More Discussion | Explanation On YouTube | Postfix Expression | Help-Line |

Q53➡ | |