first, the concept of trees
Outside the root node, the remaining nodes have only one parent node.
1, degrees
the degree of the node : The number of child nodes per node.
The degree of the tree : The maximum number of degrees for each node within the tree.
tree Height (depth): The maximum level of a node in a tree is called the depth of the tree.
node path : A node to another node of the line (tree species that path has only one). For example: B to J node if there are two paths, then the structure is not a tree.
subtree : A node outside the root node is a subtree.
leaf node: a tree in which there is no node node is called the leaf node (that is, the degree of 0 nodes), referred to as "leaves."
cousin Node : Parents in the same layer of the nodes are each other cousins;
Two classification of trees
Sequential points:
Ordered tree: Each subtree of a node in a tree is ordered and not interchangeable from left to right.
Unordered tree: Each subtree of a node in a tree is unordered and interchangeable from left to right.
second, the storage structure of the tree
Simple sequential storage is not sufficient to meet the requirements of the tree, generally we combine sequential storage with chained storage to achieve.
Commonly used three kinds of ways
1. The parents indicated that the hair
Note: The subscript column allows us to store the location of the parent class in sequential storage through parent, which is a simple way for us to find the parent element of an element, but it is relatively complex to find child elements.
2. Representation of parents and children
Note: This way the parents are represented with the child notation combined array + linked list (HASHMAP data structure), the way to find a child node simple.
3, the child brother said that the hair
Note: This method is easy to find child elements of an element, but it is relatively complex to find the parent element.
Java data structure and algorithm---tree