Dynamic Tree link-cut trees

Source: Internet
Author: User
Dynamic Tree

The dynamic tree problem requires us to maintain a forest composed of several sub-nodes in disorder.

This data structure is required to support tree separation and merging, some operations on the path of a vertex to its root, and some operations on the subtree of a vertex.

Here, we consider a simplified dynamic tree problem, which only contains operations on the tree form and operations on the path from a point to the root:

To maintain a data structure, you can perform the following operations:

• Make tree ()-create a tree with only one node.

• Cut (V)-remove the edge of V from its parent node parent (V), which is equivalent to separating the child tree of vertex v.

• Join (V, W)-Let V become W's new son. V is the root node of a tree, and V and W are different nodes in two trees.

• Find root (V)-return the root node of the tree where v is located. Once this problem is clarified, we can easily expand the data structure and maintain some information about the path of the root node from each point to the tree to which it belongs, for example, the maximum value and path length of the weight and edge weight.

 

Link-cut trees

Link-cut trees is a data structure invented by sleator and Tarjan to solve such dynamic tree problems.

This data structure can implement each operation of the above dynamic tree problem within the time span of the O (logn.

If the tree form is not changed, we can use the tree chain to split the tree into many chains and maintain the above weight information.

However, for the change in tree form, the tree chain partitioning scheme also needs to change. We use the splay idea to dynamically maintain many tree chains (called Link-cut trees ).

 

Definition of link-cut trees

It indicates that a vertex has been accessed. If the access operation on this vertex has just been executed. If the last accessed node is in the subtree W of node v, where W is the son of V, W is the preferred child of node v. If the last accessed node is V itself, it does not have a preferred child. The edge of each vertex to its preferred child is called the preferred edge. The non-extensible path connected by the preferred edge is called the preferred path. In this way, the entire tree is divided into several preferred paths. For each preferred path, use the depth of the vertex on this road as the keyword and use a Balance Tree to maintain it (in this balance tree, the vertex in the left subtree of each vertex, all are above this point in the preferred path; all vertices in the right subtree are below this point in the preferred path ). Note that such a balance tree must support separation and merging. Here, we select the splay tree as the data structure of the Balance Tree. We call this balance tree an auxiliary tree. Knowing the several preferred paths decomposed by tree T, we only need to know the connection relationships between these paths to express this tree T. The path parent is used to record the parent node of the preferred path corresponding to each auxiliary tree. If the highest point of the preferred path is the root node, the path parent of the auxiliary tree is null. Link-cut trees indicates each tree T in the forest to be maintained as several auxiliary trees. And use path parent to connect these auxiliary trees to the data structure.

 

In fact, we need to understand the definition in two aspects:

The first is the logical structure. One or more trees exist. This is logical. What we need to do is to operate and maintain the forest;

The second is the physical structure. Instead of directly storing these trees, we split the trees into multiple chains, each of which serves as a splay. The smallest node in splay is the first node of the chain.

 

Review definition:

Access: access to a node, also called expose.

Preferred child: the son of the last visit. The last accessed node has no preferred child.

Preferred edge: edge from each node to preferred child.

Preferred path: edge composed of continuous preferred edge.

Auxiliary tree (secondary tree): maintains a chain on the splay. For each node on the splay, the points on the left subtree of the node are above the chain, the vertices of the right subtree are all under the chain.

Path parent: records the father of the highest node on the chain, that is, the father of the leftmost node of splay. It is used to indicate the relationship between the chain and the chain.

 

Link-cut trees operation access

Access is the basis for all link-cut trees operations. Assume that the access (v) process is called, the path from point V to the root node becomes a new preferred path. If a node u on the path is not its parent (u) preferred child, the preferred child of parent (u) will change to U, which originally contains parent (u) the preferred path of will no longer contain the part above the node parent (u.

That is to say, process access will change the Chain Division on the logical tree. It uses the path from node V to the root node as a new chain. This chain will cut the old chain.

Physically, some trees in the splay are disconnected and reorganized.

 

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.