0

I need to call functions recursively in tree structure.

Below is the image for example tree structure.

enter image description here

here I am calling the python function in in for loop by passing A, this will produce the output B in first loop and C in second loop.

here I need to run the same function for B and C, so here B will generate D and E and C will generate F and next Run same python function for D it will generate G so on, I have to run the same until I get null.

How can I write the logic in python

asked Feb 16, 2019 at 11:32
1

1 Answer 1

0

There are better ways depending on the end goal really but this basic recursive function will traverse your whole tree.

def get_children(node):
 for child in node:
 get_children(child)

This structure will go all the way down the left branches of the tree first though. Might be worth noting.

answered Feb 17, 2019 at 11:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.