Class Factorial

java.lang.Object
topics.divideconquer.Factorial

public class Factorial extends Object
DIVIDE AND CONQUER PROBLEM: CALCULATE THE FACTORIAL OF A NUMBER
Author:
vicegd
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    fact1(int n)
    This method iteratively calculates the factorial with a linear complexity O(n)
    int
    fact2(int n)
    This method recursively calculates the factorial with a linear complexity O(n), DandC by subtraction with a=1,b=1,k=0

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Factorial

      public Factorial()
  • Method Details

    • fact1

      public int fact1(int n)
      This method iteratively calculates the factorial with a linear complexity O(n)
      Parameters:
      n - Number to calculate greater than or equal to 0
      Returns:
      Factorial of the number
    • fact2

      public int fact2(int n)
      This method recursively calculates the factorial with a linear complexity O(n), DandC by subtraction with a=1,b=1,k=0
      Parameters:
      n - Number to calculate greater than or equal to 0
      Returns:
      Factorial of the number