1 / 20

Recursion Problems | Commonly Asked Recursion Interview Questions | Simplilearn

This presentation is based on recursion problems that are most commonly asked in coding interviews. This video is dedicated to helping the candidates with commonly asked recursion interview questions along with their solutions. Learning these questions would definitely help you to bag your dream job. The slide covers the following topics.<br><br>1. Introduction<br>2. sum of numbers from zero to a given number<br>3. factorial of a given number<br>4. nth fibonacci number<br>5. checks if a string is a palindrome<br>6. reverse a given string

Simplilearn
Download Presentation

Recursion Problems | Commonly Asked Recursion Interview Questions | Simplilearn

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. AGENDA

  2. AGENDA Calculate the sum of all numbers from zero to a given number. A recursive function that returns the factorial of given number. A recursive function that returns nth no, in Fibonacci Number. A recursive function that checks if the string is a palindrome. A recursive function that takes a string and reverse the string.

  3. Click here to watch the video

  4. 1 A recursive function to calculate the sum of all numbers from zero to a given number.

  5. 1 A recursive function to calculate the sum of all numbers from zero to a given number. def sum(int num):if num is 0 or 1return numelsereturn num + sum(num-1)

  6. 2 A recursive function that returns the factorial of given number.

  7. 2 A recursive function that returns the factorial of given number. def factorial(int n):assert n >=0 and int(n) == n,if n <= 1:return 1else:return n * factorial(n-1) =4

  8. 2 A recursive function that returns the factorial of given number. def factorial(int n):assert n >=0 and int(n) == n,if n <= 1:return 1else:return n * factorial(n-1) =4 =12 X

  9. 2 A recursive function that returns the factorial of given number. def factorial(int n):assert n >=0 and int(n) == n,if n <= 1:return 1else:return n * factorial(n-1) =4 =12 X =24 X X

  10. 2 A recursive function that returns the factorial of given number. def factorial(int n):assert n >=0 and int(n) == n,if n <= 1:return 1else:return n * factorial(n-1) =4 =12 X =24 X X =24 X X X

  11. 3 A recursive function that takes a number ‘n’ and returns the nth number of the Fibonacci number.

  12. 3 • A recursive function that takes a number ‘n’ and returns the nth number of the Fibonacci number. def fibonacci(int n):if n <= 1:return nelse:return fibonacci(n-1) + fibonacci(n-2)

  13. 4 A recursive function that takes a string and returns if the string is a palindrome.

  14. 4 A recursive function that takes a string and returns if the string is a palindrome. def ispalin (string str, int low, int high):if low>=high:return Trueif str[low] != str[high] :return Falsereturn ispalin (str,low + 1, high - 1)

  15. 5 A recursive function that takes a string and reverse the string.

  16. 5 A recursive function that takes a string and reverse the string. def reverse(string str, int low, int high):if low < highswap(str[low],str[high]reverse(str, low+1, high-1)

  17. 5 A recursive function that takes a string and reverse the string. def reverse(string str, int low, int high):if low < highswap(str[low],str[high]reverse(str, low+1, high-1)

More Related