page_title: Link/cut tree
section_title: Preferred paths
hierarchical_section_title: Link/cut tree / Structure / Preferred paths
caption_attribution_description: English: Showing how a link cut tree transforms preferred paths into a forest of trees.
context_page_description: A link/cut tree is a data structure for representing a forest, a set of rooted trees, and offers the following operations:
  Add a tree consisting of a single node to the forest.
  Given a node in one of the trees, disconnect it from the tree of which it is part.
  Attach a node to another node as its child.
  Given a node, find the root of the tree to which it belongs. By doing this operation on two distinct nodes, one can check whether they belong to the same tree.
  The represented forest may consist of very deep trees, so if we represent the forest as a plain collection of parent pointer trees, it might take us a long time to find the root of a given node. However, if we represent each tree in the forest as a link/cut tree, we can find which tree an element belongs to in O(log(n)) amortized time. Moreover, we can quickly adjust the collection of link/cut trees to changes in the represented forest. In particular, we can adjust it to merge and split in O(log(n)) amortized time.
  Link/cut trees divide each tree in the represented forest into vertex-disjoint paths, where each path is represented by an auxiliary data structure.
context_section_description: When an access to a node v is made on the represented tree, the path that is taken becomes the preferred path. The preferred child of a node is the last child that was on the access path, or null if the last access was to v or if no accesses were made to this particular branch of the tree. A preferred edge is the edge that connects the preferred child to v.
  In an alternate version, preferred paths are determined by the heaviest child.
caption: Showing how a link cut tree transforms preferred paths into a forest of trees.
exif: {}