VOOZH about

URL: https://www.geeksforgeeks.org/quizzes/recursion-gate-cs-pyq-quiz/

⇱ Quiz about Recursion GATE CS PYQ Quiz


Last Updated :
Discuss
Comments

Question 1

Consider the following ANSI C program

#include 
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 _________ .

  • 60

  • 10

  • 15

  • 50

Question 2

Consider the following code:

What output will be generated by the given code d\\segment if: 
Line 1 is replaced by “auto int a = 1;” 
Line 2 is replaced by “register int a = 2;” (GATE CS 2012) 

  • 3 1

    4 1

    4 2

  • 4 2

    6 1

    6 1

  • 4 2

    6 2

    2 0

  • 4 2

    4 2

    2 0

Question 3

Consider the above question. What output will be generated by the given code d\\segment if:
Line 1 is replaced by “auto int a = 1;
Line 2 is replaced by “register int a = 2;

  • 3 1
    4 1
    4 2
  •  4 2
    6 1
    6 1
  • 4 2
    6 2
    2 0
  • 4 2
    4 2
    2 0

Question 4

Consider the following C program

What output will be generated by the given code segment?

  • 3 1
    4 1
    4 2
  • 4 2
    6 1
    6 1
  • 4 2
    6 2
    2 0
  • 3 1
    5 2
    5 2

Question 5

The height of a tree is defined as the number of edges on the longest path in the tree. The function shown in the pseudocode below is invoked as height (root) to compute the height of a binary tree rooted at the tree pointer root. 

👁 Image


The appropriate expression for the two boxes B1 and B2 are

  • B1 : (1 + height(n->right)), B2 : (1 + max(h1,h2))

  • B1 : (height(n->right)), B2 : (1 + max(h1,h2))

  • B1 : height(n->right), B2 : max(h1,h2)

  • B1 : (1 + height(n->right)), B2 : max(h1,h2)

Question 6

Consider the following function written in the C programming language. The output of the above function on input “ABCD EFGH” is

  • ABCD EFGH

  • ABCD

  • HGFE DCBA

  • DCBA

Question 7

Consider the following program:

Note: max(x,y) returns the maximum of x and y. The value printed by this program is

  • 2

  • 3

  • 4

  • 5

Question 8

What will be the output of the following JAVA program? 

  • 3 1 2 2 1 3 4 4 4

  • 3 1 2 1 1 1 2 2 2

  • 3 1 2 2 1 3 4

  • 3 1 2 1 1 1 2

Question 9

Consider the following recursive C function. If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()? 

  • 15

  • 25

  • 35

  • 45

Question 10

Consider the following C function. 

The return value of fun(5) is __________.

  • 0

  • 26

  • 51

  • 71

There are 22 questions to complete.

Take a part in the ongoing discussion