Programming and Data Structures questions — page 2 of 9

Q13

GATE CS 2025 CS-2Tree Data StructuresMCQ1 mark−1/3 if wrong
Consider a binary tree TT in which every node has either zero or two children. Let n>0n > 0 be the number of nodes in TT.

Which ONE of the following is the number of nodes in TT that have exactly two children?
Show answer without attempting

Answer: B

Q19

GATE CS 2025 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
    char a[30] = "@#Hello World!";
    stringcopy(a, a + 2);
    printf("%s\n", a);
    return 0;
}
void stringcopy(char *s, char *t) {
    while(*t)
        *s++ = *t++;
}
Which ONE of the following will be the output of the program?
Show answer without attempting

Answer: D

Q33

GATE CS 2025 CS-2C ProgrammingNAT1 mark
 int x=126,y=105;
 do {
 if(x>y) x=x-y;
 else y=y-x;
 } while(x!=y);
 printf("%d",x);
The output of the given C code segment is ________. (Answer in integer)
Show answer without attempting

Answer: 21

Q35

GATE CS 2025 CS-2Tree Data StructuresNAT1 mark
Suppose the values 10,−4,15,30,20,5,60,1910, -4, 15, 30, 20, 5, 60, 19 are inserted in that order into an initially empty binary search tree. Let TT be the resulting binary search tree.
The number of edges in the path from the node containing 19 to the root node of TT is ___________. (Answer in integer)
Show answer without attempting

Answer: 4

Q38

GATE CS 2025 CS-2Linear Data StructuresMCQ2 marks−2/3 if wrong
A meld operation on two instances of a data structure combines them into one single instance of the same data structure. Consider the following data structures:

P: Unsorted doubly linked list with pointers to the head node and tail node of the list.
Q: Min-heap implemented using an array.
R: Binary Search Tree.

Which ONE of the following options gives the worst-case time complexities for meld operation on instances of size nn of these data structures?
Show answer without attempting

Answer: A

Q45

GATE CS 2025 CS-2Linear Data StructuresMSQ2 marks
Consider a stack data structure into which we can PUSH and POP records. Assume that each record pushed in the stack has a positive integer key and that all keys are distinct.

We wish to augment the stack data structure with an O(1)O(1) time MIN operation that returns a pointer to the record with smallest key present in the stack
1) without deleting the corresponding record, and
2) without increasing the complexities of the standard stack operations.

Which one or more of the following approach(es) can achieve it?
More than one option can be correct.
Show answer without attempting

Answer: A

Q62

GATE CS 2025 CS-2C ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int main(){
    int a;
    int arr[5] = {30,50,10};
    int *ptr;
    ptr = &arr[0] + 1;
    a = *ptr;
    (*ptr)++;
    ptr++;
    printf("%d", a + (*ptr) + arr[1]);
    return 0;
}
The output of the above program is ___________. (Answer in integer)
Show answer without attempting

Answer: 111

Q63

GATE CS 2025 CS-2RecursionNAT2 marks
Consider the following C program:
#include <stdio.h>
int g(int n) {
    return (n+10);
}
int f(int n) {
    return g(n*2);
}
int main() {
    int sum, n;
    sum=0;
    for (n=1; n<3; n++)
        sum += g(f(n));
    printf ("%d", sum);
    return 0;
}
The output of the given C program is ________. (Answer in integer)
Show answer without attempting

Answer: 46

Q18

GATE CS 2024 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
int main(){
 int a = 6;
 int b = 0;
 while(a < 10) {
 a = a / 12 + 1;
 a += b;
 }
 printf("%d", a);
 return 0;
}
Which one of the following statements is CORRECT?
Show answer without attempting

Answer: C

Q19

GATE CS 2024 CS-1RecursionMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
void fX();
int main(){
fX();
return 0;
}
------------------------
void fX(){
char a;
if((a=getchar()) != '\n')
fX();
if(a != '\n')
putchar(a);
}
Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT?
Show answer without attempting

Answer: C

Q41

