Q6
Let be a binary search tree with nodes. The minimum and maximum possible heights of are:
Note: The height of a tree with a single node is 0.
Note: The height of a tree with a single node is 0.
Show answer without attempting
Answer: B
GATE CS · 14 questions
14 Programming and Data Structures questions from GATE CS papers (2017), each with the official answer key. Answer any question right here and it is marked straight away, or practise them one at a time.
Answer: B
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;
}Answer: B
#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);
}Answer: D
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);
}Answer: A
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;
}Answer: C
#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);
}Answer: 3.0
#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);
}Answer: 23.0
static char var;m = malloc(10); m = NULL;char *ptr[10];register int var1;Answer: A
Answer: B
void printxy(int x, int y) {
int *ptr;
x = 0;
ptr = &x;
y = *ptr;
*ptr = 1;
printf("%d,%d", x, y);
}printxy(1, 1) isAnswer: C
Answer: B
while (r >= y) {
r = r - y;
q = q + 1;
}Answer: C
#include <stdio.h>
int main() {
int m = 10;
int n, n1;
n = ++m;
n1 = m++;
n--;
--n1;
n -= n1;
printf("%d", n);
return 0;
}Answer: 0.0
#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;
}Answer: 2.0
0/140 correct0 marks