Resources
Video 1 - Intro to recursion (using factorial)
Length 12:13 min
A comparison of iterative and recursive implementations of factorial
- Please read and understand the following tutorial:
- Calculate Factorial With Java - Iterative and Recursive
- Consider this article on Geeks for Geeks, for an alternative (more sussinct, but less detailed) approach, that has C# implementation.
- Implement your own program, using the two iterative (for and while) and the recursive implements from the tutorial;
- You will need to figure out how to:
- incorporate the functions together with a main() method that enables the user to input a value of n to calculate the factorial of.
- Give the user the option of the two iterative and the recursive approach (I suggest case).
- Record how long each approach takes for increasing values of n.
- Use nanoTime(), as explained below:
- Measure elapsed time in Java
- You will need to figure out how to:
Video 2 - tree traversal algorithms
Length 6:06 min
Slides
Worksheet
Homework
Activity
Must
- Watch the video (12:13)
- Implement the iterative and recursive versions of the factorial program (from the video) in Java.
- Submit cropped screenshots in a single Word document, showing code and program output.
Could
- Complete Q1 from the Homework sheet