GATE CS 2024 CS-1Tree Data StructuresMCQ2 marks−2/3 if wrong
An array [82, 101, 90, 11, 111, 75, 33, 131, 44, 93] is heapified. Which one of the following options represents the first three elements in the heapified array?
Show answer without attempting

Answer: D

Q43

GATE CS 2024 CS-1Tree Data StructuresMCQ2 marks−2/3 if wrong
Consider a binary min-heap containing 10510^5 distinct elements. Let kk be the index (in the underlying array) of the maximum element stored in the heap. The number of possible values of kk is
Show answer without attempting

Answer: A

Q48

GATE CS 2024 CS-1C ProgrammingMSQ2 marks
Consider the following C function definition.
int f(int x, int y) {
 for (int i=0; i<y; i++) {
 x=x+x+y;
 }
 return x;
}
Which of the following statements is/are TRUE about the above function?
More than one option can be correct.
Show answer without attempting

Answer: B, D

Q13

GATE CS 2024 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program. Assume parameters to a function are evaluated from right to left.
#include <stdio.h>
int g(int p) { printf("%d", p); return p; }
int h(int q) { printf("%d", q); return q; }
void f(int x, int y) {
    g(x);
    h(y);
}
int main() {
    f(g(10),h(20));
}
Which one of the following options is the CORRECT output of the above C program?
Show answer without attempting

Answer: A

Q17

GATE CS 2024 CS-2Graph Data StructuresMCQ1 mark−1/3 if wrong
Let AA be the adjacency matrix of a simple undirected graph GG. Suppose AA is its own inverse. Which one of the following statements is always TRUE?
Show answer without attempting

Answer: B

Q33

GATE CS 2024 CS-2C ProgrammingMSQ1 mark
Consider the following C function definition.
int fX(char *a){
    char *b = a;
    while(*b)
        b++;
    return b - a;
}
Which of the following statements is/are TRUE?
More than one option can be correct.
Show answer without attempting

Answer: A, B, D

Q35

GATE CS 2024 CS-2Linear Data StructuresNAT1 mark
Let AA be an array containing integer values. The distance of AA is defined as the minimum number of elements in AA that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2,5,3,1,4,2,6][2, 5, 3, 1, 4, 2, 6] is ___________
Show answer without attempting

Answer: 3

Q36

GATE CS 2024 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
What is the output of the following C program?
#include <stdio.h>
int main() {
    double a[2]={20.0, 25.0}, *p, *q;
    p = a;
    q = p + 1;
    printf("%d,%d", (int)(q - p), (int)(*q - *p));
    return 0;
}
Show answer without attempting

Answer: B

Q39

GATE CS 2024 CS-2Tree Data StructuresMCQ2 marks−2/3 if wrong
You are given a set VV of distinct integers. A binary search tree TT is created by inserting all elements of VV one by one, starting with an empty tree. The tree TT follows the convention that, at each node, all values stored in the left subtree of the node are smaller than the value stored at the node. You are not aware of the sequence in which these values were inserted into TT, and you do not have access to TT.

Which one of the following statements is TRUE?
Show answer without attempting

Answer: A

Q42

GATE CS 2024 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider an array X that contains n positive integers. A subarray of X is defined to be a sequence of array locations with consecutive indices.

The C code snippet given below has been written to compute the length of the longest subarray of X that contains at most two distinct integers. The code has two missing expressions labelled (P)(P) and (Q)(Q).
int first=0, second=0, len1=0, len2=0, maxlen=0;
for (int i=0; i < n; i++) {
    if (X[i] == first) {
        len2++; len1++;
    } else if (X[i] == second) {
        len2++;
        len1 = (P) ;
        second = first;
    } else {
        len2 = (Q) ;
        len1 = 1; second = first;
    }
    if (len2 > maxlen) {
        maxlen = len2;
    }
    first = X[i];
}
Which one of the following options gives the CORRECT missing expressions?

(Hint: At the end of the i-th iteration, the value of len1 is the length of the longest subarray ending with X[i] that contains all equal values, and len2 is the length of the longest subarray ending with X[i] that contains at most two distinct values.)
Show answer without attempting

Answer: B

0/200 correct0 marks

Related topics in GATE CS