[ACE] Binary Search Tree
- Tree Terminology
Internal node: node with at least one child
External node: node without children
Depth: number of ancestors(not counting itself)/ number of lines from the node to the root
Height: maximum depth of any node/ length of longest path from root to a leaf
- Binary Search Tree and its implementation
Simply speaking, it is a binary tree and the left child is always smaller than the parent, the right child is always greater than the parent
Implementation
Traversal:
Preorder Traversal:
-
In a preorder
traversal, a node is
visited before its
descendants
Inorder Traversal
- Properties of perfect binary trees
The number of all nodes are 1+ 2d+1
For the perfect binary trees, the height(h) and size(n) has the following relationship:
For the perfect binary trees, the height(h) and size(n) has the following relationship:
- h=log2 (n+1)-1
I won't give the prove process of this because it is really simple
评论
发表评论