From 7681b72fdab3abe53cd2483351a741bb3d8fe172 Mon Sep 17 00:00:00 2001 From: Antti H S Laaksonen Date: Sun, 12 Mar 2017 10:13:29 +0200 Subject: [PATCH] Change function union -> unite --- chapter15.tex | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/chapter15.tex b/chapter15.tex index 4be2643..57fb917 100644 --- a/chapter15.tex +++ b/chapter15.tex @@ -371,7 +371,7 @@ builds the minimum spanning tree as follows: \begin{lstlisting} for (...) { - if (!same(a,b)) union(a,b); + if (!same(a,b)) unite(a,b); } \end{lstlisting} @@ -381,11 +381,11 @@ where $a$ and $b$ are two nodes. Two functions are needed: the function \texttt{same} determines 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$. 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 \texttt{same} as a graph traversal and check if we can get from node $a$ to node $b$. @@ -408,7 +408,7 @@ a collection of sets. The sets are disjoint, so no element belongs to more than one set. 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 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}. @@ -541,7 +541,7 @@ bool same(int a, int b) { \end{lstlisting} \begin{samepage} -The function \texttt{union} joins the sets +The function \texttt{unite} joins the sets that contain elements $a$ and $b$ (the elements has to be in different sets). The function first finds the representatives @@ -549,7 +549,7 @@ of the sets and then connects the smaller set to the larger set. \begin{lstlisting} -void union(int a, int b) { +void unite(int a, int b) { a = find(a); b = find(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} is $O(\log n)$ assuming that the length of each 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. -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 the smaller set to the larger set.