Skip to content

Commit

Permalink
backtrack
Browse files Browse the repository at this point in the history
  • Loading branch information
idf committed Oct 22, 2015
1 parent c1736c1 commit 30d1026
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
8 changes: 6 additions & 2 deletions chapterBacktracking.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -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:

Expand Down
20 changes: 20 additions & 0 deletions chapterBalancedSearchTree.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions chapterDynamicProgramming.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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<i \big) &\mbox{// if $s[k:i]$ is palindrome}
Expand Down
4 changes: 0 additions & 4 deletions chapterGreedy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@ \chapter{Greedy}


\section{Introduction}
Queue, Stack


\subsection{Summarizing properties}
TODO

3 changes: 0 additions & 3 deletions chapterSearch.tex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,3 @@ \section{Binary Search}
hi = mid
return lo-1
\end{python}

\section{Looping Root}
Iterate the list and make the current element as the root, evaluate the left part and the right part and combine the results (i.e. looping + divide \& conquer).
3 changes: 1 addition & 2 deletions chapterTree.tex
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ \subsection{Range search}
self.predecessors(root.right, target, stk)
\end{python}

\section{Interval Search Tree}
TODO



\section{Binary Index Tree (BIT)}\label{BIT}
Expand Down
2 changes: 2 additions & 0 deletions notation.tex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ \section*{General math notation}
$\sim$ & Tilde, the leading term of mathematical expressions \\
$\arg\max\limits_x f(x)$ & Argmax: the value $x$ that maximizes $f$\\
$\binom{n}{k}$ & $n$ choose $k$ , equal to $\frac{n!}{k!(n-k)!}$\\
$range(i,j)$ & range of number from i (inclusive) to j (exclusive) \\
$A[i:j]$ & subarray consist of $A_i, A_{i+1}, ..., A_{j-1}$.
\noalign{\smallskip}\hline\noalign{\smallskip}
\end{longtable}

Expand Down

0 comments on commit 30d1026

Please sign in to comment.