1 / 33

Good morning!

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).

ide
Télécharger la présentation

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. 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. Good morning!

  2. Recursive Algorithms

  3. Example: Gift box!

  4. Example: Gift box!

  5. Example: Gift box!

  6. Value of gift box : Equation?

  7. Example: Treasure hunt!

  8. What is recursion? • Popular in math definitions • Inductive proof

  9. Example: factorial(n)

  10. Example: factorial(n) • Non-recursive solution

  11. How does recursion work? • Stack memory • How much stack memory is needed?

  12. How to understand recursion? • Method invocations & returns diagram • Example: factorial(5)

  13. How to understand recursion? • Method invocations & returns diagram • Example: fibonacci(n)

  14. How to understand recursion? • Tree diagram • Example: fibonacci(n)

  15. fibonacci(n) : non-recursive solution?

  16. How to analyze recursion? • Recurrence relation & Time complexity

  17. Example: Hanoi tower

  18. Example: Fractals

  19. Petrol cost minimization problem

  20. Similar solution: Quick-sort

  21. Quick-sort: non-recursive solution?

  22. Similar solution: Merge-sort

  23. Example: Knapsack problem

  24. Example: Change for $ 100 • Available denominations: 1c, 5c, 10c, 25c, $1, $2, $5, $10, $20, $50, $100 • How many combinations are there?

  25. How to make recursion efficient? • Parameters • Tail recursion

  26. Example: N-Queens puzzle

  27. Example: Knight’s tour

  28. Example: Sudoku’s puzzle

  29. Example: Maximizing total conviviality

  30. 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.

  31. Questions & Answers?

More Related