Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
22 views2 pages

Recursion

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

1.

Write a function using recursion that takes in a string and returns


a reversed copy of the string. The only string operation you are
allowed to use is string concatenation.

2. Write algorithm and Python coding for a recursive function that


computes the following equation:

𝑛!
𝐶𝑘𝑛 =
𝑘! (𝑛 − 𝑘)!

3. Write a recursive function that takes in one argument n and


computes 𝐹𝑛 , the 𝑛𝑡ℎ value of the Fibonacci sequence. Recall that
the Fibonacci sequence is defined by the relation:

𝐹𝑛 = 𝐹𝑛1 + 𝐹𝑛2
Where:
𝐹0 = 0 and 𝐹1 =1

4. Write a recursive Python function that has a parameter


representing a list of integers and returns the maximum stored in
the list. Thinking recursively, the maximum is either the first value
in the list or the maximum of the rest of the list, whichever is
larger. If the list only has 1 integer, then its maximum is this
single value, naturally.

5. Write a Python program to calculate the harmonic sum of n-1.


Note: The harmonic sum is the sum of reciprocals of the positive
integers.
Example :

1 1 1 1
∑ = 1+ + + +⋯
𝑛 2 3 4
𝑛=1
6. Greatest Common Divisor(GCD) of 2 Numbers

The most significant positive number is GCD of two or more


integers that each of the integers is divisible, i.e., it is the most
significant number that divides both of them. Thus, simply
factorizing both numbers and multiplying common prime factors
will give GCD.

7. Write a recursive function that accepts a decimal integer and


display its binary equivalent.

8. Compute the sum of all numbers between 1 and any positive


integer N.

9. Let us consider the case of raising a real number, a, to a


nonnegative integer power, b. “𝑎𝑏 ”

10. Design a function that accepts a list of numbers as an argument.


The function should recursively calculate the sum of the numbers
in the list and return that value.

11. Design a function that accepts a string as an argument. Assume


that the string will contain a single word. The function should use
recursion to determine whether the word is a palindrome (a word
that reads the same backwards as forward). Hint: Use string
slicing to refer to and compare the characters on either end of the
string.

12. Find sum of factorials till N factorial (1! + 2! + 3! + … + N!)

13. Write a python program that check if number is prime or not


(Using Recursion).

You might also like