QuestionPapersHub.com

Programming and Data Structures (PDS)

GATE-2019

Q:   Consider the following C program: The value printed by the program is ________.

content
GATE-2019

Q:   Consider the following C program:

#include
int main(){
int arr[]={1,2,3,4,5,6,7,8,9,0,1,2,5}, *ip=arr+4;
printf(“%d\n”, ip[1]);
return 0;

The number that will be displayed on execution of the program is ___________ . }

GATE-2019

Q:   Consider the following C function.

void convert(int n){
if(n<0)
printf(“%d”,n);
else {
convert(n/2);
printf(“%d”,n%2);
}
}

Which one of the following will happen when the function convert is called with any positive integer n as argument?

  • A:  It will print the binary representation of n and terminate
  • B:  It will print the binary representation of n in the reverse order and terminate
  • C:  It will print the binary representation of n but will not terminate
  • D:  It will not print anything and will not terminate
GATE-2019

Q:   Consider the following C program:

#include
int r(){
static int num=7;
return num--;
}
int main(){
for (r();r();r())
printf(“%d”,r());
return 0;
}

Which one of the following values will be displayed on execution of the programs?

  • A:  41
  • B:  52
  • C:  63
  • D:  630
GATE-2019

Q:   Consider the following statements:
I. The smallest element in a max-heap is always at a leaf node
II. The second largest element in a max-heap is always a child of the root node
III. A max-heap can be constructed from a binary search tree in Θ(n) time
IV. A binary search tree can be constructed from a max-heap in Θ(n) time
Which of the above statements are TRUE?

  • A:  I, II and III
  • B:  I, II and IV
  • C:  I, III and IV
  • D:  II, III and IV
GATE-2019

Q:   Let T be a full binary tree with 8 leaves. (A full binary tree has every level full.) Suppose two leaves a and b of T are chosen uniformly and independently at random. The expected value of the distance between a and b in T (i.e., the number of edges in the unique path between a and b) is (rounded off to 2 decimal places) .

GATE-2018

Q:   Consider the following C program:


#include
int main(){
float sum = 0.0, j = 1.0, i = 2.0;
while (i/j > 0.0625){
j = j + j;
sum = sum + i/j;
printf("%f\n", sum);
}
return 0;
}

The number of times the variable sum will be printed, when the above program is executed, is _________________.

GATE-2019

Q:   Consider the following C program:


#include
int main()
{
int a[ ] = {2, 4, 6, 8, 10};
int i, sum = 0, *b = a + 4;
for (i = 0; i < 5; i++)
sum = sum + (*b – i) – *(b – i);
printf (“%d\n”, sum);
return 0;
}

The output of the above C program is __________.

GATE-2018

Q:   Consider the following C program.

#include
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:

  • A:  0, c
  • B:  0, a+2
  • C:  '0', 'a+2'
  • D:  '0', 'c'
GATE-2018

Q:   The postorder traversal of a binary tree is 8,9,6,7,4,5,2,3,1. The inorder traversal of the same tree is 8,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 ______.

1