MCPcopy Create free account
hub / github.com/douchuan/algorithm / QuickUnionUF

Class QuickUnionUF

src/common/uf.rs:62–65  ·  view source on GitHub ↗

In particular, suppose that we use quick-find for the dynamic connectivity problem and wind up with a single component. This requires at least N - 1 calls to union(), and, consequently, at least (N + 3)(N - 1) ~ N^2 array accesses —- we are led immediately to the hypothesis that dynamic connectivity with quick-find can be a quadratic-time process. Suppose that the input pairs come in the order 0-

Source from the content-addressed store, hash-verified

60/// and site i at depth 0). Thus, the total number of array accesses for the
61/// find() operations for these N pairs is 2 (1 + 2 + . . . + N ) ~ N^2
62pub struct QuickUnionUF {
63 parent: Vec<usize>, // parent[i] = parent of i
64 count: usize, // number of components
65}
66
67/// Rather than arbitrarily connecting the second tree to the first for union(),
68/// we keep track of the size of each tree and always connect the smaller tree to

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected