Questions

M.C.Q

🎯

Test yourself on this topic

15 questions · timed · auto-graded

MCQ 21 Mark
What does the following function print for n = 25?

  • A
    11001
  • 10011
  • C
    11111
  • D
    0
Answer
Correct option: B.
10011
(b) 10011
View full question & answer
MCQ 31 Mark
Consider the following recursive function fun(x, y). What is the value of fun(4, 3)?

  • 13
  • B
    12
  • C
    9
  • D
    10
Answer
Correct option: A.
13
(a) 13
View full question & answer
MCQ 51 Mark
What is the output of the following piece of code?

  • A
    0 1 2 3
  • B
    An exception is thrown
  • C
    0 1 1 2 3
  • 0 1 1 2
Answer
Correct option: D.
0 1 1 2
(d) Explanation: The above piece of code prints the Fibonacci series.
View full question & answer
MCQ 61 Mark
Which of these is not true about recursion?
  • A
    Making the code look clean
  • B
    A complex task can be broken into sub-problems
  • Recursive calls take up less memory
  • D
    Sequence generation is easier than a nested iteration
Answer
Correct option: C.
Recursive calls take up less memory
(c) Explanation: Recursive calls take up a lot of memory and time as memory is taken up each time the function is called.
View full question & answer
MCQ 71 Mark
What happens if the base condition isn't defined in recursive programs?
  • Program gets into an infinite loop
  • B
    Program runs once
  • C
    Program runs n number of times where n is the argument given to the function
  • D
    An exception is thrown
Answer
Correct option: A.
Program gets into an infinite loop
(a) Explanation: The program will run until the system gets out of memory.
View full question & answer
MCQ 81 Mark
What is the output of the following piece of code?

  • A
    50
  • 100
  • C
    74 <
  • D
    Infinite loop
Answer
Correct option: B.
100
(b) Explanation: The fun(fun(n+11)) part of the code keeps executing until the value of n becomes greater than 100, after which n-5 is returned and printed.
View full question & answer
MCQ 91 Mark
Which of the following statement is false about recursion?

  • A
    Every recursive function must have a base case
  • B
    Infinite recursion can occur if the base case isn't properly mentioned
  • C
    A recursive function makes the code easier to understand
  • Every recursive function must have a return value
Answer
Correct option: D.
Every recursive function must have a return value
(d) Explanation: A recursive function needn't have a return value.
View full question & answer
MCQ 101 Mark
Observe the following piece of code?

  • A
    Both a() and b() aren't tail recursive
  • B
    Both a() and b() are tail recursive
  • b() is tail recursive but a() isn't
  • D
    a() is tail recursive but b() isn't
Answer
Correct option: C.
b() is tail recursive but a() isn't
(c) Explanation: A recursive function is tail recursive when recursive call is executed by the function in the last.
View full question & answer
MCQ 111 Mark
What is tail recursion?

  • A
    A recursive function that has two base cases
  • B
    A function where the recursive functions leads to an infinite loop
  • C
    A recursive function where the function doesn't return anything and just prints the values
  • A function where the recursive call is the last thing executed by the function
Answer
Correct option: D.
A function where the recursive call is the last thing executed by the function
(d) Explanation: A recursive function is tail recursive when recursive call is executed by the function in the last.
View full question & answer
MCQ 121 Mark
What is the output of the following code?

  • A
    0 1 1
  • 1 1 0
  • C
    3
  • D
    Infinite loop
Answer
Correct option: B.
1 1 0
(b) Explanation: The above code gives the binary equivalent of the number.
View full question & answer
MCQ 131 Mark
Fill in the line of code for calculating the factorial of a number.

  • num*fact(num-1)
  • B
    (num-1)*(num-2)
  • C
    num*(num-1)
  • D
    fact(num)*fact(num-1)
Answer
Correct option: A.
num*fact(num-1)
(a) Explanation: Suppose n=5 then, 5*4*3*2*1 is returned which is the factorial of 5.
View full question & answer
MCQ 141 Mark
Which of these is false about recursion?
  • A
    Recursive function can be replaced by a nonrecursive function
  • B
    Recursive functions usually take more memory space than non-recursive function
  • Recursive functions run faster than nonrecursive function
  • D
    Recursion makes programs easier to understand
Answer
Correct option: C.
Recursive functions run faster than nonrecursive function
(c) Recursive functions run faster than nonrecursive function
View full question & answer
MCQ 151 Mark
Which is the most appropriate definition for recursion?
  • A
    A function that calls itself
  • A function execution instance that calls another execution instance of the same function
  • C
    A class method that calls another class method
  • D
    An in-built method that is automatically called
Answer
Correct option: B.
A function execution instance that calls another execution instance of the same function
(b) A function execution instance that calls another execution instance of the same function
View full question & answer
M.C.Q - Computer Science STD 12 Commerce Questions - Vidyadip