Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON (DATA STRUCTURES AND ALGORITHMS) Which of the following are true: (there

ID: 3596453 • Letter: P

Question

PYTHON (DATA STRUCTURES AND ALGORITHMS)

Which of the following are true: (there are multiple correct answers, choose them all)

Tail recursion:

1. A tail recursion makes recursive calls as its last step.

2. There should be no statement after a recursive call.

3. The BinarySum function(a function that adds all the numbers in an integer array using Binary recursion) is not a tail recursion.

4. A tail recursion must be a linear recursion

5. A tail recursion doesn't have to be a linear recursion.


Binary Recursion:

1. A binary recursion has two recursive calls included in the implementation.

2. A binary recursion could have one or more base cases.

3. A binary recursion has two recursive calls been executed in non-base cases.

4. A binary recursion has exactly two base cases.


Explanation / Answer

Please find my answer.

Please let me know in case of any issue.

Tail recursion:

Ans:

1. A tail recursion makes recursive calls as its last step.

2. There should be no statement after a recursive call.

4. A tail recursion must be a linear recursion

About tail recursion:

The tail recursive functions considered better than non tail recursive functions as tail-recursion can be optimized by compiler. The idea used by compilers to optimize tail-recursive functions is simple, since the recursive call is the last statement, there is nothing left to do in the current function, so saving the current function’s stack frame is of no use.

Binary Recursion:

2. A binary recursion could have one or more base cases.

3. A binary recursion has two recursive calls been executed in non-base cases.