0

How to do only using recursion

Please refer code below : Main question is on visitall function. It has recursive call also and a for loop also... Can I avoid for loop and completely do recursive call only ? If yes , could you please let me know how to do so ? https://code.sololearn.com/c17n29Lr87xr/?ref=app

10th May 2022, 2:15 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
7 Réponses
+ 1
This is what i came up with, but theres no benefit to using recursion vs simply a for loop In my example* https://code.sololearn.com/crnl4SYodEZC/?ref=app
11th May 2022, 2:51 PM
Raul Ramirez
Raul Ramirez - avatar
+ 1
Ketan Lalcheta i used my phone but yeah most likely on sololearns end.
11th May 2022, 3:34 PM
Raul Ramirez
Raul Ramirez - avatar
0
How you have things set up i dont think so. Since each node has its own list, you need that for loop to navigate through each list. so its basically stacking things like for(node in root node list ) for (node in child list ) for ( node in child chid list) … and so on Print data
11th May 2022, 5:32 AM
Raul Ramirez
Raul Ramirez - avatar
0
Ok... Is there other way to store this data to allow only recurring code ? Can u please suggest on this ?
11th May 2022, 6:44 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Thanks Raul Ramirez but seems there is some issue in sololearn now a days... I belive you have prepared this code on laptop and I am accessing this from android mobile app... I can find code incomplete so can't check code what has been done..
11th May 2022, 3:32 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Don't know what happened since last few days... Am I the only one who could see it first 25 lines into code ?
11th May 2022, 4:56 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Raul Ramirez thanks for your answers.. I was just going through my previous questions... now i can check your full solution Your solution works but requirement is to have list of list kind of n tree You are adding all items to store object... that is not my requirement. What i have as data structure is fix for storing data... can i still achieve visiting all either by only recursion or either by only iteration Right now i am doing both (for loop and recursion call) .can i do using only one ?
30th Sep 2022, 7:14 AM
Ketan Lalcheta
Ketan Lalcheta - avatar