From the course: Python: Recursion
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
The factorial function: Iterative version - Python Tutorial
From the course: Python: Recursion
The factorial function: Iterative version
- [Narrator] The factorial function in mathematics, is a function which takes an integer for example five, I'll just show you this as a comment so you can see what's going on. So we take five and then we multiply it by one less and then one less again, and then one less again, all the way down to multiplying it by one. So five factorial would be five times four, times three, times two, times one, which will come out as 120. When learning how to run recursive algorithms, it can be very helpful to implement an iterative version first. This enables us to ensure that we fully understand what is required and also to make sure we're familiar with any elements of our programming language, which we're likely to need in both an iterative and recursive version. Later on this is not so true as when you have some experience you will start to reason about recursive algorithms in purely recursive terms. Now you might want to…
Contents
-
-
-
-
(Locked)
Exceptions to GitHub Codespaces1m 30s
-
(Locked)
The ingredients of a recursive algorithm4m 11s
-
Recursion in action3m 26s
-
(Locked)
The factorial function: Iterative version3m 26s
-
(Locked)
A recursive factorial function4m 13s
-
(Locked)
Winding and unwinding the call stack in recursion6m 46s
-
(Locked)
Challenge: Fix the recursive algorithm1m 11s
-
(Locked)
Solution: The fundamentals of recursion1m 8s
-
(Locked)
-
-
-
-
-
-
-
-