[Reproduced] tree, forest and two-fork tree conversion

Source: Internet
Author: User

This article was reproduced from: http://www.cnblogs.com/zhuyf87/archive/2012/11/04/2753950.html

The tree is converted to a two-fork tree

(1) Add line. Add an attachment between all the sibling nodes.

(2) Go to line. Each node in the tree retains its connection to the first child's node, removing its connection to the other child's nodes.

(3) Level adjustment. Take the root node of the tree as the axis, the whole tree clockwise rotation of a certain angle, so that the structure of a clear hierarchy. (Note that the first child is the left child of the knot, and the child converted by the brother is the right child of the knot.)

Forest converted to two-fork tree

(1) Convert each tree to a two-fork tree.

(2) The first binary tree does not move, starting from the second binary tree, in turn the root node of the second fork tree as the root node of the previous binary tree, the right child, connected with the line.

Binary tree converted to tree

is the inverse process of a tree converted to a two-fork tree.

(1) Add line. If a node x's left child node exists, then the left child's right child node, right child's right child node, right child's right child's right child knot point, all as Node x child. Connect the node x to these right child nodes using a line.

(2) Go to line. Delete all nodes in the original binary tree and their right child nodes.

(3) Level adjustment.

Binary tree converted to forest

If the root node of a binary tree has a right child, the binary tree can be converted into a forest, otherwise it will be converted to a tree.

(1) Starting from the root node, if the right child exists, then the link with the right child node is removed. Then look at the detached two-fork tree, if the right child of the root node exists, then the connection is deleted .... Until all of these root nodes are removed from the right child's connection.

(2) Convert each separated two-fork tree into a tree.

Reference:

[1] "Big talk data Structure"

[Reproduced] tree, forest and two-fork tree conversion

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.