Programming and Data Structures questions

Q6

GATE CS 2017 CS-1Tree Data StructuresMCQ1 mark−1/3 if wrong
Let TT be a binary search tree with 1515 nodes. The minimum and maximum possible heights of TT are:
Note: The height of a tree with a single node is 0.
Show answer without attempting

Answer: B

Q8

GATE CS 2017 CS-1Linear Data StructuresMCQ1 mark−1/3 if wrong
Consider the C code fragment given below.
typedef struct node {
    int data;
    node* next;
} node;

void join(node* m, node* n) {
    node* p = n;
    while (p->next != NULL) {
        p = p->next;
    }
    p->next = m;
}
Assuming that mm and nn point to valid NULL-terminated linked lists, invocation of join will
Show answer without attempting

Answer: B

Q13

GATE CS 2017 CS-1C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C code:
#include <stdio.h>
int *assignval(int *x, int val) {
    *x = val;
    return x;
}

void main () {
    int *x = malloc(sizeof(int));
    if (NULL == x) return;
    x = assignval(x, 0);
    if (x) {
        x = (int *)malloc(sizeof(int));
        if (NULL == x) return;
        x = assignval(x, 10);
    }
    printf("%d\n", *x);
    free(x);
}
The code suffers from which one of the following problems:
Show answer without attempting

Answer: D

Q35

GATE CS 2017 CS-1RecursionMCQ2 marks−2/3 if wrong
Consider the following two functions.
void fun1(int n) {
    if (n == 0) return;
    printf("%d", n);
    fun2(n - 2);
    printf("%d", n);
}

void fun2(int n) {
    if (n == 0) return;
    printf("%d", n);
    fun1(++n);
    printf("%d", n);
}
The output printed when fun1(5) is called is
Show answer without attempting

Answer: A

Q36

GATE CS 2017 CS-1RecursionMCQ2 marks−2/3 if wrong
Consider the C functions foo and bar given below:
int foo(int val) {
    int x = 0;
    while(val > 0) {
        x = x + foo(val--);
    }
    return val;
}

int bar(int val) {
    int x = 0;
    while(val > 0) {
        x = x + bar(val-1);
    }
    return val;
}
Invocations of foo(3) and bar(3) will result in:
Show answer without attempting

Answer: C

Q53

GATE CS 2017 CS-1C ProgrammingNAT2 marks
Consider the following C program.
#include <stdio.h>
#include <string.h>

void printlength(char *s, char *t) {
    unsigned int c = 0;
    int len = ((strlen(s) - strlen(t)) > c) ? strlen(s): strlen(t);
    printf("%d\n", len);
}

void main() {
    char *x = "abc";
    char *y = "defgh";
    printlength(x,y);
}
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 without attempting

Answer: 3.0

Q55

GATE CS 2017 CS-1C ProgrammingNAT2 marks
The output of executing the following C program is ____________.
#include <stdio.h>

int total(int v) {
    static int count = 0;
    while(v) {
        count += v&1;
        v >>= 1;
    }
    return count;
}

void main() {
    static int x = 0;
    int i = 5;
    for(; i > 0; i--) {
        x = x + total(i);
    }
    printf("%d\n", x);
}
Show answer without attempting

Answer: 23.0

Q2

GATE CS 2017 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Match the following:

(P) static char var;
(Q) m = malloc(10); m = NULL;
(R) char *ptr[10];
(S) register int var1;

(i) Sequence of memory locations to store addresses
(ii) A variable located in data section of memory
(iii) Request to allocate a CPU register to store data
(iv) A lost memory which cannot be freed
Show answer without attempting

Answer: A

Q13

GATE CS 2017 CS-2Linear Data StructuresMCQ1 mark−1/3 if wrong
A 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)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.
Show answer without attempting

Answer: B

Q14

GATE CS 2017 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following function implemented in C:
void printxy(int x, int y) {
    int *ptr;
    x = 0;
    ptr = &x;
    y = *ptr;
    *ptr = 1;
    printf("%d,%d", x, y);
}
The output of invoking printxy(1, 1) is
Show answer without attempting

Answer: C

Q36

GATE CS 2017 CS-2Tree Data StructuresMCQ2 marks−2/3 if wrong
The pre-order traversal of a binary search tree is given by 12,8,6,2,7,9,10,16,15,19,17,2012, 8, 6, 2, 7, 9, 10, 16, 15, 19, 17, 20. Then the post-order traversal of this tree is:
Show answer without attempting

Answer: B

Q37

GATE CS 2017 CS-2C ProgrammingMCQ2 marks−2/3 if wrong
Consider the C program fragment below which is meant to divide xx by yy using repeated subtractions. The variables x,y,qx, y, q and rr are all unsigned int.
while (r >= y) {
    r = r - y;
    q = q + 1;
}
Which of the following conditions on the variables x,y,qx, y, q and rr before the execution of the fragment will ensure that the loop terminates in a state satisfying the condition x == (y*q + r)?
Show answer without attempting

Answer: C

Q54

GATE CS 2017 CS-2C ProgrammingNAT2 marks
Consider the following C Program.
#include <stdio.h>
int main() {
    int m = 10;
    int n, n1;
    n = ++m;
    n1 = m++;
    n--;
    --n1;
    n -= n1;
    printf("%d", n);
    return 0;
}
The output of the program is ____________.
Show answer without attempting

Answer: 0.0

Q55

GATE CS 2017 CS-2C ProgrammingNAT2 marks
Consider the following C Program.
#include <stdio.h>
#include <string.h>
int main() {
    char* c = "GATECSIT2017";
    char* p = c;
    printf("%d", (int)strlen(c+2[p]-6[p]-1));
    return 0;
}
The output of the program is ____________.
Show answer without attempting

Answer: 2.0

0/140 correct0 marks

Related topics in GATE CS