Tree and Node Data Structures

  1. Define a binary tree structure using a list for each node. Each node should have the following structure:

    ['name', left_sibling, right_sibling]
    

    where left_sibling and right_sibling are either the node list data structure or None.

    Write a recursive function that walks the tree and shows the name of each node.

  2. Define a tree structure using a list for each node and a list to contain the chidren under each node. Each node should have the following structure:

    ['name', [child1, child2, ...]]    # or
    ['name', []]
    

    Write a recursive function that walks the tree and shows the name of each node.

  3. Define a binary tree structure using a dictionary for each node. Each node should have the following structure:

    {'name': 'the name', 'lsib': left_sibling, 'rsib': right_sibling}
    

    where left_sibling and right_sibling are either the node dictionary data structure or None.

    Write a recursive function that walks the tree and shows the name of each node.

  4. Define a class Node to represent each node of a binary tree. The class should have the following instance variables:

    • name -- a string
    • lsib -- an instance of class Node or None.
    • rsib -- an instance of class Node or None.

    Also implement a method in class Node to recursive walk the tree and show the name of each node.

What you will learn: