Wednesday, March 5, 2014

Binary Trees and Linked Lists


A binary search tree is essentially a list with a value, representing the node or the parent, which points to its left child and right child. The left child and the right child could be a value or a tree itself, which could have another tree within itself, and so on. It differentiates for an actual tree as its branches grow downwards and it can only have 2 branches since it is binary. When a branch does not further lead to other branches, it ends by pointing to None type objects. An example would be:
T = [5, [4, [3, None, None], [1, None, None]], [2, None, None]] 

A linked list, on the other hand, is basically the same kind of structure as at binary tree but the only difference is that it has only one child. It is also made of a list, which only points to one child instead of a left child and right child. Consequently, the visual representation of the following linked list example is:
L = [5, [4, [3, None]]     


No comments:

Post a Comment