5.5 Trees and forests

Source: Internet
Author: User

Storage structure of 5.5.1 tree

The tree's storage structure is usually represented in the following three ways.

1. Parental representation

This storage structure is convenient for the parent (or ancestor including the root) of the specified node.

In this storage notation, however, children or other descendants of the specified node may need to traverse the entire structure.

2. Child Linked List method

In contrast to parental representations, the child's linked-list notation facilitates the implementation of operations involving child nodes, and does not apply to the operation of the parent (t,x).

3. Child Brother representation

The biggest advantage of this storage structure is that it is exactly the same as the two-fork list of the two-fork tree, so you can use the various algorithms of the binary tree to implement the tree operation.

Transformation of 5.5.2 tree, forest and two-fork tree

Tree, forest to two fork tree conversion

We know that each node in the tree has at most only one leftmost child (the eldest son) and one right neighbour's brother, according to this relationship, you can convert a tree into a binary tree by the following method: First, add a line between all the sibling nodes, and then keep the line of the eldest son on each node, removing the knot from the other child. Since the roots have no brothers, the right subtree of the root node of the transformed two-tree will be empty.

The way to convert a forest into a two-tree is to first convert each tree in the forest into a binary tree, and then treat the root nodes of each of the two-forked trees as brothers together, forming a tree

Two-pronged tree.

5.5 Trees and forests

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.