Change function union -> unite

This commit is contained in:
Antti H S Laaksonen 2017-03-12 10:13:29 +02:00
parent d41fcea986
commit 7681b72fda
1 changed files with 8 additions and 8 deletions

View File

@ -371,7 +371,7 @@ builds the minimum spanning tree as follows:
\begin{lstlisting} \begin{lstlisting}
for (...) { for (...) {
if (!same(a,b)) union(a,b); if (!same(a,b)) unite(a,b);
} }
\end{lstlisting} \end{lstlisting}
@ -381,11 +381,11 @@ where $a$ and $b$ are two nodes.
Two functions are needed: Two functions are needed:
the function \texttt{same} determines the function \texttt{same} determines
if the nodes are in the same component, if the nodes are in the same component,
and the function \texttt{union} and the function \texttt{unite}
joins the components that contain nodes $a$ and $b$. joins the components that contain nodes $a$ and $b$.
The problem is how to efficiently implement The problem is how to efficiently implement
the functions \texttt{same} and \texttt{union}. the functions \texttt{same} and \texttt{unite}.
One possibility is to implement the function One possibility is to implement the function
\texttt{same} as a graph traversal and check if \texttt{same} as a graph traversal and check if
we can get from node $a$ to node $b$. we can get from node $a$ to node $b$.
@ -408,7 +408,7 @@ a collection of sets.
The sets are disjoint, so no element The sets are disjoint, so no element
belongs to more than one set. belongs to more than one set.
Two $O(\log n)$ time operations are supported: Two $O(\log n)$ time operations are supported:
the \texttt{union} operation joins two sets, the \texttt{unite} operation joins two sets,
and the \texttt{find} operation finds the representative and the \texttt{find} operation finds the representative
of the set that contains a given element\footnote{The structure presented here of the set that contains a given element\footnote{The structure presented here
was introduced in 1971 by J. D. Hopcroft and J. D. Ullman \cite{hop71}. was introduced in 1971 by J. D. Hopcroft and J. D. Ullman \cite{hop71}.
@ -541,7 +541,7 @@ bool same(int a, int b) {
\end{lstlisting} \end{lstlisting}
\begin{samepage} \begin{samepage}
The function \texttt{union} joins the sets The function \texttt{unite} joins the sets
that contain elements $a$ and $b$ that contain elements $a$ and $b$
(the elements has to be in different sets). (the elements has to be in different sets).
The function first finds the representatives The function first finds the representatives
@ -549,7 +549,7 @@ of the sets and then connects the smaller
set to the larger set. set to the larger set.
\begin{lstlisting} \begin{lstlisting}
void union(int a, int b) { void unite(int a, int b) {
a = find(a); a = find(a);
b = find(b); b = find(b);
if (s[a] < s[b]) swap(a,b); if (s[a] < s[b]) swap(a,b);
@ -562,9 +562,9 @@ void union(int a, int b) {
The time complexity of the function \texttt{find} The time complexity of the function \texttt{find}
is $O(\log n)$ assuming that the length of each is $O(\log n)$ assuming that the length of each
chain is $O(\log n)$. chain is $O(\log n)$.
In this case, the functions \texttt{same} and \texttt{union} In this case, the functions \texttt{same} and \texttt{unite}
also work in $O(\log n)$ time. also work in $O(\log n)$ time.
The function \texttt{union} makes sure that the The function \texttt{unite} makes sure that the
length of each chain is $O(\log n)$ by connecting length of each chain is $O(\log n)$ by connecting
the smaller set to the larger set. the smaller set to the larger set.