Tree, forest and two-fork tree conversion

Source: Internet
Author: User

1. Tree converted to two-fork tree

Each node in the tree has at most one left-most child (eldest son) and one right-neighbour brother

1) Add a connection between all the sibling nodes

2) Each node, in addition to retaining the connection to its eldest son, removes the connection to the other child

3) Level adjustment. Take the root point as the axis, the whole tree clockwise rotation of a certain angle, so that the structure of a clear hierarchy. The left child of this knot is the left child before, and the right child is the previous sibling node.


2. 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.



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.