Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lecture "Organising information: trees", exercise 1 #33

Open
essepuntato opened this issue Dec 6, 2021 · 4 comments
Open

Lecture "Organising information: trees", exercise 1 #33

essepuntato opened this issue Dec 6, 2021 · 4 comments
Labels

Comments

@essepuntato
Copy link
Contributor

Write in Python a recursive function def breadth_first_visit(root_node). This function takes the root node of a tree and returns a list containing all the tree's nodes according to a breadth-first order. The breadth-first order considers all the nodes of the first level, then those of the second level, and so forth. For instance, considering the nodes created in Listing 2 in Chapter "Organising information: trees", the function called on the node book should return the following list: [book, chapter_1, chapter_2, text_8, paragraph_1, paragraph_2, paragraph_3, text_7, text_1, quotation_1, text_3, quotation_2, text_5, text_6, text_2, text_4]. Accompany the implementation of the function with the appropriate test cases.

@RebeccaJillianBeattie
Copy link

Recursive tree1
recursive tree2
Recursive tree diagram

@katya-avem
Copy link

image
image

@olgagolgan
Copy link

olgagolgan commented Dec 15, 2021

Screenshot (158)

Screenshot (156)

@essepuntato
Copy link
Contributor Author

@olgagolgan @angstigone your solution is not recursive, is iterative! It is a good solution for exercise 2 though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants