Last answered:

20 Jun 2024

Posted on:

26 Apr 2024

0

Multiple recursion helpful info - Tower of Hanoi

Hi everyone,

after some time searching online for answers on how multiple recursion functions are called, here's what helped me:


First I used the function explained in the youtube video from the same teacher linked in this discussion https://365datascience.com/q/3a349f6924 (the one in the course works as well, I just worked on this because it seemed more linear):



Then understanding the decision tree -> since our function calls itself twice inside it, each time it's called the tree splits in 2: 


Then we need to clear out what is happening to the variables locally during the calls, since they move around quite a lot:


Hope that helps, happy coding!

2 answers ( 0 marked as helpful)
Instructor
Posted on:

29 Apr 2024

1

Hey Jessica,

This looks great! Amazing work! Thanks so much for sharing with the other people taking the course.

Visualizing recursive calls as a decision tree is an excellent method to comprehend the branching nature of recursion, especially in multiple recursion scenarios. Each node in the tree represents a function call, and each branch represents a new recursive call initiated by the current function call. This visualization helps in understanding how the recursive calls expand exponentially.

Best,

Ned

Posted on:

20 Jun 2024

0

I did not understand why the order of the lists inside the function mattered, but your solution helped me visualise it and now I understand that. Thank you for that. But, one thing I still don't understand is how the order of the list changes its meaning, i.e. how does list B go from auxiliary to target just by changing it's order and how does list A go from being target auxiliary etc etc? In the video's solution, we only ever call list A and list C in our base case and in the solution here, we only ever call the target list. I don't really understand how changing the order in which we call the lists inside the function change the position of the list?

Submit an answer