The following C function is an example of what type of recursion? int f(int n)…

2023

The following C function is an example of what type of recursion?

int f(int n) { if(n==1) return 1; else if(n==0) return 0; else return(f(n-1)+f(n-2)); }

  1. A.

    Binary

  2. B.

    Tail

  3. C.

    Linear

  4. D.

    Head

Attempted by 191 students.

Show answer & explanation

Correct answer: A

The function calls itself twice, as f(n-1) and f(n-2), for the recursive case. A recursion with two recursive calls is binary recursion.

Explore the full course: Niacl Ao It Specialist