Programming and Data Structures questions

Q23

GATE CS 2026 CS-1Tree Data StructuresMSQ1 mark
Let nn be an odd number greater than 100. Consider a binary minheap with nn elements stored in an array PP whose index starts from 1.

Which of the following indices of PP do/does NOT correspond to any leaf node of the minheap?
More than one option can be correct.
Show answer without attempting

Answer: B, C

Q27

GATE CS 2026 CS-1C ProgrammingMSQ1 mark
Consider the following C statements:
char *str1 = "Hello; /* Statement S1 */
char *str2 = "Hello;"; /* Statement S2 */
int *str3 = "Hello"; /* Statement S3 */
Which of the following options is/are correct?
More than one option can be correct.
Show answer without attempting

Answer: C

Q33

GATE CS 2026 CS-1Tree Data StructuresNAT1 mark
The height of a binary tree is the number of edges in the longest path from the root to a leaf in the tree. The maximum possible height of a full binary tree with 23 nodes is _________. (answer in integer)
Show answer without attempting

Answer: 11

Q34

GATE CS 2026 CS-1C ProgrammingNAT1 mark
Consider the following program in C:
#include <stdio.h>

void func(int i, int j) {
 if(i < j) {
 int i = 0;
 while (i < 10) {
 j += 2;
 i++;
 }
 }
 printf("%d", i);
}

int main() {
 int i = 9, j = 10;
 func(i, j);
 return 0;
}
The output of the program is _________. (answer in integer)
Note: Assume that the program compiles and runs successfully.
Show answer without attempting

Answer: 9

Q39

GATE CS 2026 CS-1Linear Data StructuresMCQ2 marks−2/3 if wrong
Consider the following code snippet in C language that computes the number of nodes in a non-empty singly linked list pointed to by the pointer variable head.
struct node{
 int elt;
 struct node *next;
};

int getListSize (struct node *head)
{
 if( E1 ) return 1;
 return E2;
}
Which one of the following options gives the correct replacements for the expressions E1 and E2?
Show answer without attempting

Answer: B

Q40

GATE CS 2026 CS-1Tree Data StructuresMCQ2 marks−2/3 if wrong
Let PP be the set of all integers from 1 to 15. Consider any order of insertion of the elements of PP into a binary search tree that creates a complete binary tree.

Which one of the following elements can NEVER be the third element that is inserted?
Show answer without attempting

Answer: D

Q61

GATE CS 2026 CS-1RecursionNAT2 marks
Consider the recursive functions represented by the following code segment:
int bar(int n){
 if (n == 1) return 0;
 else return 1 + bar(n/2);
}

int foo(int n){
 if (n == 1) return 1;
 else return 1 + foo(bar(n));
}
The smallest positive integer n for which foo(n) returns 5 is ______. (answer in integer)

Note: Ignore syntax errors (if any) in the function.
Show answer without attempting

Answer: 65536

Q62

GATE CS 2026 CS-1Tree Data StructuresNAT2 marks
The following sequence corresponds to the preorder traversal of a binary search tree TT:

50, 25, 13, 40, 30, 47, 75, 60, 70, 80, 77

The position of the element 60 in the postorder traversal of TT is ______. (answer in integer)

Note: The position begins with 1.
Show answer without attempting

Answer: 7

Q12

GATE CS 2026 CS-2Tree Data StructuresMCQ1 mark−1/3 if wrong
The set T represents various traversals over binary tree. The set S represents the order of visiting nodes during a traversal.

| T | S |
|---|---|
| I: Inorder | L: left subtree, node, right subtree |
| II: Preorder | M: node, left subtree, right subtree |
| III: Postorder | N: left subtree, right subtree, node |

Which one of the following is the correct match from T to S ?
Show answer without attempting

Answer: A

Q19

GATE CS 2026 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following three ANSI-C programs, P1, P2, and P3.
/* P1 */
#include <stdio.h>
int a=5;
int main(){
 int a=7;
 return(0);
}
/* P2 */
#include <stdio.h>
int main(){
 int a=5;
 int a=7;
 return(0);
}
/* P3 */
#include <stdio.h>
int main(){
 int a=5;
 float a=7;
 return(0);
}
Which one of the following statements is true?
Show answer without attempting

Answer: A

Q49

GATE CS 2026 CS-2Tree Data StructuresMSQ2 marks
Consider a binary search tree (BST) with nn leaf nodes (n>0n > 0). Given any node VV, the key present in the node is denoted as Val(V)Val(V). All the keys present in the given BST are distinct. The keys belong to the set of real numbers.

For a node VV, let Suc(V)Suc(V) denote the node that is its inorder successor. If a node VV does not have an inorder successor, then Suc(V)Suc(V) is NULLNULL. As there are no duplicates, if Suc(V)Suc(V) is not NULLNULL, then Val(V)<Val(Suc(V))Val(V) < Val(Suc(V)).

Corresponding to every leaf node LiL_i that has a non-NULLNULL Suc(Li)Suc(L_i), a new key kik_i with the following property is to be inserted into the BST.

Val(Li)<ki<Val(Suc(Li))Val(L_i) < k_i < Val(Suc(L_i))

Let KK represent the list of all such new keys to be inserted into the BST.

Which of the following statements is/are true?
More than one option can be correct.
Show answer without attempting

Answer: A, C

Q50

GATE CS 2026 CS-2Linear Data StructuresMSQ2 marks
Consider a stack SS and a queue QQ. Both of them are initially empty and have the capacity to store ten elements each. The elements 1, 2, 3, 4, and 5 arrive one by one, in that order. When an element arrives, it is assigned either to SS (pushed on SS) or to QQ (enqueued to QQ). Once all the five elements are stored, the output is generated in two steps. First, stack S is emptied by popping all elements. Then queue QQ is emptied by dequeueing all elements. The output obtained by following this process is 4  3  1  2  54 \; 3 \; 1 \; 2 \; 5.

Given the output, the objective is to predict whether an element was assigned to SS or QQ.

Which of the following options is/are possible valid assignment(s) of the elements?

Note: In the options, the notation xSxS denotes that element xx was assigned to SS and yQyQ denotes that element yy was assigned to QQ.
More than one option can be correct.
Show answer without attempting

Answer: A, B

Q60

GATE CS 2026 CS-2C ProgrammingNAT2 marks
Consider the following ANSI-C program.
#include <stdio.h>
int main(){
 int *ptr, a, b, c;
 a=5; b=11; c=20;
 ptr=&a; *ptr=c; ptr=&c;
 a=*(&b); c=*ptr-a;
 printf("%d",c);
 return(0);
}
The output of this program is ____________. (answer in integer)

Note: Assume that the program compiles and runs successfully.
Show answer without attempting

Answer: 9

Q61

GATE CS 2026 CS-2RecursionNAT2 marks
Consider the following ANSI-C function.
int func(int start, int end){
 int length=end+1-start;
 if((length<1)||(start<0)||(end<0)){ return(0); }
 if(length%3==0){
 return(func(start+1, end));
 } else if(length%3==1){
 return(1+func(start, end-1));
 } else {
 return(func(start+2, end));
 }
}
The maximum possible value that can be returned from this function is ____________. (answer in integer)

Note: Ignore syntax errors (if any) in the function.
Show answer without attempting

Answer: 1

0/140 correct0 marks

Related topics in GATE CS