Programming and Data Structures questions

Q10

GATE CS 2021 CS-1Tree Data StructuresMCQ1 mark−1/3 if wrong
A binary search tree TT contains nn distinct elements. What is the time complexity of picking an element in TT that is smaller than the maximum element in TT?
Show answer without attempting

Answer: D

Q21

GATE CS 2021 CS-1Linear Data StructuresNAT1 mark
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 without attempting

Answer: 86

Q37

GATE CS 2021 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following ANSI C program.
#include <stdio.h>
int main()
{
    int i, j, count;
    count = 0;
    i = 0;
    for (j = -3; j <= 3; j++)
    {
        if ((j >= 0) && (i++))
            count = count + j;
    }
    count = count + i;
    printf("%d", count);
    return 0;
}
Which one of the following options is correct?
Show answer without attempting

Answer: B

Q48

GATE CS 2021 CS-1C ProgrammingNAT2 marks
Consider the following ANSI C function:
int SimpleFunction(int Y[], int n, int x)
{
  int total = Y[0], loopIndex;
  for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)
       total = x * total + Y[loopIndex];
  return total;
}
Let Z be an array of 10 elements with Z[ii]=1, for all ii such that 0≤i≤90 \le i \le 9. The value returned by SimpleFunction(Z, 10, 2) is ______.
Show answer without attempting

Answer: 1023

Q2

GATE CS 2021 CS-2Tree Data StructuresMCQ1 mark−1/3 if wrong
Let HH be a binary min-heap consisting of nn elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the maximum element in HH?
Show answer without attempting

Answer: C

Q10

GATE CS 2021 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following ANSI C program:
#include <stdio.h>
int main(){
    int arr[4][5];
    int i, j;
    for (i=0; i<4; i++){
        for (j=0; j<5; j++){
            arr[i][j] = 10*i + j;
        }
    }
    printf("%d", *(arr[1] + 9));
    return 0;
}
What is the output of the above program?
Show answer without attempting

Answer: C

Q16

GATE CS 2021 CS-2Tree Data StructuresNAT1 mark
Consider a complete binary tree with 7 nodes. Let AA denote the set of first 3 elements obtained by performing Breadth-First Search (BFS) starting from the root. Let BB denote the set of first 3 elements obtained by performing Depth-First Search (DFS) starting from the root.
The value of ∣A−B∣|A - B| is ____________.
Show answer without attempting

Answer: 1

Q23

GATE CS 2021 CS-2RecursionNAT1 mark
Consider the following ANSI C function:
int SomeFunction(int x, int y)
{
    if ((x == 1) || (y == 1)) return 1;
    if (x == y) return x;
    if (x > y) return SomeFunction(x - y, y);
    if (y > x) return SomeFunction(x, y - x);
}
The value returned by SomeFunction(15, 255) is ____________.
Show answer without attempting

Answer: 15

Q35

GATE CS 2021 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following ANSI C program:
#include <stdio.h>
#include <stdlib.h>
struct Node{
    int value;
    struct Node *next;
};
int main(){
    struct Node *boxE, *head, *boxN; int index = 0;
    boxE = head = (struct Node *) malloc(sizeof(struct Node));
    head->value = index;
    for (index = 1; index <= 3; index++){
        boxN = (struct Node *) malloc(sizeof(struct Node));
        boxE->next = boxN;
        boxN->value = index;
        boxE = boxN; }
    for (index = 0; index <= 3; index++) {
        printf("Value at index %d is %d\n", index, head->value);
        head = head->next;
        printf("Value at index %d is %d\n", index+1, head->value); }
}
Which one of the statements below is correct about the program?
Show answer without attempting

Answer: D

Q49

GATE CS 2021 CS-2RecursionNAT2 marks
Consider the following ANSI C program:
#include <stdio.h>
int foo(int x, int y, int q)
{
    if ((x <= 0) && (y <= 0))
        return q;
    if (x <= 0)
        return foo(x, y-q, q);
    if (y <= 0)
        return foo(x-q, y, q);
    return foo(x, y-q, q) + foo(x-q, y, q);
}
int main()
{
    int r = foo(15, 15, 10);
    printf("%d", r);
    return 0;
}
The output of the program upon execution is ____________.
Show answer without attempting

Answer: 60

0/100 correct0 marks

Related topics in GATE CS