ECS 36A Lecture 8: Recursions

146 views1 pages
Verified Note

Document Summary

Is when a function calls on itself in its own definition. A recursion processes. def factorial(n): if n == 1: return 1 else: return n * factorial(n - 1) The tower of hanoi is a classical example involving the redistribution of disks in a new order. Though visualization helps with this concept, below is a program that reimagines it through code. def hanoi(n, src, dst, tmp): if n > 0: hanoi(n - 1, src, tmp, dst) move(src, dst) hanoi(n - 1, tmp, dst, src) Can use tmp peg def hanoi_(n-1) (src, dst, tmp): pass.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents