Recursion || Important Questions || Sumita-Arora || Preeti-Arora || Computer Science || Class 12
Q. What is recursion?
Q. What are the two cases required in a recursive function?
Q. What are the base case and recursive case? What is their role in a recursive program?
Q. When does infinite recursion occur?
Q. Differentiate between iteration and recursion.
Q. Why are recursive functions considered slower than their iterative counterparts?
Q. State one advantage and one disadvantage of using recursion over iteration.
Q. Compare and contrast the use of iteration and recursion in terms of memory space and speed.
Q. Write recursive code to compute and print sum of squares of n numbers. Value of n is passed as parameter
Q. Write a program to display first four multiples of a number using recursion.
Q. Write recursive code to compute the greatest common divisor of two numbers.
Q. A happy number is a number in which the eventual sum of the square of the digits of the number is equal to 1.
Example : 12 = (1)2+(2)2 =1+4=5
Hence, 12 is not a happy number
Example 100 = (1)2 + ( 0 )2 + ( 0 )2 = 1+ 0 + 0 = 1 Hence, 100 is a happy number.
Write a program that takes a number and checks if it is a happy number by using following two functions in it :
Sum_sq_digits :returns the sum of the square of the digits of the number x, using the recursive technique
Ishappy() : checks if the given number is a happy number by calling the function sum_sq_digits and displays an appropriate message
Q . A Geometric Progression (GP) is a progression where the each term is a multiple of the previous one. The multiplying
factor is called the common ratio.
So a GP with a first term a and a common ratio r with n terms, can be stated as:
a, ar, ar2, ar³, ar4…. arn-1
(a) Write a recursive function that prints a GP. Input a, r and n in_main_part..
(b) Write a recursive function that calculates the sum of a GP by changing the function that you wrote in part (a). Obtain a, r
and n in_main_ part. Highlight the changes that were made to get the desired result.
Q. Write a function that takes a number and tests if it is a prime number using recursion technique.
Q. The hailstone sequence starting at a positive integer n is generated by following two simple rules. If n even, the next
number in the sequence is n/ 2. If n is odd, the next number in the sequence is 3*n+1 Repeating this process, the hailstone
sequence gets generated. Write a recursive function hailstone ( n) Which prints the hailstone sequence beginning at 1. Stop
when the sequence reaches the number 1 (since otherwise, we would loop forever 1, 4, 2, 1, 4, 2, ….) .
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )