References etc.
This commit is contained in:
parent
22c35334dd
commit
3f203aaacf
77
kirj.tex
77
kirj.tex
|
@ -20,12 +20,6 @@
|
||||||
\emph{Programming Pearls}.
|
\emph{Programming Pearls}.
|
||||||
Addison-Wesley, 1986.
|
Addison-Wesley, 1986.
|
||||||
|
|
||||||
\bibitem{ber93}
|
|
||||||
O. Berkman and U. Vishkin.
|
|
||||||
Recursive star-tree parallel data structure.
|
|
||||||
\emph{SIAM Journal on Computing},
|
|
||||||
22(2):221--242, 1993.
|
|
||||||
|
|
||||||
\bibitem{cod15}
|
\bibitem{cod15}
|
||||||
Codeforces: On ''Mo's algorithm'',
|
Codeforces: On ''Mo's algorithm'',
|
||||||
\url{http://codeforces.com/blog/entry/20032}
|
\url{http://codeforces.com/blog/entry/20032}
|
||||||
|
@ -55,6 +49,11 @@
|
||||||
A new data structure for cumulative frequency tables.
|
A new data structure for cumulative frequency tables.
|
||||||
\emph{Software: Practice and Experience}, 24(3):327--336, 1994.
|
\emph{Software: Practice and Experience}, 24(3):327--336, 1994.
|
||||||
|
|
||||||
|
\bibitem{fis06}
|
||||||
|
J. Fischer and V. Heun.
|
||||||
|
Theoretical and practical improvements on the RMQ-problem, with applications to LCA and LCE.
|
||||||
|
In \emph{Annual Symposium on Combinatorial Pattern Matching}, 36--48, 2006.
|
||||||
|
|
||||||
\bibitem{fis11}
|
\bibitem{fis11}
|
||||||
J. Fischer and V. Heun.
|
J. Fischer and V. Heun.
|
||||||
Space-efficient preprocessing schemes for range minimum queries on static arrays.
|
Space-efficient preprocessing schemes for range minimum queries on static arrays.
|
||||||
|
@ -102,6 +101,11 @@
|
||||||
A method for the construction of minimum-redundancy codes.
|
A method for the construction of minimum-redundancy codes.
|
||||||
\emph{Proceedings of the IRE}, 40(9):1098--1101, 1952.
|
\emph{Proceedings of the IRE}, 40(9):1098--1101, 1952.
|
||||||
|
|
||||||
|
\bibitem{kar87}
|
||||||
|
R. M. Karp and M. O. Rabin.
|
||||||
|
Efficient randomized pattern-matching algorithms.
|
||||||
|
\emph{IBM Journal of Research and Development}, 31(2):249--260, 1987.
|
||||||
|
|
||||||
\bibitem{kas61}
|
\bibitem{kas61}
|
||||||
P. W. Kasteleyn.
|
P. W. Kasteleyn.
|
||||||
The statistics of dimers on a lattice: I. The number of dimer arrangements on a quadratic lattice.
|
The statistics of dimers on a lattice: I. The number of dimer arrangements on a quadratic lattice.
|
||||||
|
@ -117,6 +121,17 @@
|
||||||
On the shortest spanning subtree of a graph and the traveling salesman problem.
|
On the shortest spanning subtree of a graph and the traveling salesman problem.
|
||||||
\emph{Proceedings of the American Mathematical Society}, 7(1):48--50, 1956.
|
\emph{Proceedings of the American Mathematical Society}, 7(1):48--50, 1956.
|
||||||
|
|
||||||
|
\bibitem{ben00}
|
||||||
|
M. A. Bender and M. Farach-Colton.
|
||||||
|
The LCA problem revisited. In
|
||||||
|
\emph{Latin American Symposium on Theoretical Informatics}, 88--94, 2000.
|
||||||
|
|
||||||
|
\bibitem{mai84}
|
||||||
|
M. G. Main and R. J. Lorentz.
|
||||||
|
An $O(n \log n)$ algorithm for finding all repetitions in a string.
|
||||||
|
\emph{Journal of Algorithms}, 5(3):422--432, 1984.
|
||||||
|
|
||||||
|
|
||||||
\bibitem{pac13}
|
\bibitem{pac13}
|
||||||
J. Pachocki and J. Radoszweski.
|
J. Pachocki and J. Radoszweski.
|
||||||
Where to use and how not to use polynomial string hashing.
|
Where to use and how not to use polynomial string hashing.
|
||||||
|
@ -137,59 +152,9 @@
|
||||||
Gaussian elimination is not optimal.
|
Gaussian elimination is not optimal.
|
||||||
\emph{Numerische Mathematik}, 13(4):354--356, 1969.
|
\emph{Numerische Mathematik}, 13(4):354--356, 1969.
|
||||||
|
|
||||||
\bibitem{tar84}
|
|
||||||
R. E. Tarjan and U. Vishkin.
|
|
||||||
Finding biconnected components and computing tree functions
|
|
||||||
in logarithmic parallel time.
|
|
||||||
\emph{25th Annual Symposium on Foundations of Computer Science}, 12--20, 1984.
|
|
||||||
|
|
||||||
\bibitem{tem61}
|
\bibitem{tem61}
|
||||||
H. N. V. Temperley and M. E. Fisher.
|
H. N. V. Temperley and M. E. Fisher.
|
||||||
Dimer problem in statistical mechanics -- an exact result.
|
Dimer problem in statistical mechanics -- an exact result.
|
||||||
\emph{Philosophical Magazine}, 6(68):1061--1063, 1961.
|
\emph{Philosophical Magazine}, 6(68):1061--1063, 1961.
|
||||||
|
|
||||||
\end{thebibliography}
|
\end{thebibliography}
|
||||||
%
|
|
||||||
%
|
|
||||||
% \chapter*{Literature}
|
|
||||||
% \markboth{\MakeUppercase{Literature}}{}
|
|
||||||
% \addcontentsline{toc}{chapter}{Literature}
|
|
||||||
%
|
|
||||||
% \subsubsection{Textbooks on algorithms}
|
|
||||||
%
|
|
||||||
% \begin{itemize}
|
|
||||||
% \item T. H. Cormen, C. E. Leiserson,
|
|
||||||
% R. L Rivest and C. Stein:
|
|
||||||
% \emph{Introduction to Algorithms},
|
|
||||||
% MIT Press, 2009 (3rd edition)
|
|
||||||
% \item J. Kleinberg and É. Tardos:
|
|
||||||
% \emph{Algorithm Design},
|
|
||||||
% Pearson, 2005
|
|
||||||
% \item S. S. Skiena:
|
|
||||||
% \emph{The Algorithm Design Manual},
|
|
||||||
% Springer, 2008 (2nd edition)
|
|
||||||
% \end{itemize}
|
|
||||||
%
|
|
||||||
% \subsubsection{Textbooks on competitive programming}
|
|
||||||
%
|
|
||||||
% \begin{itemize}
|
|
||||||
% \item K. Diks, T. Idziaszek,
|
|
||||||
% J. Łącki and J. Radoszewski:
|
|
||||||
% \emph{Looking for a Challenge?},
|
|
||||||
% University of Warsaw, 2012
|
|
||||||
% \item S. Halim and F. Halim:
|
|
||||||
% \emph{Competitive Programming},
|
|
||||||
% 2013 (3rd edition)
|
|
||||||
% \item S. S. Skiena and M. A. Revilla:
|
|
||||||
% \emph{Programming Challenges: The Programming
|
|
||||||
% Contest Training Manual},
|
|
||||||
% Springer, 2003
|
|
||||||
% \end{itemize}
|
|
||||||
%
|
|
||||||
% \subsubsection{Other books}
|
|
||||||
%
|
|
||||||
% \begin{itemize}
|
|
||||||
% \item J. Bentley:
|
|
||||||
% \emph{Programming Pearls},
|
|
||||||
% Addison-Wesley, 1999 (2nd edition)
|
|
||||||
% \end{itemize}
|
|
2
kkkk.tex
2
kkkk.tex
|
@ -1,6 +1,6 @@
|
||||||
\documentclass[twoside,12pt,a4paper,english]{book}
|
\documentclass[twoside,12pt,a4paper,english]{book}
|
||||||
|
|
||||||
\includeonly{luku27,kirj}
|
\includeonly{luku18,kirj}
|
||||||
|
|
||||||
\usepackage[english]{babel}
|
\usepackage[english]{babel}
|
||||||
\usepackage[utf8]{inputenc}
|
\usepackage[utf8]{inputenc}
|
||||||
|
|
|
@ -353,10 +353,10 @@ time and even in $O(n)$ time.
|
||||||
|
|
||||||
Given an array of $n$ integers $x_1,x_2,\ldots,x_n$,
|
Given an array of $n$ integers $x_1,x_2,\ldots,x_n$,
|
||||||
our task is to find the
|
our task is to find the
|
||||||
\key{maximum subarray sum}, i.e.,
|
\key{maximum subarray sum}\footnote{Bentley's
|
||||||
|
book \emph{Programming Pearls} \cite{ben86} made this problem popular.}, i.e.,
|
||||||
the largest possible sum of numbers
|
the largest possible sum of numbers
|
||||||
in a contiguous region in the array\footnote{Jon Bentley's
|
in a contiguous region in the array.
|
||||||
book \emph{Programming Pearls} \cite{ben86} made this problem popular.}.
|
|
||||||
The problem is interesting when there may be
|
The problem is interesting when there may be
|
||||||
negative numbers in the array.
|
negative numbers in the array.
|
||||||
For example, in the array
|
For example, in the array
|
||||||
|
|
|
@ -245,7 +245,7 @@ to the position of $X$.
|
||||||
Next we will see how we can
|
Next we will see how we can
|
||||||
process range minimum queries in $O(1)$ time
|
process range minimum queries in $O(1)$ time
|
||||||
after an $O(n \log n)$ time preprocessing\footnote{There are also
|
after an $O(n \log n)$ time preprocessing\footnote{There are also
|
||||||
sophisticated techniques \cite{fis11} where the preprocessing time
|
sophisticated techniques \cite{fis06} where the preprocessing time
|
||||||
is only $O(n)$, but such algorithms are not needed in
|
is only $O(n)$, but such algorithms are not needed in
|
||||||
competitive programming.}.
|
competitive programming.}.
|
||||||
Note that minimum and maximum queries can always
|
Note that minimum and maximum queries can always
|
||||||
|
|
25
luku18.tex
25
luku18.tex
|
@ -85,9 +85,9 @@ as a sum where each term is a power of two.
|
||||||
|
|
||||||
\section{Subtrees and paths}
|
\section{Subtrees and paths}
|
||||||
|
|
||||||
\index{node array}
|
\index{tree traversal array}
|
||||||
|
|
||||||
A \key{node array}\footnote{A similar idea is sometimes called the \key{Euler tour technique} \cite{tar84}.} contains the nodes of a rooted tree
|
A \key{tree traversal array} contains the nodes of a rooted tree
|
||||||
in the order in which a depth-first search
|
in the order in which a depth-first search
|
||||||
from the root node visits them.
|
from the root node visits them.
|
||||||
For example, in the tree
|
For example, in the tree
|
||||||
|
@ -155,7 +155,7 @@ a depth-first search proceeds as follows:
|
||||||
|
|
||||||
\end{tikzpicture}
|
\end{tikzpicture}
|
||||||
\end{center}
|
\end{center}
|
||||||
Hence, the corresponding node array is as follows:
|
Hence, the corresponding tree traversal array is as follows:
|
||||||
\begin{center}
|
\begin{center}
|
||||||
\begin{tikzpicture}[scale=0.7]
|
\begin{tikzpicture}[scale=0.7]
|
||||||
\draw (0,0) grid (9,1);
|
\draw (0,0) grid (9,1);
|
||||||
|
@ -186,8 +186,8 @@ Hence, the corresponding node array is as follows:
|
||||||
\subsubsection{Subtree queries}
|
\subsubsection{Subtree queries}
|
||||||
|
|
||||||
Each subtree of a tree corresponds to a subarray
|
Each subtree of a tree corresponds to a subarray
|
||||||
in the node array,
|
in the tree traversal array such that
|
||||||
where the first element is the root node.
|
the first element in the subarray is the root node.
|
||||||
For example, the following subarray contains the
|
For example, the following subarray contains the
|
||||||
nodes in the subtree of node $4$:
|
nodes in the subtree of node $4$:
|
||||||
\begin{center}
|
\begin{center}
|
||||||
|
@ -265,7 +265,7 @@ is $3+4+3+1=11$.
|
||||||
\end{tikzpicture}
|
\end{tikzpicture}
|
||||||
\end{center}
|
\end{center}
|
||||||
|
|
||||||
The idea is to construct a node array that contains
|
The idea is to construct a tree traversal array that contains
|
||||||
three values for each node: (1) the identifier of the node,
|
three values for each node: (1) the identifier of the node,
|
||||||
(2) the size of the subtree, and (3) the value of the node.
|
(2) the size of the subtree, and (3) the value of the node.
|
||||||
For example, the array for the above tree is as follows:
|
For example, the array for the above tree is as follows:
|
||||||
|
@ -381,7 +381,7 @@ and calculate the sum of values in $O(\log n)$ time.
|
||||||
|
|
||||||
\subsubsection{Path queries}
|
\subsubsection{Path queries}
|
||||||
|
|
||||||
Using a node array, we can also efficiently
|
Using a tree traversal array, we can also efficiently
|
||||||
calculate sums of values on
|
calculate sums of values on
|
||||||
paths from the root node to any other
|
paths from the root node to any other
|
||||||
node in the tree.
|
node in the tree.
|
||||||
|
@ -484,7 +484,7 @@ For example, the following array corresponds to the above tree:
|
||||||
When the value of a node increases by $x$,
|
When the value of a node increases by $x$,
|
||||||
the sums of all nodes in its subtree increase by $x$.
|
the sums of all nodes in its subtree increase by $x$.
|
||||||
For example, if the value of node 4 increases by 1,
|
For example, if the value of node 4 increases by 1,
|
||||||
the node array changes as follows:
|
the array changes as follows:
|
||||||
|
|
||||||
\begin{center}
|
\begin{center}
|
||||||
\begin{tikzpicture}[scale=0.7]
|
\begin{tikzpicture}[scale=0.7]
|
||||||
|
@ -650,7 +650,7 @@ performed in $O(\log n)$ time.
|
||||||
\subsubsection{Method 2}
|
\subsubsection{Method 2}
|
||||||
|
|
||||||
Another way to solve the problem is based on
|
Another way to solve the problem is based on
|
||||||
a node array.
|
a tree traversal array \cite{ben00}.
|
||||||
Once again, the idea is to traverse the nodes
|
Once again, the idea is to traverse the nodes
|
||||||
using a depth-first search:
|
using a depth-first search:
|
||||||
|
|
||||||
|
@ -689,12 +689,13 @@ using a depth-first search:
|
||||||
\end{tikzpicture}
|
\end{tikzpicture}
|
||||||
\end{center}
|
\end{center}
|
||||||
|
|
||||||
However, in this problem,
|
|
||||||
we add each node to the node array \emph{always}
|
However, we use a bit different technique where
|
||||||
|
we add each node to the tree traversal array \emph{always}
|
||||||
when the depth-first search visits the node,
|
when the depth-first search visits the node,
|
||||||
and not only at the first visit.
|
and not only at the first visit.
|
||||||
Hence, a node that has $k$ children appears $k+1$ times
|
Hence, a node that has $k$ children appears $k+1$ times
|
||||||
in the node array, and there are a total of $2n-1$
|
in the array, and there are a total of $2n-1$
|
||||||
nodes in the array.
|
nodes in the array.
|
||||||
|
|
||||||
We store two values in the array:
|
We store two values in the array:
|
||||||
|
|
|
@ -196,7 +196,9 @@ from node $s$ using character $c$.
|
||||||
|
|
||||||
\key{String hashing} is a technique that
|
\key{String hashing} is a technique that
|
||||||
allows us to efficiently check whether two
|
allows us to efficiently check whether two
|
||||||
substrings in a string are equal.
|
substrings in a string are equal\footnote{The technique
|
||||||
|
was popularized by the Karp–Rabin pattern matching
|
||||||
|
algorithm \cite{kar87}.}.
|
||||||
The idea is to compare the hash values of the
|
The idea is to compare the hash values of the
|
||||||
substrings instead of their individual characters.
|
substrings instead of their individual characters.
|
||||||
|
|
||||||
|
@ -428,7 +430,10 @@ gives for each position $k$ in the string
|
||||||
the length of the longest substring
|
the length of the longest substring
|
||||||
that begins at position $k$ and is a prefix of the string.
|
that begins at position $k$ and is a prefix of the string.
|
||||||
Such an array can be efficiently constructed
|
Such an array can be efficiently constructed
|
||||||
using the \key{Z-algorithm} \cite{gus97}.
|
using the \key{Z-algorithm}\footnote{The Z-algorithm
|
||||||
|
was presented in \cite{gus97} as the simplest known
|
||||||
|
method for linear-time pattern matching, and the original idea
|
||||||
|
was attributed to \cite{mai84}.}.
|
||||||
|
|
||||||
For example, the Z-array for the string
|
For example, the Z-array for the string
|
||||||
\texttt{ACBACDACBACBACDA} is as follows:
|
\texttt{ACBACDACBACBACDA} is as follows:
|
||||||
|
|
Loading…
Reference in New Issue