Skip to content

Commit

Permalink
more data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
joseproenca committed Nov 9, 2023
1 parent 5d87a08 commit 78b9dca
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
4 changes: 4 additions & 0 deletions slides/3-countingsteps.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified slides/6-data-structures.pdf
Binary file not shown.
44 changes: 39 additions & 5 deletions slides/6-data-structures.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 78b9dca

Please # to comment.