Learnings

  • Can be used in situations where loops are used
  • Must call itself and have a base case

Big O Notation

  • Describes time complexity for code to run
// O(n) time since it must go through n iterations to calculate factorial
public int factorial (int n) {
    if (n == 0 || n == 1) {
      return 1;
    }
    return n * factorial(n-1);
  }
  
  System.out.println(factorial(5));
120

Completed google form