diff --git a/chapterBacktracking.tex b/chapterBacktracking.tex index 3bf2de4..795b52c 100644 --- a/chapterBacktracking.tex +++ b/chapterBacktracking.tex @@ -6,7 +6,7 @@ \section{Introduction} \section{Math} \subsection{Decomposition} -\subsubsection{Factorize a number}.\label{factorization} +\subsubsection{Factorize a number}\label{factorization} \rih{Core clues}: \begin{enumerate} \item Expand the search tree \textbf{horizontally}. @@ -31,11 +31,15 @@ \subsubsection{Factorize a number}.\label{factorization} n = cur.pop() start = cur[-1] if cur else 2 for i in xrange(start, int(sqrt(n))+1): - if n%i == 0: + if self.predicate(n, i): cur.append(i) cur.append(n/i) self.dfs(cur, ret) cur.pop() + +def predicate(self, n, i): + return n%i == 0 + \end{python} \rih{Time complexity.} $O(2^n)$ where $n$ is the number of prime factors. Choose $i$ prime factors to combine then, and keep the rest uncombined: diff --git a/chapterBalancedSearchTree.tex b/chapterBalancedSearchTree.tex index f32ee72..34a6ca5 100644 --- a/chapterBalancedSearchTree.tex +++ b/chapterBalancedSearchTree.tex @@ -117,6 +117,26 @@ \section{B-Tree} \caption{B-Tree} \label{fig:b-tree} \end{figure} +\subsection{Bascis} +Half-full principle: + +\begin{tabular}{lll} +\hline\noalign{\smallskip} +\textbf{Attrs} & \textbf{Non-leaf} & \textbf{Leaf} \\ +\noalign{\smallskip}\hline\noalign{\smallskip} +Ptrs & \lceil\frac{n+1}{2}\rceil & \lfloor\frac{n+1}{2}\rfloor \\ +\noalign{\smallskip}\hline\noalign{ +\caption{Nodes at least half-full} +\end{tabular} + +\subsection{Operations} +Core clues +\begin{enumerate} +\item \textbf{Split \& Up}: split half, move up the RIGHT node's FIRST of split nodes +recursively +\item The node moved up should be removed in the original node UNLESS it is a leaf +node. +\end{enumerate} \section{AVL Tree} TODO diff --git a/chapterDynamicProgramming.tex b/chapterDynamicProgramming.tex index e01311d..3f3ec88 100644 --- a/chapterDynamicProgramming.tex +++ b/chapterDynamicProgramming.tex @@ -121,14 +121,14 @@ \section{Sequence} \section{String} \runinhead{Is palindrome.} Given a string $s$, use an array to determine whether $s[i:j]$. -Let $P_{i,j}$ indicates whether $s[i:j]$ is palindrome. +Let $P_{i,j}$ indicates whether $s[i:j]$ is palindrome. We have one condition - whether the head and the end letter are equal: \begin{eqnarray*} -P_{i. j} = P_{i-1, j+1}\ \&\&\ s[i] = s[j-1] +P_{i. j} = P_{i-1, j+1}\ \wedge\ s[i] = s[j-1] \end{eqnarray*} \runinhead{Minimum palindrome cut.} Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s. -Let $C_i$ be the min cut for $s[:i]$. +Let $C_i$ be the min cut for $s[:i]$. We have 1 more cut from previous state to make $S[:i]$ palindrome. \begin{eqnarray*} C_{i} = \left\{ \begin{array}{rl} \min\big(C[k]+1 \cdot \forall k