Good
This presentation is the property of its rightful owner.
Sponsored Links
1 / 33

Good morning! PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on
  • Presentation posted in: General

Good morning!. Recursive Algorithms. Example: Gift box!. Example: Gift box!. Example: Gift box!. Value of gift box : Equation?. Example: Treasure hunt!. What is recursion?. Popular in math definitions Inductive proof. Example: factorial(n). Example: factorial(n).

Download Presentation

Good morning!

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Good morning

Good morning!


Recursive algorithms

Recursive Algorithms


Example gift box

Example: Gift box!


Example gift box1

Example: Gift box!


Example gift box2

Example: Gift box!


Value of gift box equation

Value of gift box : Equation?


Example treasure hunt

Example: Treasure hunt!


What is recursion

What is recursion?

  • Popular in math definitions

  • Inductive proof


Example factorial n

Example: factorial(n)


Example factorial n1

Example: factorial(n)

  • Non-recursive solution


How does recursion work

How does recursion work?

  • Stack memory

  • How much stack memory is needed?


How to understand recursion

How to understand recursion?

  • Method invocations & returns diagram

  • Example: factorial(5)


How to understand recursion1

How to understand recursion?

  • Method invocations & returns diagram

  • Example: fibonacci(n)


How to understand recursion2

How to understand recursion?

  • Tree diagram

  • Example: fibonacci(n)


Fibonacci n non recursive solution

fibonacci(n) : non-recursive solution?


How to analyze recursion

How to analyze recursion?

  • Recurrence relation & Time complexity


Example hanoi tower

Example: Hanoi tower


Example fractals

Example: Fractals


Petrol cost minimization problem

Petrol cost minimization problem


Similar solution quick sort

Similar solution: Quick-sort


Quick sort non recursive solution

Quick-sort: non-recursive solution?


Similar solution merge sort

Similar solution: Merge-sort


Example knapsack problem

Example: Knapsack problem


Example change for 100

Example: Change for $ 100

  • Available denominations: 1c, 5c, 10c, 25c, $1, $2, $5, $10, $20, $50, $100

  • How many combinations are there?


How to make recursion efficient

How to make recursion efficient?

  • Parameters

  • Tail recursion


Example n queens puzzle

Example: N-Queens puzzle


Example knight s tour

Example: Knight’s tour


Example sudoku s puzzle

Example: Sudoku’s puzzle


Example maximizing total conviviality

Example: Maximizing total conviviality


Conclusions

Conclusions

  • Recursion is one of the difficult concepts to understand, perhaps it is not that intuitive.

  • As per a few mathematicians & CS folks, it is one of the most beautiful concepts!

  • While it is not used much in commercial applications, it certainly puts your logical thinking skills to work!

  • It is easy to remove tail recursion, but all others are lot harder to remove.


Questions answers

Questions & Answers?


  • Login