Binary trees is a Tree that has two children for the node.The tree can be empty too with None. The children are called left and right. It's interesting to see how flexible the Tree class can be. You can use the Tree class to apply to specific designs of the format of the Tree class. Through the tree, you can visit the nodes in different ways.
You can visit the tree inorder:
-visit the left subtree inorder
- visit this node itself
- visit the right subtree inorder
You can visit the tree preorder:
-visit this node itself
- visit the left subtree in preorder
- visit the right subtree in preorder
You can visit the tree postorder:
- visit the left subtree in postorder
- visit the rightsubtree in postorder
- visit this node itself
We can design a class that has more conditions than just a binary tree. There is a type of binary tree called binary search trees (BST). The node.data are comparable. The nodes in left subtree are less than node.data. The nodes in the right subtree are more than node.data. This tree is really efficient if you want to go through a tree without looking at every single node.
No comments:
Post a Comment