Python Forum
Don't Understand Recursive Function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Don't Understand Recursive Function
#6
Your visualization really helped me a lot; especially with the nested calls. Thank you.

(Dec-02-2020, 06:03 PM)stranac Wrote: This is the basic structure of your function:
Output:
rec_count(5) print 5 rec_count(4) print 5
If we expand all calls like that, we get:
Output:
rec_count(5) print 5 rec_count(4) print 4 rec_count(3) print 3 rec_count(2) print 2 rec_count(1) print 1 rec_count(0) print 0 return 0 print 0 -- not called because the return ends this call print 1 print 2 print 3 print 4 print 5
Hope that helps.
Reply


Messages In This Thread
Don't Understand Recursive Function - by muzikman - Dec-02-2020, 05:30 PM
RE: Don't Understand Recursive Function - by muzikman - Dec-03-2020, 02:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Execution of Another Recursive Function muzikman 6 4,770 Mar-08-2025, 01:57 PM
Last Post: bterwijn
  Unable to understand the function string.split() Hudjefa 8 2,474 Sep-16-2024, 04:25 AM
Last Post: Pedroski55
  with open context inside of a recursive function billykid999 1 1,310 May-23-2023, 02:37 AM
Last Post: deanhystad
  Why recursive function consumes more of processing time than loops? M83Linux 9 6,033 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Combine Two Recursive Functions To Create One Recursive Selection Sort Function Jeremy7 12 10,402 Jan-17-2021, 03:02 AM
Last Post: Jeremy7
  list call problem in generator function using iteration and recursive calls postta 1 2,489 Oct-24-2020, 09:33 PM
Last Post: bowlofred
  Recursive function returns None, when True is expected akar 0 4,411 Sep-07-2020, 07:58 PM
Last Post: akar
  factorial using recursive function spalisetty06 12 6,049 Aug-25-2020, 03:16 PM
Last Post: spalisetty06
  Recursive Function sridhar 7 3,985 Jul-14-2020, 07:53 PM
Last Post: deanhystad
  Nested Recursive Function not Returning Etotheitau 2 3,164 May-09-2020, 06:09 PM
Last Post: Etotheitau

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020