Java data structure and algorithm---tree

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.