
โ ๏ธRecursion
Q1: Head-Recursion
Q1: Head-Recursionvoid headRecursion(int count) {
// Base-Condition
if (count == 0)
return;
// Recursive Relation
headRecursion(count - 1);
// Processing
cout << count << " ";
}
// o/p = 1 2 3 4 5Q2: Tail-Recursion
Q2: Tail-Recursion
void tailRecursion(int count) {
// Base-Condition
if (count == 0)
return;
// Processing
cout << count << " ";
// Recursive Relation
tailRecursion(count - 1);
}
// o/p = 5 4 3 2 1Q3: Fibonacci Number
Q3: Fibonacci Number
Q5: SayDigits
Q5: SayDigitsQ6: isSorted-Array
Q6: isSorted-Array
Q8: Linear Search
Q8: Linear SearchDay-04 Recursion
Q9: Reverse String
Q9: Reverse String In this program, the recursiveFunc() function is called recursively until the base case is reached. The base case is when s > e. Therefore, the number of recursive calls made by the function is equal to half the length of the string. Hence, the time complexity of your program is O(n/2) or O(n) 1.
The space complexity of your program depends on the maximum depth of recursion. In your program, the maximum depth of recursion is equal to half the length of the string. Therefore, the space complexity of your program is O(n/2) or O(n) 2.
Q10: Find Exponent in logarithmic time
Q10: Find Exponent in logarithmic timeLast updated
Was this helpful?