comp-think / 2021-2022

The GitHub repository containing all the material related to the Computational Thinking and Programming course of the Digital Humanities and Digital Knowledge degree at the University of Bologna (a.a. 2021/2022).
17 stars 9 forks source link

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

Open essepuntato opened 2 years ago

essepuntato commented 2 years ago

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 commented 2 years ago

Recursive tree1 recursive tree2 Recursive tree diagram

katya-avem commented 2 years ago

image image

olgagolgan commented 2 years ago

Screenshot (158)

Screenshot (156)

essepuntato commented 2 years ago

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