Tree Terminology and Types of Binary Trees
- Root: The top node without a parent.
- Edge: A link between a parent and a child node.
- Leaf: A node which does not have children.
- Sibling: Children of the same parent.
- Ancestor: A parent, grandparent, great-grandparent, etc., of a node.
- Depth of a Node: The length of the path from the root to the node, measured in the number of edges.
- Height of a Node: The length of the path from the node to the deepest node connected to it. This length is measured by the number of edges.
- Depth of the Tree: The depth of the root node, which is always zero.
- Height of the Tree: The height of the root node.
- Each node has either 0 or 2 children. No node has exactly 1 child.
- Every node other than leaf nodes has exactly two children.
- All leaf nodes are at the same level.
- The tree has exactly 2^(h+1) - 1 nodes, where
h
is the height of the tree.
- The number of leaf nodes is (n+1)/2 for a tree with
n
nodes.
- Every level, except possibly the last, is completely filled.
- If the last level is not filled, nodes are as far left as possible.
- A tree where all leaf nodes are at the same distance from the root.
Deepest Node in a Binary Tree
- The deepest node is the last node reached in a level order traversal.
- Preorder Traversal: Visit the root node, then the left subtree, followed by the right subtree.
- Inorder Traversal: Visit the left subtree, then the root node, and finally the right subtree.
- Postorder Traversal: Visit the left subtree, the right subtree, and then the root node.
Breadth First Search (BFS)
- Level Order Traversal: Visit each level from left to right.
About
Using python to work with binary trees and binary search trees
Languages
Language:Python 100.0%