jeff1evesque / interview-twitter

Least Common Ancestor
2 stars 0 forks source link

create the binary tree in least-common-ancestor.py #5

Open jeff1evesque opened 10 years ago

jeff1evesque commented 10 years ago

We need to take the binary search tree representation from the external file (input.txt), and create the tree representation in least-common-ancestor.py file.

jeff1evesque commented 10 years ago

b7ee086: In python, we need to define a class before we can create instances of it. Prior to ca1d481, the Node class was defined at the end of least-common-ancestor.py file -- however, we tried to use it prior to this. Ideally, we have to move the definition prior to creating the instance -- but, we decided to create a separate file to contain the definitions, class_definitions.py and import it within least-common-ancestor.py.

Note: we have to append the file name when we create instances of a specific class from class_definitions.py. For example:

root = class_definitions.Node(cast_type(data_root[0]))

jeff1evesque commented 10 years ago

380189a, eb2d6ca, 47d210a: in python, it's good practice to name variables and files using underscores, instead of dashes -- since dashes are typically interpreted as subtraction

jeff1evesque commented 10 years ago

9443288: we call the class methods imported from class_definitions.py in order to build the tree we need in least_common_ancestor.py. We also implemented a recursive breadth-first algorithm in order to print the binary search tree.

jeff1evesque commented 10 years ago

Note: since class_definitions.py is imported in least_common_ancestor.py, running the latter file creates a bytecode copy of the former file, specifically class_defintions.pyc. Bytecode files are represented by the file extension, pyc.