diff --git a/slides/3-countingsteps.tex b/slides/3-countingsteps.tex index c70e9e1..f71aefc 100755 --- a/slides/3-countingsteps.tex +++ b/slides/3-countingsteps.tex @@ -249,6 +249,10 @@ \section{Counting operations} \end{lstlisting} \end{column} \end{columns} +% T_sum(a,b) = b-a+1 +% T(N) = sum[i=0..N-1] sum[j=i..N-1] j-i+1 +% = sum[i=0..N-1] ((N-1-i+1)-(i-i+1))/2 * (N-i) +% = sum[i=0..N-1] (N-i)*(N-1-i)/2 % % T(N) = ... % = sum_i=0^(N-1) (N-i)*((N-1-i)/2) diff --git a/slides/6-data-structures.pdf b/slides/6-data-structures.pdf index 8168b68..15a4f4b 100644 Binary files a/slides/6-data-structures.pdf and b/slides/6-data-structures.pdf differ diff --git a/slides/6-data-structures.tex b/slides/6-data-structures.tex index eaa841e..081ed42 100755 --- a/slides/6-data-structures.tex +++ b/slides/6-data-structures.tex @@ -355,7 +355,7 @@ \section{Buffers (stacks and queueus)} \end{columns} -\only<2->{\doSimpleExercise{(Informally) what is the complexity of: \texttt{push}, \texttt{pop}, \texttt{head}?}} +\only<2->{\doSimpleExercise{(Informally) what is the expected complexity of: \texttt{push}, \texttt{pop}, \texttt{head}?}} % with static arrays % with linked lists @@ -799,23 +799,57 @@ \section{Dictionaries} \begin{columns}[t] \begin{column}{0.48\textwidth} - \begin{block}{Height-balanced} + \begin{alertblock}{Height-balanced} - more used - \\- left-height = right-height ± 1 (AVL) + \\- AVL: left-height = right-height ± 1 + \\- Red-black: similar wrt \emph{black} \\- height = $\log n$ - \end{block} + \end{alertblock} \end{column} \begin{column}{0.48\textwidth} \begin{block}{Weight-balanced} - less used \\- $\text{leafs-left/right} \geq \alpha \times \text{leafs}$, $0<\alpha<1$ + \\- better for lookup intensive systems \end{block} \end{column} - \end{columns} + \end{columns} +\end{frame} + + +\newcommand{\notyet}[1]{\textcolor{black!40}{\textit{#1}}} + +\begin{frame}\frametitle{AVL trees} +\centering + +\begin{itemize} + \item By Adelson-Velsky and Landis + \item Oldest self-balancing binary search tree data structure to be invented ('62) + \item Binary (left-right) search (sorted) tree + \item Labels in the nodes + \item At every node, the \alert{height of left and right trees differ at most by 1} + \item Insertions and removals preserve this +\end{itemize} + +\begin{tabular}{lcc@{~~~}cc} +\toprule +Function & Amortized & Worst Case + & \notyet{Amortized (RB)} & \notyet{Worst case (RB)} +\\\midrule +Search & ${\Theta(\log n)}$ & ${\mathcal{O}(\log n)}$ + & \notyet{${\mathcal{O}(\log n)}$} & \notyet{${\mathcal{O}(\log n)}$}\\ +Insert & ${\Theta(\log n)}$ & ${\mathcal{O}(\log n)}$ + & \notyet{${\mathcal{O}(1)}$} & \notyet{${\mathcal{O}(\log n)}$}\\ +Delete & ${\Theta(\log n)}$ & ${\mathcal{O}(\log n)}$ + & \notyet{${\mathcal{O}(1)}$} & \notyet{${\mathcal{O}(\log n)}$}\\ +\bottomrule +\end{tabular} \end{frame} + + \section{Graphs} \begin{frame}\frametitle{Overview}