Given the Factorial function as below int Fact int N int Fa

Given the Factorial function as below;
int Fact (int N)
{
int Fact=1;
for(int I=1; I<=N; i++)
{
Fact=Fact*I;}
return Fact;
}

WHAT IS THE RUNTIME OF THE PROBLEM? GIVE EXPLANATION.

Solution

fact=1 ( 1 time unit)
I<=N ( N time units)
I++ ( N time units)
Fact=fact*i (N time units)because it is in loop
Return fact ( 1 time unit )
Total time = 3N+2
Time complexity = maximum order of total time= O(N)

Given the Factorial function as below; int Fact (int N) { int Fact=1; for(int I=1; I<=N; i++) { Fact=Fact*I;} return Fact; } WHAT IS THE RUNTIME OF THE PROBL

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site