Skip to content

Commit 5d789ec

Browse files
authored
Update 17 fibbonacci using memoization.c
1 parent 8756cf6 commit 5d789ec

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Recursion/17 fibbonacci using memoization.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ int mfib(int n)
2424
{
2525
if (n<=1)
2626
{
27-
F[n]=n;
27+
F[n]=n; // in function F of n simply return the value of the n if n is less then 1;
2828
return n;
2929
}
3030
else
3131
{
32-
if (F[n-2]==-1)
33-
F[n-2]=mfib(n-2);
34-
if (F[n-1]==-1);
35-
F[n-1]=mfib(n-1);
32+
if (F[n-2]==-1) // if place is not called then
33+
F[n-2]=mfib(n-2); // call recursively
34+
if (F[n-1]==-1); // if this is also not called then
35+
F[n-1]=mfib(n-1);// call recursively
3636

37-
return F[n-2]+F[n-1];
37+
return F[n-2]+F[n-1]; // at last return the sum of the called terms
3838
}
3939

4040
}

0 commit comments

Comments
 (0)