Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
idf committed Oct 9, 2015
1 parent 2943bd0 commit 7bacb39
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
1 change: 1 addition & 0 deletions chapterBalancedSearchTree.tex
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ \section{B-Tree}
\end{figure}

\section{AVL Tree}
TODO
2 changes: 1 addition & 1 deletion chapterDynamicProgramming.tex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ \section{Introduction}

The so called concept dp as memoization of recursion does not grasp the core philosophy of dp.

The formula in the following section are unimportant. What is important is the definition of dp array and transition function derivation.
The formula in the following section are unimportant. Instead, what is important is the definition of dp array and transition function derivation.
\subsection{Common practice}
\rih{Dummy.} Use dummies to avoid using if-else conditional branch.
\begin{enumerate}
Expand Down
1 change: 1 addition & 0 deletions chapterGraph.tex
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ \subsection{Undirected Graph}
visited.add(k)
return True
\end{python}

\section{Topological Sorting}
For a graph $G=\{V, E\}$, $ A \rightarrow B $, then $A$ is before $B$ in the ordered list.
\subsection{Algorithm}
Expand Down
2 changes: 1 addition & 1 deletion chapterGreedy.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ \section{Introduction}


\subsection{Summarizing properties}

TODO

3 changes: 0 additions & 3 deletions chapterSearch.tex
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
\chapter{Search}


\section{Introduction}

\section{Binary Search}
Variants:
\begin{enumerate}
Expand Down
69 changes: 35 additions & 34 deletions chapterSort.tex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ \subsubsection{3-way pivoting}
return lt+1, gt
\end{python}

\section{Stability}
\subsection{Stability}
Definition: a stable sort preserves the \textbf{relative order of items with equal keys} (scenario: sorted by time then sorted by location).

Algorithms:
Expand All @@ -135,7 +135,7 @@ \section{Stability}
\label{fig:trie}
\end{figure}

\section{Applications}
\subsection{Applications}
\begin{enumerate}
\item Sort
\item Partial quick sort (selection), k-th largest elements
Expand All @@ -145,12 +145,44 @@ \section{Applications}
\item Data compression
\end{enumerate}

\subsection{Considerations}
\begin{enumerate}
\item Stable?
\item Distinct keys?
\item Need guaranteed performance?
\item Linked list or arrays?
\item Caching system? (reference to neighboring cells in the array?
\item Usually randomly ordered array?
(or partially sorted?)\item Parallel?
\item Deterministic?
\item Multiple key types?
\end{enumerate}

$O(N\lg N)$ is the lower bound of comparison-based sorting; but for other
contexts, we may not need $O(N \lg N)$:
\begin{enumerate}
\item Partially-ordered arrays: insertion sort to achieve $O(N)$. \textbf{Number of inversions}: 1 inversion $=$ 1 pair of keys that are out
of order.
\item Duplicate keys
\item Digital properties of keys: radix sort to achieve $O(N)$.
\end{enumerate}

\subsection{Summary}
\begin{figure}[hbtp]
\centering
\subfloat{\includegraphics[scale=0.80]{sort_summary}}
\caption{Sort summary}
\label{fig:trie}
\end{figure}


\section{Reversion}
If $a_i > a_j$ but $i<j$, then this is considered as 1 reversion.

\subsection{Calculation}
MergeSort to calculate the \#reverse-ordered paris. The only difference from a normal merge sort is that - when pushing the 2nd half of the array to the place, you calculate the reversion generated by the element $A_2[i_2]$ compared to $A_1[i_1:]$.
MergeSort to calculate the \#reverse-ordered paris. The only difference from a normal
merge sort is that - when pushing the 2nd half of the array to the place, you calculate
the reversion generated by the element $A_2[i_2]$ compared to $A_1[i_1:]$.

\begin{python}
def merge(A1, n1, A2, n2, A, n):
Expand Down Expand Up @@ -196,34 +228,3 @@ \subsection{Calculation}
return count
\end{python}



\section{Considerations}
\begin{enumerate}
\item Stable?
\item Distinct keys?
\item Need guaranteed performance?
\item Linked list or arrays?
\item Caching system? (reference to neighboring cells in the array?
\item Usually randomly ordered array?
(or partially sorted?)\item Parallel?
\item Deterministic?
\item Multiple key types?
\end{enumerate}

$O(N\lg N)$ is the lower bound of comparison-based sorting; but for other
contexts, we may not need $O(N \lg N)$:
\begin{enumerate}
\item Partially-ordered arrays: insertion sort to achieve $O(N)$. \textbf{Number of inversions}: 1 inversion $=$ 1 pair of keys that are out
of order.
\item Duplicate keys
\item Digital properties of keys: radix sort to achieve $O(N)$.
\end{enumerate}

\section{Summary}
\begin{figure}[hbtp]
\centering
\subfloat{\includegraphics[scale=0.90]{sort_summary}}
\caption{Sort summary}
\label{fig:trie}
\end{figure}

0 comments on commit 7bacb39

Please sign in to comment.