0% found this document useful (0 votes)
1 views2 pages

Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Python

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

1. Direct vs.

Indirect Recursion Direct Recursion: * Definition


& Syntax: Correct. A function calling itself directly inside its
own body is exactly how this works.
Indirect Recursion: * Definition & Diagram: Correct. Your
"Circular call" diagram perfectly shows fun1() calling fun2(),
which then calls fun1().
Non-Tail Recursion:
Concept & Code: Correct. Because of the n + fun(n-1)
statement, the addition is a pending operation. The
computer must wait for the recursive call to finish before it
can add n. This is exactly how a classic factorial program
behaves.
Concept: Correct. You correctly identified that a tail call
means there are no pending operations left to do after the
function returns.
Code Logic: ❌ Slightly Wrong. While your code is syntactically
tail-recursive, its logic is broken. Because it returns fun(n-1)
all the way down until it hits the base case (return 0), this
function will always return 0 for any positive number you
pass into it.
The Fix: To make it a useful example of tail recursion, you
usually pass an "accumulator" variable to keep track of the
result, or just use it to print a countdown:
3. Syntax Errors / Typos to Fix
Look closely at the Non-Tail Recursion code block on the right
side of the second page:
The Closing Brace: At the very bottom of that function, you
accidentally wrote an opening brace { instead of a closing
brace }. Change it to } to close the function properly.
Semicolon: Make sure there is a semicolon after return 0;
inside the if block, just like you did on the left side.

You might also like