Question: Lab Exercises Chapter 5 - Recursion Lab Objective: To practice the students on how to write a recursive method; compare between a recursive and a

Lab Exercises
Chapter 5- Recursion
Lab Objective: To practice the students on how to write a recursive method;
compare between a recursive and a none recursive definition of the
same method.
Q1) Write a class factorial that contains a recursive and a non-recursive methods to return the
factorial of a given number.
Where the factorial of n is calculated using the following law
11
nn**(n-1)! for n>1.
Q2) Write a class PalindromeCheck that contains a recursive and a non-recursive methods to
check a given string input is palindrome or not.
Where a string is palindrome if it can be read from left to right as it can be read from right to
left. e.g. AdA is palindrome
rrrrrrrrrrrr is palindrome
salsa is not palindrome
hhhtthhh is palindrome
ABCDEDCBA is palindrome
Q3) Write a class ReverseString that contains a recursive and a non-recursive methods to
reverse a given string.
input output
abcd dcba
Ahmed demha
Q4) Write a class Fibonacci that contains a recursive and a non-recursive methods to
calculate the fibonacci number n for a given input n.
Where Fibonacci is the sequence of numbers
1,1,2,3,5,8,13,21dots..
which is governed by the following law
Fib(1)=1
Fib(2)=1
Fib(n)=Fib(n-1)+Fib(n-2)
 Lab Exercises Chapter 5- Recursion Lab Objective: To practice the students

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!