Programming and Data Structures questions

Q26

GATE CS 2025 CS-1Tree Data StructuresMSQ1 mark
Which of the following statement(s) is/are TRUE for any binary search tree (BST) having nn distinct integers?
More than one option can be correct.
Show answer without attempting

Answer: A, B

Q34

GATE CS 2025 CS-1C ProgrammingNAT1 mark
#include <stdio.h>
void foo(int *p, int x){
 *p=x;
}
int main(){
 int *z;
 int a = 20, b = 25;
 z = &a;
 foo(z,b);
 printf("%d",a);
 return 0;
}
The output of the given C program is __________. (Answer in integer)
Show answer without attempting

Answer: 25

Q35

GATE CS 2025 CS-1Tree Data StructuresNAT1 mark
The height of any rooted tree is defined as the maximum number of edges in the path from the root node to any leaf node.
Suppose a Min-Heap TT stores 32 keys. The height of TT is _____________. (Answer in integer)
Show answer without attempting

Answer: 5

Q61

GATE CS 2025 CS-1RecursionNAT2 marks
#include <stdio.h>
int foo(int S[],int size){
 if(size == 0) return 0;
 if(size == 1) return 1;
 if(S[0] != S[1]) return 1+foo(S+1,size-1);
 return foo(S+1,size-1);
}
int main(){
 int A[]={0,1,2,2,2,0,0,1,1};
 printf("%d",foo(A,9));
 return 0;
}
The value printed by the given C program is _______ . (Answer in integer)
Show answer without attempting

Answer: 5

Q62

GATE CS 2025 CS-1Linear Data StructuresNAT2 marks
Let LIST be a datatype for an implementation of linked list defined as follows:
typedef struct list {
 int data;
 struct list *next;
} LIST;
Suppose a program has created two linked lists, L1 and L2, whose contents are given in the figure below (code for creating L1 and L2 is not provided here). L1 contains 9 nodes, and L2 contains 7 nodes.

Consider the following C program segment that modifies the list L1. The number of nodes that will be there in L1 after the execution of the code segment is ________ . (Answer in integer)
int find (int query, LIST *list) {
 while (list != NULL){
 if(list->data == query) return 1;
 list = list->next;
 }
 return 0;
}
int main () {

 ptr1=L1; ptr2=L2;
 while (ptr1->next != NULL){
 query = ptr1->next->data;
 if (find (query, L2))
 ptr1->next = ptr1->next->next;
 else ptr1 = ptr1->next;
 }

 return 0;
}
Question figure
Show answer without attempting

Answer: 5

Q63

GATE CS 2025 CS-1C ProgrammingNAT2 marks
Consider the following C program:
#include <stdio.h>
int gate (int n) {
 int d, t, newnum, turn;
 newnum = turn = 0; t=1;
 while (n>=t) t *= 10;
 t /=10;
 while (t>0) {
 d = n/t;
 n = n%t;
 t /= 10;
 if (turn) newnum = 10*newnum + d;
 turn = (turn + 1) % 2;
 }
 return newnum;
}
int main () {
 printf ("%d", gate(14362));
 return 0;
}
The value printed by the given C program is _______ . (Answer in integer)
Show answer without attempting

Answer: 46

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

0/140 correct0 marks

Related topics in GATE CS