Union-find: Difference between revisions

From Algowiki
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
{{#ev:youtube|https://youtu.be/wE8Y8TU-iUI|500|right|Chapters
#[00:00] Einführung
#[06:27] Wie funktioniert Union-Find nochmal?
#[07:03] Und wie war das noch mit der asymptotischen Komplexität?
|frame}}
== General information ==
== General information ==



Latest revision as of 13:58, 20 June 2015

Chapters
  1. [00:00] Einführung
  2. [06:27] Wie funktioniert Union-Find nochmal?
  3. [07:03] Und wie war das noch mit der asymptotischen Komplexität?

General information

Representation invariant:

  1. There is a nonnegative natural number NN, which is constant throughout the lifetime of the object.
  2. At any moment, there is a (dynamically changing) partition of S:={1,,N} into non-empty disjoint subsets. Each element of S belongs to exactly one of these partition sets.
  3. Each of these subsets SS is represented by an arbitrary particular member of S, which does not change as long as S is one of the partition sets (in other words, as long as S is not involved in any call of method unite).

Constructor: Receives N as its input and initializes the union-find object such that each i{1,,N} is a singleton {i}, which is represented by its unique member i.

Find

Input: An element i{1,,N}.

Output: The element j{1,,N} that represents the subset to which i currently belongs (i=j is possible).

Precondition: none.

Postcondition: none.

Unite

Input: Two elements, i,j{1,,N}.

Output: none.

Precondition: The elements i and j do not belong to the same subset. In other words, it is find(i) find(j).

Postcondition: The subsets to which i and j belong are united (the representative of the united set is not specified).

Known implementations

  1. Union-find with lists