Small fixes

This commit is contained in:
Antti H S Laaksonen 2017-05-06 13:28:57 +03:00
parent ab15bd6644
commit e1154777ab
1 changed files with 18 additions and 18 deletions

View File

@ -928,24 +928,27 @@ $d(5)=3$, $d(8)=4$ and $d(2)=2$,
so the distance between nodes 5 and 8 is so the distance between nodes 5 and 8 is
$3+4-2\cdot2=3$. $3+4-2\cdot2=3$.
\section{Offline queries} \section{Offline algorithms}
So far, we have discussed \emph{online} queries So far, we have discussed \emph{online} algorithms
where the queries have a fixed order and we that are able to efficiently process queries
answer each query before processing the next query. one after another in a given order.
In this section we focus on \emph{offline} queries In particular, we may require that the algorithm
where we are given a list of all queries and we processes each query before receiving the next query.
can process them in any order.
Processing offline queries may be easier than However, in many problems, the online
processing online queries, and in many problems property is not necessary.
it suffices to process offline queries. In this section, we focus on \emph{offline} algorithms
that are given a collection of queries that can be
processed in any order.
It is often easier to design an offline algorithm
compared to an online algorithm.
\subsubsection{Merging data structures} \subsubsection{Merging data structures}
A common method to process offline tree One method to construct an offline algorithm
queries is to traverse the tree is to traverse the tree recursively
recursively and maintain data structures for and maintain data structures for processing queries.
processing the queries.
At each node $s$, we create a data structure At each node $s$, we create a data structure
$\texttt{d}[s]$ that is based on the $\texttt{d}[s]$ that is based on the
data structures of the children of $s$. data structures of the children of $s$.
@ -957,10 +960,7 @@ We are given a tree where each node has some value.
Our task is to process queries of the form Our task is to process queries of the form
''calculate the number of nodes with value $x$ ''calculate the number of nodes with value $x$
in the subtree of node $s$''. in the subtree of node $s$''.
For example, in the following tree,
In the following tree, the
blue numbers denote the values of the nodes.
For example,
the subtree of node $4$ contains two nodes the subtree of node $4$ contains two nodes
whose value is 3. whose value is 3.