Better definition for function f [closes #31]

This commit is contained in:
Antti H S Laaksonen 2017-04-17 11:23:40 +03:00
parent c1ac1df7dc
commit e010fb27e8
1 changed files with 4 additions and 5 deletions

View File

@ -21,8 +21,10 @@ For example, such queries are:
The $k$th \key{ancestor} of a node $x$ in a rooted tree The $k$th \key{ancestor} of a node $x$ in a rooted tree
is the node that we will reach if we move $k$ is the node that we will reach if we move $k$
levels up from $x$. levels up from $x$.
Let $f(x,k)$ denote the $k$th ancestor of $x$. Let $f(x,k)$ denote the $k$th ancestor of a node $x$
For example, in the following tree, $f(2,1)=1$ and $f(8,2)=4$. (or $0$ if there is no such an ancestor).
For example, in the following tree, $f(2,1)=1$, $f(8,2)=4$
and $f(5,2)=0$.
\begin{center} \begin{center}
\begin{tikzpicture}[scale=0.9] \begin{tikzpicture}[scale=0.9]
@ -74,9 +76,6 @@ $\cdots$ \\
\end{tabular} \end{tabular}
\end{center} \end{center}
The value $0$ means that the $k$th ancestor
of a node does not exist.
The preprocessing takes $O(n \log n)$ time, The preprocessing takes $O(n \log n)$ time,
because each node can have at most $n$ ancestors. because each node can have at most $n$ ancestors.
After this, any value of $f(x,k)$ can be calculated After this, any value of $f(x,k)$ can be calculated