Programming and Data Structures questions

Q2

GATE CS 2018 CSC ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program.
#include<stdio.h>
struct Ournode{
 char x,y,z;
};
int main(){
 struct Ournode p = {'1', '0', 'a'+2};
 struct Ournode *q = &p;
 printf ("%c, %c", *((char*)q+1), *((char*)q+2));
 return 0;
}
The output of this program is:
Show answer without attempting

Answer: A

Q3

GATE CS 2018 CSLinear Data StructuresMCQ1 mark−1/3 if wrong
A queue is implemented using a non-circular singly linked list. The queue has a head pointer and a tail pointer, as shown in the figure. Let nn denote the number of nodes in the queue. Let enqueue be implemented by inserting a new node at the head, and dequeue be implemented by deletion of a node from the tail.

Which one of the following is the time complexity of the most time-efficient implementation of enqueue and dequeue, respectively, for this data structure?
Question figure
Show answer without attempting

Answer: B

Q20

GATE CS 2018 CSTree Data StructuresNAT1 mark
The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,18,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,6,9,4,7,2,5,1,38,6,9,4,7,2,5,1,3. The height of a tree is the length of the longest path from the root to any leaf. The height of the binary tree above is ______.
Show answer without attempting

Answer: 4

Q21

GATE CS 2018 CSRecursionNAT1 mark
Consider the following C program:
#include <stdio.h>
int counter = 0;
int calc (int a, int b) {
 int c;
 counter++;
 if (b==3) return (a*a*a);
 else {
 c = calc(a, b/3);
 return (c*c*c);
 }
}
int main (){
 calc(4, 81);
 printf ("%d", counter);
}
The output of this program is _____.
Show answer without attempting

Answer: 4

Q29

GATE CS 2018 CSC ProgrammingMCQ2 marks−2/3 if wrong
Consider the following C program:
#include<stdio.h>
void fun1(char *s1, char *s2){
char *tmp;
tmp = s1;
s1 = s2;
s2 = tmp;
}
void fun2(char **s1, char **s2){
char *tmp;
tmp = *s1;
*s1 = *s2;
*s2 = tmp;
}
int main(){
char *str1 = "Hi", *str2 = "Bye";
fun1(str1, str2); printf("%s %s ", str1, str2);
fun2(&str1, &str2); printf("%s %s", str1, str2);
return 0;
}
The output of the program above is
Show answer without attempting

Answer: A

Q32

GATE CS 2018 CSRecursionMCQ2 marks−2/3 if wrong
Consider the following C code. Assume that unsigned long int type length is 64 bits.
unsigned long int fun(unsigned long int n){
 unsigned long int i, j = 0, sum = 0;
 for (i = n; i > 1; i = i/2) j++;
 for ( ; j > 1; j = j/2) sum++;
 return(sum);
}
The value returned when we call fun with the input 2402^{40} is
Show answer without attempting

Answer: B

Q45

GATE CS 2018 CSRecursionNAT2 marks
Consider the following program written in pseudo-code. Assume that x and y are integers.
Count(x,y) {
 if (y != 1){
 if (x != 1) {
 print("*");
 Count(x/2, y);
 }
 else {
 y = y-1;
 Count(1024, y);
 }
 }
}
The number of times that the print statement is executed by the call Count(1024,1024) is _____.
Show answer without attempting

Answer: 10230

Q46

GATE CS 2018 CSTree Data StructuresNAT2 marks
The number of possible min-heaps containing each value from {1,2,3,4,5,6,7}\{1, 2, 3, 4, 5, 6, 7\} exactly once is _____.
Show answer without attempting

Answer: 80

0/80 correct0 marks

Related topics in GATE CS