in Algorithms edited by
17,958 views
60 votes
60 votes

Consider the following recursive C function.

void get(int n)
{
    if (n<1) return;
    get (n-1);
    get (n-3);
    printf("%d", n);
}

If $get(6)$ function is being called in $main()$ then how many times will the $get()$ function be invoked before returning to the $main()$?

  1. $15$
  2. $25$
  3. $35$
  4. $45$
in Algorithms edited by
18.0k views

3 Comments

14
14
How can  get(1) call to get(0) and get(-2) as n<1 ?.
2
2
T(n) = T(n-1) + T(n-3) +1
T(0) = 1 (counting get(0) as 1 count)
T(1) = 3
T(-1) = 1 (count get(-1) as 1 count)

solving T(6) in this will also give 25
3
3

5 Answers

1 vote
1 vote

1 comment

can u explain what they hav done ?? i am nt getting it ..
0
0
Answer:

Related questions