GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing docs.kernel.org — Union-Find in Linux — The Linux Kernel documentation
English
Union-Find in Linux¶
What is union-find, and what is it used for?¶Union-find is a data structure used to handle the merging and querying of disjoint sets. The primary operations supported by union-find are:
As a data structure used to maintain sets (groups), union-find is commonly utilized to solve problems related to offline queries, dynamic connectivity, and graph theory. It is also a key component in Kruskal’s algorithm for computing the minimum spanning tree, which is crucial in scenarios like network routing. Consequently, union-find is widely referenced. Additionally, union-find has applications in symbolic computation, register allocation, and more. Space Complexity: O(n), where n is the number of nodes. Time Complexity: Using path compression can reduce the time complexity of
the find operation, and using This document covers use of the Linux union-find implementation. For more information on the nature and implementation of union-find, see:
Linux implementation of union-find¶Linux’s union-find implementation resides in the file “lib/union_find.c”. To use it, “#include <linux/union_find.h>”. The union-find data structure is defined as follows: struct uf_node {
struct uf_node *parent;
unsigned int rank;
};
In this structure, parent points to the parent node of the current node.
The rank field represents the height of the current tree. During a Initializing union-find¶You can complete the initialization using either static or initialization interface. Initialize the parent pointer to point to itself and set the rank to 0. Example: struct uf_node my_node = UF_INIT_NODE(my_node); or
Find the Root Node of union-find¶This operation is mainly used to determine whether two nodes belong to the same set in the union-find. If they have the same root, they are in the same set. During the find operation, path compression is performed to improve the efficiency of subsequent find operations. Example: int connected;
struct uf_node *root1 = uf_find(&node_1);
struct uf_node *root2 = uf_find(&node_2);
if (root1 == root2)
connected = 1;
else
connected = 0;
Union Two Sets in union-find¶To uf_union(&node_1, &node_2); |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |