Binary Tree

来源:互联网 发布:iapp制作文字游戏源码 编辑:程序博客网 时间:2024/06/16 15:40

A Binary tree is made up of a set of elements called nodes. This set either is empty or consists of a node called the root together with to binary trees, called the left and right subtrees, which are disjoint from each other and from the root. The roots of these subtrees are children of the root. There is an edge from a node to each of its children, and a node is said to be the parent of its children.


The depth of a node M in the tree is the length of the path from root of the tree to node M. The height of a tree is one more than the depth of the deepest node in the tree. All nodes of depth d are at level d in the tree. The root is the only node at level 0, and its depth is 0. A leaf node is any node that has two empty children. Aninternal node is any node that has at one non-empty child.


Full Binary Tree: 

Each node in a full binary tree is either an internal node with exactly two non-empty children or a leaf.

Complete Binary Tree:

A complete binary tree has a restricted shape obtained by starting at the root and filling the tree by levels from left to right.


If  a tree is a full binary tree, the number of nodes in this tree is even, and the number of leaf nodes is one more than that of internal nodes. 


Any process for visiting all of the nodes in some order is called a traversal(遍历). 


Binary Search Tree

All nodes stored in the right subtree of a node whose key value is K have key values greater than or equal to K.

All nodes stored in the left subtree of a node whose key value is K have key values less than K. 






原创粉丝点击