diff --git a/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.pdf b/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.pdf new file mode 100644 index 0000000..6ed0ff9 Binary files /dev/null and b/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.pdf differ diff --git a/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.tex b/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.tex new file mode 100644 index 0000000..af24cd8 --- /dev/null +++ b/2019/2019-2/2019-10-Elementary _Data_Structure/2-10_ElementaryDataStructure.tex @@ -0,0 +1,53 @@ +\documentclass[UTF8,11pt,handout]{beamer} + +\input{mj_preamble_lecturenote} +\mode +\begin{document} + \author{MA Jun} + \title{Problem Solving} + \subtitle{2-10 Elementary Data Structure} + \logo{\includegraphics[width=0.05\textwidth]{figs/ICS_LOGO_left.png}} + \institute{Institute of Computer Software} + %\date{March 31, 2020} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} +\begin{frame}[plain] + \maketitle +\end{frame} +\begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-2}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[hideallsubsections] +\end{frame} +\AtBeginSection[]{ + \begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-1}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[currentsection] + \end{frame} +} + +\begin{frame} + \begin{block}{ + \begin{center} + {\huge + Thank You! + + \textcolor[rgb]{1,0,0} {Questions?} + } + \end{center} + } + \end{block} + \begin{block}{} + \begin{center} + + Office 819 + + majun@nju.edu.cn + \end{center} + \end{block} + \end{frame} +\end{document} \ No newline at end of file diff --git a/2019/2019-2/2019-10-Elementary _Data_Structure/figs/ICS_LOGO_left.png b/2019/2019-2/2019-10-Elementary _Data_Structure/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/2019/2019-2/2019-10-Elementary _Data_Structure/figs/ICS_LOGO_left.png differ diff --git a/2019/2019-2/2019-10-Elementary _Data_Structure/mj_preamble_lecturenote.tex b/2019/2019-2/2019-10-Elementary _Data_Structure/mj_preamble_lecturenote.tex new file mode 100644 index 0000000..3d40131 --- /dev/null +++ b/2019/2019-2/2019-10-Elementary _Data_Structure/mj_preamble_lecturenote.tex @@ -0,0 +1,22 @@ +\usepackage[utf8]{inputenc} +\usepackage{latexsym} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage[english]{babel} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} +\usepackage{graphicx} +\usepackage{tikz} +\usetikzlibrary{matrix,shapes,arrows,positioning,fit,backgrounds,calc} +\usepackage{overpic} +\usepackage[]{algorithm} +\usepackage[]{algpseudocode} % noend +\usepackage[most]{tcolorbox} +\usepackage{ulem} +\usepackage{fancybox} +\usetikzlibrary{decorations.pathreplacing} +\usetheme{Eastlansing} +\newcommand{\fallingfactorial}[1]{% + ^{\underline{#1}}% +} \ No newline at end of file diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/2-11_Heap&HeapSort.pdf b/2019/2019-2/2019-2-11-Heap&HeapSort/2-11_Heap&HeapSort.pdf new file mode 100644 index 0000000..0ac8165 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/2-11_Heap&HeapSort.pdf differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.pdf b/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.pdf new file mode 100644 index 0000000..b566397 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.pdf differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.tex b/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.tex new file mode 100644 index 0000000..0e7fc71 --- /dev/null +++ b/2019/2019-2/2019-2-11-Heap&HeapSort/2019-2-11_Heap&HeapSort.tex @@ -0,0 +1,765 @@ +\documentclass[UTF8,11pt]{beamer} +\input{../../../mj_preamble_lecturenote} +\mode +\begin{document} + \author{MA Jun} + \title{Problem Solving} + \subtitle{2-11 Heap \& Heapsort} + \logo{\includegraphics[width=0.05\textwidth]{figs/ICS_LOGO_left.png}} + \institute{Institute of Computer Software} + %\date{March 31, 2020} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} +\begin{frame}[plain] + \maketitle +\end{frame} + +\begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-2}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[hideallsubsections] +\end{frame} +\AtBeginSection[]{ + \begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-1}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[currentsection,hideallsubsections] + \end{frame} +} +\section{Heaps} +\subsection{Basic Idea} + +\begin{frame} +\centering{ + \includegraphics[width=0.4\linewidth]{figs/real_heap.png} + + Heap +} +\end{frame} + +\begin{frame} %生成目录页,目录太长时加选项[shrink] +\frametitle{Heaps} +\begin{block}{} + The (binary) heap data structure is \textbf{\teal{an array object}} that we can view as a \textbf{\color{blue}nearly complete binary tree} + \pause + \begin{itemize} + \item The tree is \teal{completely} filled on all levels {\color{blue}except possibly} the {\color{blue}lowest} + \end{itemize} +\end{block} +\begin{block}{} + \begin{center} + \includegraphics[width=.4\textwidth]{figs/heap_tree.png} +% \includegraphics[width=.3\textwidth]{figs/heap_array.png} +% \includegraphics[width=.2\textwidth]{figs/heap_array_parent_procedure.png} + \end{center} + +\end{block} +\end{frame} + +\begin{frame} %生成目录页,目录太长时加选项[shrink] +\frametitle{Heaps: Max-heap VS Min-heap} +\begin{columns} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{center} + \begin{tikzpicture} + \draw [] (0,0) node (a){12} circle (0.25cm); + \draw [] (-1,-1) node (b){10} circle (0.25cm); + \draw [] (1,-1) node (c){9} circle (0.25cm); + \draw [] (-1.5,-2) node (d){5} circle (0.25cm); + \draw [] (-0.5,-2) node (e){6} circle (0.25cm); + \draw [] (0.5,-2) node (f){1} circle (0.25cm); + \draw (a)--(b); + \draw (a)--(c); + \draw (b)--(d); + \draw (b)--(e); + \draw (c)--(f); + \end{tikzpicture} + \begin{block}{Max-heap property} + \begin{center} + $A\left[ Parent(i)\right]\ge A\left[ i\right] $ + \end{center} + \end{block} + \end{center} + \end{column} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{center} + \begin{tikzpicture} + \draw [] (0,0) node (a){1} circle (0.25cm); + \draw [] (-1,-1) node (b){5} circle (0.25cm); + \draw [] (1,-1) node (c){9} circle (0.25cm); + \draw [] (-1.5,-2) node (d){10} circle (0.25cm); + \draw [] (-0.5,-2) node (e){6} circle (0.25cm); + \draw [] (0.5,-2) node (f){12} circle (0.25cm); + \draw (a)--(b); + \draw (a)--(c); + \draw (b)--(d); + \draw (b)--(e); + \draw (c)--(f); + \end{tikzpicture} + \begin{block}{Min-heap property} + \begin{center} + $A\left[ Parent(i)\right]\le A\left[ i\right] $ + \end{center} + \end{block} + \end{center} + \end{column} +\end{columns} +\end{frame} + +\begin{frame} %生成目录页,目录太长时加选项[shrink] +\frametitle{Heaps: Storage} +\question{1}{Why do we implement a heap with an array?} + +\begin{block}{} + \begin{center} + \includegraphics[width=.4\textwidth]{figs/heap_tree.png} + \includegraphics[width=.3\textwidth]{figs/heap_array.png} + \onslide<2->{ + \includegraphics[width=.2\textwidth]{figs/heap_array_parent_procedure.png} + } + \end{center} +\begin{itemize} + \onslide<2->{ + \item Easy to index + } + \onslide<3->{ + \item Save memory + } + \onslide<4->{ + \item Better cache locality + } +\end{itemize} +\end{block} +\end{frame} + +\begin{frame} %生成目录页,目录太长时加选项[shrink] +\frametitle{Heaps: Height} +\begin{block}{The height of a node} + \begin{itemize} + \item The number of edges on the \teal{longest simple downward path} from the node to a leaf. + \end{itemize} + +\end{block} + +\pause +\begin{block}{The height of a heap} + \begin{itemize} + \item The height of its root, {\color{blue}$\Theta(\lg{n})$}. + \item A heap of $n$ elements is based on a \textbf{nearly complete binary tree} + + \end{itemize} +\end{block} +\begin{block}{} + \begin{center} + \begin{tikzpicture} + \node at (0,0){ + \includegraphics[width=.4\textwidth]{figs/heap_tree.png}}; + \footnotesize{ + \node at(0.7,1.2){h=3}; + \node at(1.7,0.5){h=1}; + + \node at(-1.7,0.5){h=2}; + + \node at(2.3,-0.2){h=0}; + \node at(-2.3,-0.2){h=1}; + + \node at(0,-0.9){h=0}; + } + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} + + +\begin{frame} +\frametitle{Heaps: basic operations} +\begin{block}{} + \begin{tikzpicture} + \node at(0,0) {\includegraphics[width=0.9\textwidth]{figs/operations_on_heap.PNG}}; + \coordinate (c1l) at(-4.3,1.8); + \coordinate (c1r) at(-2.2,1.8); + \coordinate (c2l) at(-4.3,0.9); + + \coordinate (c3l) at(-4.3,-0.9); + \coordinate (c3t) at(-2.85,-0.7); + + \coordinate (c4t) at(0.5,-0.7); + + \coordinate (c5t) at(3.75,-0.7); + + \pause + \draw [color=blue,thick] (-4.3,1.6) rectangle +(2.1,0.4); + \pause + \draw [color=blue,thick] (-4.3,0.7) rectangle +(2.7,0.4); + \draw [color=blue,->, >=triangle 45] (c2l).. controls (-5,0.9) and (-5,1.8)..(c1l); + \pause + \draw [color=red,thick] (-4.3,-0.2) rectangle +(1.6,0.4); + + \pause + \draw [color=blue,thick] (-4.3,-1.1) rectangle +(2.9,0.4); + \draw [color=blue,thick] (-1.2,-1.1) rectangle +(3.1,0.4); + \draw [color=blue,thick] (2.1,-1.1) rectangle +(3.3,0.4); + \draw [color=blue,thick] (-4.3,-1.55) rectangle +(2.5,0.4); + + \pause + \draw [color=blue,->, >=triangle 45] (c3t).. controls (-2.85,0) and (3.75,0)..(c5t); + \draw [color=blue,->, >=triangle 45] (c4t).. controls (-2,0.5) and (3,0.5)..(c1r); + \pause + \draw [color=red,thick] (-1.1,-2) rectangle +(2,0.4); + \end{tikzpicture} + +\end{block} +\end{frame} +\subsection{Maintaining the heap property} +\begin{frame} +\frametitle{ Maintaining the heap property: \textproc{Max-Heapify}} +\begin{center} + \question{2}{ Can you explain the process of \textproc{Max-Heapify}} + \begin{center} + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=0.45\textwidth]{figs/MAX-HEAPIFY.PNG}}; + + + + \pause + \draw [color=red,thick] (-2.2,0.8) rectangle (-0.3,1.5)node(a){}; + \node (b)at (4,1.5) [fill= green!50!black!20!,text width=7cm]{ \footnotesize{\textbf{\color{blue}Pre-condition:}$Left(i)$ and $Right(i)$ are maxheaps.}}; + \node (e)at (6,0.5) [fill= green!50!black!20!,text width=5cm]{ \footnotesize{\textbf{\color{blue}Post-condition:}the tree rooted at $i$ is a maxheap.}}; + + \draw [color=red,->,thick] (b)--(a); + + \pause + \draw [color=red,thick] (-1.85,-1.2) rectangle +(0.9,0.3); + \node (c) at (5,-1) [fill= green!50!black!20!,text width=4cm]{ \footnotesize{\parbox{4cm}{index of the largest element in the tree rooted at $i$}}}; + + \draw [color=gray,thick] (-2.2,-1.2) rectangle +(5,2); + + \pause + \draw [color=blue,thick] (-1.6,-1.9) rectangle (1.5,-1.45); + \end{tikzpicture} + + \end{center} + + + \includegraphics[width=0.32\textwidth]{figs/MAX-HEAPIFY(a).PNG} + \includegraphics[width=0.32\textwidth]{figs/MAX-HEAPIFY(b).PNG} + \includegraphics[width=0.32\textwidth]{figs/MAX-HEAPIFY(c).PNG} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{ Maintaining the heap property: \textproc{Max-Heapify}} +\begin{center} + \begin{block}{\textbf{\color{blue}Worst-case} for \textproc{Max-Heapify}} + \begin{columns} + \begin{column}[T]{0.45\textwidth} + + \begin{center} + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=\textwidth]{figs/MAX-HEAPIFY.PNG}}; + + \onslide<2> + \draw [color=gray,thick] (-2.2,-1.2) rectangle +(5,2); + \onslide<3> + \draw [color=blue,thick] (-1.6,-1.9) rectangle (1.5,-1.45); + \end{tikzpicture} + + \end{center} + + \end{column} + \begin{column}[T]{0.5\textwidth} + The running time of \textproc{Max-Heapify} on a subtree of size $n$ rooted at a given node $i$ is the sum of: + \begin{itemize} + + \onslide<2->{ \item Time to find the \teal{largest}, {\color{green}$\Theta(1)$}} + + \onslide<3->{ \item Time to run \textproc{Max-Heapify} recursively, $\le {\color{red}T(2n/3)}$} + \end{itemize} + + \end{column} + \end{columns} + \end{block} + \onslide<4->{ + \fbox{\color{blue}$T(n)\le {\color{red}T(2n/3)}+{\color{green}\Theta(1)}=O(\lg{n})\onslide<4->{=O(h)}$} + } +\end{center} +\end{frame} + +\begin{frame} +\frametitle{ Maintaining the heap property: \textproc{Max-Heapify}} + +\begin{block}{\textbf{\color{blue}Worst-case} for \textproc{Max-Heapify}} + \begin{center} + Time to run \textproc{Max-Heapify} recursively, $\le {\color{red}T(2n/3)}$ + \vspace{0.3cm} + \begin{tikzpicture} + \onslide<2-> + \filldraw [fill=white](0,0) circle (0.2) node(n1){$i$}; + + \filldraw [fill=white](-1,-1) circle (0.2) node(n2){$l$}; + \filldraw [gray,fill=lightgray] (1,-1)--(0.5,-2)--(1.5,-2)--cycle; + \filldraw [fill=white](1,-1) circle (0.2) node(n3){$r$}; + \filldraw [fill=white](-2,-2) circle (0.05) node(n4){ }; + \filldraw [fill=white](0,-2) circle (0.05) node(n5){ }; + \draw (n1)--(n2); + \draw (n1)--(n3); + + \filldraw [gray,fill=lightgray] (-2,-2)--(-2.5,-3)--(-1.5,-3)--cycle; + \filldraw [gray,fill=lightgray] (0,-2)--(-0.5,-3)--(0.5,-3)--cycle; + \draw (n2)--(n4); + \draw (n2)--(n5); + + \onslide<3-> + \node at (-0.5,-3.5) {The subtree rooted at $l$ is full}; + %number of nodes in subtrees + \onslide<4-> + \node at(-2,-2.5) {X}; + \node at(0,-2.5) {X}; + \node at(1,-1.5) {X}; + \end{tikzpicture} + \begin{itemize} + \onslide<5->{ \item Total number of nodes $n=3X+2$} + \onslide<6->{ \item Total number of nodes in the left subtree $2X+1$} + \onslide<7->{ \item $\frac{2X+1}{3X+2}<2/3$} + \end{itemize} + \end{center} +\end{block} +\end{frame} + +\subsection{Building a heap} +\begin{frame} +\frametitle{Building a heap: \textproc{Build-Max-Heap}} +\begin{center} + \begin{columns} + \begin{column}[T]{0.4\textwidth} + \question{3}{ Can you explain the process of \textproc{Build-Max-Heap}} + \begin{center} + \begin{tikzpicture} + \node at (0,0) { \includegraphics[width=\textwidth]{figs/BUILD-MAX-HEAP_procedure.png} }; + \onslide<2->{ + \draw [color=red,thick](-1.4,-0.4) rectangle +(2.4,0.4); + } + \end{tikzpicture} + + \end{center} + + \onslide<4->{ + \question{4}{Can you prove the correctness of \textproc{Build-Max-Heap}?} + } + \end{column} + \begin{column}[T]{0.55\textwidth} + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=0.9\textwidth]{figs/BUILD-MAX-HEAP_example.png}}; + \onslide<2->{ + \draw [color=red,thick] (-1.4,3.4)--(-1.4,3); + } + \onslide<3->{ + \draw [dashed,color=blue](-3,1.6)--(-1.4,1.6)--(-1.4,2)--(0,2)--(0,1.5)--(-1.2,1.5)--(-1.2,1.1)node[below]{\footnotesize{one-element heaps}}--(-3,1.1)--cycle ; + } + \end{tikzpicture} + + \end{column} + \end{columns} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Correctness of \textproc{Build-Max-Heap}} +\begin{center} +\begin{block}{Invariant} +\teal{ At the start of each iteration of the for loop of lines 2-3, each node $i+1,i+2,\cdots,n$ is the root of a max-heap. } +\end{block} + +\pause +\begin{proof} + \begin{tikzpicture} + \node at(0,0) { \includegraphics[width=0.9\textwidth]{figs/proof_correctness_build_max_heap.png}}; + \pause + \draw [color=red,thick] (-5,1.5)--(0,1.5); + \pause + \draw [color=red,thick] (-3.4,-0.2)--(-0.5,-0.2); + \pause + \draw [color=red,thick] (-1.4,-1.8)--(-0.4,-1.8); + \end{tikzpicture} +\end{proof} +\end{center} +\end{frame} +\begin{frame}[t] +\frametitle{Running time of \textproc{Build-Max-Heap}} +\begin{center} + \includegraphics[width=0.5\textwidth]{figs/BUILD-MAX-HEAP_procedure.png} + + \pause + \begin{block}{A poor upper bound} + \begin{itemize} + \item Each call to \textproc{ Max-Heapify} costs $O(\lg{n})$ + \item At most $O(n)$ calls + \item Thus, \textbf{\color{blue}$O(n\lg{n})$} + \end{itemize} + \end{block} + + \pause + \question{5}{Can you give a better one?} +\end{center} +\end{frame} + +\begin{frame}[t] +\frametitle{Running time of \textproc{Build-Max-Heap}} +\begin{center} + \begin{block}{A tighter linear upper bound} + \begin{itemize} + \pause + \item An $n$-element heap has height {\color{teal}$\lfloor\lg{n}\rfloor$}. + + \pause + \item At most {\color{teal}$\lceil n/{2^{h+1}}\rceil$} nodes of any height $h$. + + \pause + \item Thus, + \[ + \sum\limits_{h=0}^{\lfloor\lg{n}\rfloor}{\lceil\frac{n}{2^{h+1}}\rceil O(h)} + \pause + =O\left(n \sum\limits_{h=0}^{\lfloor\lg{n}\rfloor}{\frac{h}{2^h}}\right)\pause + =O\left(n \sum\limits_{h=0}^{\infty}{\frac{h}{2^h}}\right) + ={\color{blue}O(2n)} + ={\color{blue}O(n)} + \] + + \pause + \centering{\teal{\fbox{ + $ + \sum\limits_{h=0}^{\lfloor\lg{n}\rfloor}{\frac{h}{2^h}}\le \sum\limits_{h=0}^{\infty}{\frac{h}{2^h}}=\frac{1/2}{(1-{1/2})^2}=2$ + }}} + \end{itemize} + \end{block} +\end{center} +\end{frame} + +\subsection{Inserting an element} +\begin{frame} +\frametitle{Inserting an element into a Heap} +\begin{center} + \begin{tikzpicture} + \node at (0,0) { \includegraphics[width=0.5\textwidth]{figs/insert_example.png}}; + \pause + \node at (3,-2) [color=blue]{$O(\lg{n})$}; + \end{tikzpicture} + + \begin{itemize} + \item \textbf{\color{blue}Step-1}: \red{Add} the new element to the \teal{end} of the heap + \item \textbf{\color{blue}Step-2}: \red{Compare} the new element to its \teal{parent}, if it is greater than its parent, \red{swap} the two elements + \item \textbf{\color{blue}Step-3}: \red{Repeat} step-2 until the new element is smaller than its parent or it is the root. + \end{itemize} +\end{center} +\end{frame} + +\subsection{Inserting an element} +\begin{frame} +\frametitle{Build heap with insertion?} +\begin{center} + \begin{itemize} + \item Insert $A[1,..,n]$ to a heap one by one. + \item Complexity? + \end{itemize} +\end{center} +\end{frame} + +\subsection{Deleting an element} +\begin{frame} +\frametitle{Deleting an element from a Heap} +Assume that we try to delete a node $i$ +\begin{center} + \pause + \begin{itemize} + \item \textbf{\color{blue}Step-1}: \red{Copy} the value of the \teal{last} node to node $i$ + \item \textbf{\color{blue}Step-2}: \red{Remove} the last node + \item \textbf{\color{blue}Step-3}: \red{Call} \textproc{Max-Heapify} on node $i$ + \end{itemize} + + \begin{tikzpicture} + %init + \footnotesize{ + \draw (0,0) circle (0.2) node(n1){13}; + \draw (-1,-1) circle (0.2) node(n2){12}; + \draw (1,-1) circle (0.2) node(n3){10}; + \draw (-1.5,-2) circle (0.2) node(n4){8}; + \draw (-0.5,-2) circle (0.2) node(n5){7}; + \draw (0.5,-2) circle (0.2) node(n6){9}; + \draw (1.5,-2) circle (0.2) node(n7){6}; + \draw (n1)--(n2); + \draw (n1)--(n3); + \draw (n2)--(n4); + \draw (n2)--(n5); + \draw (n3)--(n6); + \draw (n3)--(n7); + \pause + \node at (0,-2.5){Delete 12}; + \draw (-1,-1) circle (0.2) node[color=lightgray]{12}; + } + + \pause + \draw [->,>=triangle 45, line width=2pt](1.6,-1)--+(1,0); + \footnotesize{ + \draw [xshift=4cm] (0,0) circle (0.2) node(n1){13}; + \draw [xshift=4cm] (-1,-1) circle (0.2) node(n2)[color=blue]{6}; + \draw [xshift=4cm] (1,-1) circle (0.2) node(n3){10}; + \draw [xshift=4cm] (-1.5,-2) circle (0.2) node(n4){8}; + \draw [xshift=4cm] (-0.5,-2) circle (0.2) node(n5){7}; + \draw [xshift=4cm] (0.5,-2) circle (0.2) node(n6){9}; + \draw [xshift=4cm] (1.5,-2) circle (0.2) node(n7){6}; + \draw [xshift=4cm] (n1)--(n2); + \draw [xshift=4cm] (n1)--(n3); + \draw [xshift=4cm] (n2)--(n4); + \draw [xshift=4cm] (n2)--(n5); + \draw [xshift=4cm] (n3)--(n6); + \draw [xshift=4cm] (n3)--(n7); + \draw[xshift=4cm,color=red,dashed,->,>=triangle 45] (n7) .. controls (n3) and (0,-1) .. (n2); + \node [xshift=3cm]at (0,-3){\parbox{4cm}{\centering{Copy 6 to the node to be deleted}}}; + } + \pause + \draw [xshift=4cm,->,>=triangle 45, line width=2pt](1.6,-1)--+(1,0); + \footnotesize{ + \draw [xshift=8cm] (0,0) circle (0.2) node(n1){13}; + \draw [xshift=8cm] (-1,-1) circle (0.2) node(n2)[color=blue]{6}; + \draw [xshift=8cm] (1,-1) circle (0.2) node(n3){10}; + \draw [xshift=8cm] (-1.5,-2) circle (0.2) node(n4){8}; + \draw [xshift=8cm] (-0.5,-2) circle (0.2) node(n5){7}; + \draw [xshift=8cm] (0.5,-2) circle (0.2) node(n6){9}; + \draw [xshift=8cm] (n1)--(n2); + \draw [xshift=8cm] (n1)--(n3); + \draw [xshift=8cm] (n2)--(n4); + \draw [xshift=8cm] (n2)--(n5); + \draw [xshift=8cm] (n3)--(n6); + \node [xshift=8cm]at (0,-3){\parbox{4cm}{\centering{Delete the last node}}}; + } + \end{tikzpicture} +\end{center} +\end{frame} + +\section{Heapsort} +\begin{frame} +\frametitle{Heapsort} +\begin{center} + \includegraphics[width=0.5\textwidth]{figs/heapsort_procedure.png} + + \includegraphics[width=0.9\textwidth]{figs/heapsort_example.png} +\end{center} +\end{frame} +\begin{frame} +\frametitle{Heapsort: Correctness} +\begin{center} + \includegraphics[width=0.5\textwidth]{figs/heapsort_procedure.png} + + \question{6}{How to prove the correctness of \textproc{Heapsort}?} + + \pause + \begin{block}{Loop Invariant (\teal{Exercise 6.4-2})} + \fbox{\parbox{\textwidth}{At the start of each iteration of the for loop of lines 2-5, + \begin{itemize} + \item the subarray \teal{$A[1..i]$} is a max-heap containing the $i$ smallest elements of $A[1..n]$, + \item the subarray \teal{$A[i+1..n]$} contains the $n-i$ largest elements of $A[1..n]$, \red{sorted}. + \end{itemize} + + }} + \end{block} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{In-place sorting} +\begin{center} + \begin{block}{In-place sorting algorithms} + Algorithms require {\color{blue}$O(1)$} extra space and sorting is said to be + happened in-place, or for example, within the array itself. + \pause + \begin{itemize} + \item \textproc{Bubble-sort} {\color{green}\cmark} + \item \textproc{Insertion-sort} {\color{green}\cmark} + \item \textproc{Heapsort} {\color{green}\cmark} + \item \textproc{Mergesort} {\color{green}\cmark} + \item \textproc{Quicksort}{\color{red}\xmark} + \end{itemize} + \end{block} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Review \textproc{Quicksort}} +\begin{center} + + \question{7}{Why is \textproc{Quicksort} more efficient in practice?} + \pause + \begin{block}{Based on a \textbf{fix computer model}!} + \begin{itemize} + \item \textproc{QuickSort}: $11.667(n+1)\ln{n}-1.74n-18.74$ + \item \textproc{MergeSort}: $12.5n\ln{n}$ + \item \textproc{HeapSort}: $16n\ln{n}+0.01n$ + \item \textproc{InsertionSort}: $2.25n^2+7.75n-3\ln{n}$ + \end{itemize} + \end{block} + \begin{tikzpicture} + \node at(-4,0){\includegraphics[width=0.15\linewidth]{figs/Donald-Knuth.jpg}}; + \node at(-4,-1.5) {Donald Knuth}; + \node at (0,0) {\includegraphics[width=0.18\linewidth]{figs/TAOCP_V3.png}}; + \node at (1,-2) {\tiny{\href{https://www-cs-faculty.stanford.edu/\%7Eknuth/taocp.html}{https://www-cs-faculty.stanford.edu/~knuth/taocp.html}}}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Review \textproc{Quicksort}} +\begin{center} + + \question{7}{Why is \textproc{Quicksort} more efficient in practice?} + + \begin{block}{Analyze \textbf{abstract basic operations}! \teal{\#swap \& \#comparison}} + + \begin{itemize} + \item \textproc{QuickSort}: $2n\ln{n}$ comparisons and $\frac{1}{3}n\ln{n}$ swaps on average + \item \textproc{MergeSort}: $1.44n\ln{n}$ comparisons, but up to $8.66nln(n)$ array accesses (mergesort is not swap based, so we cannot count that). + \item \textproc{InsertionSort}: $\frac{1}{4}n^2$ comparisons and $\frac{1}{4}n^2$ swaps on average. + \end{itemize} + \end{block} + \begin{tikzpicture} + \node at(-4,0){\includegraphics[width=0.15\linewidth]{../../Homework/2-9-sorting-and-selection/figs/robert-sedgewick}}; + \node at(-4,-1.5) {Robert Sedgewick}; + \node at (0,0) {\includegraphics[width=0.2\linewidth]{figs/Book_Algorithms.jpg}}; + \node at (1,-2) {\tiny{\href{https://algs4.cs.princeton.edu/home/}{https://algs4.cs.princeton.edu/home/}}}; + \end{tikzpicture} + +\end{center} +\end{frame} + +\section{Priority Queue} +\begin{frame}[t] +\frametitle{Priority Queue: ADT} +\begin{center} + \begin{block}{\textbf{Priority queue}} + A data structure for maintaining a set $S$ of elements, each with an associated value called a {\color{red}key}. + \end{block} + \pause + \begin{block}{A \textbf{max-priority queue} supports the following operations:} + \includegraphics[width=0.9\textwidth]{figs/priority_queue_operations.png} + \end{block} +\end{center} +\end{frame} + +\begin{frame}[t] +\frametitle{Priority Queue: ADT} +\begin{center} + \question{8}{What is key difference between a Queue and a Priority-queue?} +\end{center} +\begin{columns} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{block}{Queue} + \textbf{\teal{FIFO}}: First-In-First-Out + \end{block} + + \end{column} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{block}{Priority Queue} + \begin{itemize} + \item \teal{Order} does not matter + \item \teal{Priority} matters + \end{itemize} + \end{block} + \end{column} +\end{columns} +\end{frame} + + +\begin{frame}[t] +\frametitle{Priority Queue: Implementation} +\begin{center} + \begin{block}{ Heap $\rightarrow$ Priority Queue} + \end{block} + \begin{tikzpicture} + \node at(-4,3) {\fbox{\includegraphics[width=0.25\textwidth]{figs/pq_heap_maximum.png}}}; + \node at(-4,0) {\fbox{\includegraphics[width=0.4\textwidth]{figs/pq_HEAP-EXTRACT-MAX.png}}}; + \node at(2,2.2) {\fbox{\includegraphics[width=0.5\textwidth]{figs/pq_HEAP-INCREASE-KEY.png}}}; + \node at(2,-0.8) {\fbox{\includegraphics[width=0.5\textwidth]{figs/pq_MAX-HEAP-INSERT.png}}}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame}[t] +\frametitle{Priority Queue: Applications} + +\begin{block}{Message Queue} + In the cloud, a message queue is typically used to delegate tasks to background processing. + \begin{center} + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=0.9\linewidth]{figs/priority-queue-pattern.png}}; + \node at(0,-3){\tiny{\href{https://docs.microsoft.com/en-us/azure/architecture/patterns/priority-queue}{https://docs.microsoft.com/en-us/azure/architecture/patterns/priority-queue}}}; + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} + +\begin{frame}[t] +\frametitle{Priority Queue: Applications} +\begin{block}{Message Queue (Without Priority Queue)} + \begin{center} + \begin{tikzpicture} + \node at(0,0){\includegraphics[height=0.7\textheight]{figs/priority-queue-separate.png}}; + \node at(0,-3){\tiny{\href{https://docs.microsoft.com/en-us/azure/architecture/patterns/priority-queue}{https://docs.microsoft.com/en-us/azure/architecture/patterns/priority-queue}}}; + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} + +\begin{frame}[t] +\frametitle{Priority Queue: Applications} +\begin{block}{Dijkstra's Shortest Path Algorithm} + \begin{center} + \begin{tikzpicture} + \node at(-5,0){\includegraphics[width=0.2\linewidth]{figs/dijkstra.jpg}}; + \node at(-5,-2){\parbox{3cm}{\scriptsize{ Edsger W. Dijkstra.\\ + 1972 ACM A.M. Turing Award winner}}}; + \node at(0,0){ \animategraphics[autoplay,loop,width=0.35\textwidth]{3}{figs/Dijkstra_Animation-}{0}{42}}; + \node at(0,-2.5){\tiny{\href{https://en.wikipedia.org/wiki/Dijkstra\%27s\_algorithm}{https://en.wikipedia.org/wiki/Dijkstra\%27s\_algorithm}}}; + \end{tikzpicture} + \end{center} + \footnotesize{\blue{``I designed in about twenty minutes''}. + + In 1956, ``One morning I was shopping in Amsterdam with my young fiancée, and tired, we sat down on the café terrace to drink a cup of coffee and I was just thinking about whether I could do this, and I then designed the algorithm for the shortest path''} +\end{block} +\end{frame} + +\begin{frame}[t] +\frametitle{Priority Queue: Applications} +\begin{block}{Prim Algorithm for MST} + \begin{center} + \begin{tikzpicture} + \node at(0,0){ \animategraphics[autoplay,loop,width=0.4\textwidth]{3}{figs/PrimAlgDemo-}{0}{57}}; + \node at(0,-3){\tiny{\href{https://en.wikipedia.org/wiki/Dijkstra\%27s\_algorithm}{https://en.wikipedia.org/wiki/Dijkstra\%27s\_algorithm}}}; + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} + + +\begin{frame} + \begin{block}{ + \begin{center} + {\huge + Thank You! + + \textcolor[rgb]{1,0,0} {Questions?} + } + \end{center} + } + \end{block} + \begin{block}{} + \begin{center} + + Office 819 + + majun@nju.edu.cn + \end{center} + \end{block} + \end{frame} +\end{document} \ No newline at end of file diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_example.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_example.PNG new file mode 100644 index 0000000..4cfd8ed Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_example.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_procedure.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_procedure.PNG new file mode 100644 index 0000000..1758131 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/BUILD-MAX-HEAP_procedure.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Book_Algorithms.jpg b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Book_Algorithms.jpg new file mode 100644 index 0000000..20ae50c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Book_Algorithms.jpg differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-0.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-0.png new file mode 100644 index 0000000..740c447 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-0.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-1.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-1.png new file mode 100644 index 0000000..7055ad8 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-1.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-10.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-10.png new file mode 100644 index 0000000..aaf03be Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-10.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-11.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-11.png new file mode 100644 index 0000000..472893a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-11.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-12.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-12.png new file mode 100644 index 0000000..b979c66 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-12.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-13.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-13.png new file mode 100644 index 0000000..df4ec7e Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-13.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-14.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-14.png new file mode 100644 index 0000000..9a67ad4 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-14.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-15.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-15.png new file mode 100644 index 0000000..16a8a02 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-15.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-16.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-16.png new file mode 100644 index 0000000..9a67ad4 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-16.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-17.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-17.png new file mode 100644 index 0000000..d967683 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-17.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-18.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-18.png new file mode 100644 index 0000000..df4ec7e Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-18.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-19.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-19.png new file mode 100644 index 0000000..039e33c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-19.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-2.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-2.png new file mode 100644 index 0000000..4c7828f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-2.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-20.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-20.png new file mode 100644 index 0000000..b91a96f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-20.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-21.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-21.png new file mode 100644 index 0000000..039e33c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-21.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-22.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-22.png new file mode 100644 index 0000000..33e7550 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-22.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-23.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-23.png new file mode 100644 index 0000000..51e26f1 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-23.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-24.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-24.png new file mode 100644 index 0000000..249c0c2 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-24.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-25.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-25.png new file mode 100644 index 0000000..023123b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-25.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-26.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-26.png new file mode 100644 index 0000000..75fdaa2 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-26.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-27.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-27.png new file mode 100644 index 0000000..023123b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-27.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-28.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-28.png new file mode 100644 index 0000000..9c8262b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-28.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-29.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-29.png new file mode 100644 index 0000000..40ae4a6 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-29.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-3.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-3.png new file mode 100644 index 0000000..7055ad8 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-3.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-30.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-30.png new file mode 100644 index 0000000..46ee1ae Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-30.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-31.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-31.png new file mode 100644 index 0000000..f082a1b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-31.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-32.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-32.png new file mode 100644 index 0000000..46ee1ae Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-32.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-33.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-33.png new file mode 100644 index 0000000..529ba81 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-33.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-34.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-34.png new file mode 100644 index 0000000..8e07c47 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-34.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-35.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-35.png new file mode 100644 index 0000000..7c4fe2c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-35.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-36.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-36.png new file mode 100644 index 0000000..400ac70 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-36.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-37.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-37.png new file mode 100644 index 0000000..4db16c9 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-37.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-38.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-38.png new file mode 100644 index 0000000..a5e5eed Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-38.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-39.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-39.png new file mode 100644 index 0000000..4db16c9 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-39.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-4.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-4.png new file mode 100644 index 0000000..bd14265 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-4.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-40.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-40.png new file mode 100644 index 0000000..d68f5d5 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-40.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-41.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-41.png new file mode 100644 index 0000000..6edacb6 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-41.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-42.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-42.png new file mode 100644 index 0000000..0ca5185 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-42.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-5.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-5.png new file mode 100644 index 0000000..6fb4bcb Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-5.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-6.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-6.png new file mode 100644 index 0000000..a537153 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-6.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-7.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-7.png new file mode 100644 index 0000000..6fb4bcb Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-7.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-8.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-8.png new file mode 100644 index 0000000..0180698 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-8.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-9.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-9.png new file mode 100644 index 0000000..472893a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation-9.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation.gif b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation.gif new file mode 100644 index 0000000..3b1f8f7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Dijkstra_Animation.gif differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Donald-Knuth.jpg b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Donald-Knuth.jpg new file mode 100644 index 0000000..4958252 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/Donald-Knuth.jpg differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/ICS_LOGO_left.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/ICS_LOGO_left.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(a).PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(a).PNG new file mode 100644 index 0000000..e50a809 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(a).PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(b).PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(b).PNG new file mode 100644 index 0000000..3d73d93 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(b).PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(c).PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(c).PNG new file mode 100644 index 0000000..9387132 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY(c).PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY.PNG new file mode 100644 index 0000000..0124727 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/MAX-HEAPIFY.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-0.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-0.png new file mode 100644 index 0000000..05c6d0c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-0.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-1.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-1.png new file mode 100644 index 0000000..8e9d8e9 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-1.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-10.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-10.png new file mode 100644 index 0000000..56fd042 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-10.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-11.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-11.png new file mode 100644 index 0000000..e41d64b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-11.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-12.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-12.png new file mode 100644 index 0000000..da84cfc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-12.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-13.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-13.png new file mode 100644 index 0000000..f5da958 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-13.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-14.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-14.png new file mode 100644 index 0000000..f46ae8c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-14.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-15.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-15.png new file mode 100644 index 0000000..73d0784 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-15.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-16.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-16.png new file mode 100644 index 0000000..ae66917 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-16.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-17.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-17.png new file mode 100644 index 0000000..866035d Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-17.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-18.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-18.png new file mode 100644 index 0000000..09333c7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-18.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-19.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-19.png new file mode 100644 index 0000000..7bc5f46 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-19.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-2.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-2.png new file mode 100644 index 0000000..c78b24d Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-2.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-20.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-20.png new file mode 100644 index 0000000..5275cc6 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-20.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-21.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-21.png new file mode 100644 index 0000000..210309c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-21.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-22.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-22.png new file mode 100644 index 0000000..1f3252f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-22.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-23.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-23.png new file mode 100644 index 0000000..a0ca0fc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-23.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-24.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-24.png new file mode 100644 index 0000000..94e255c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-24.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-25.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-25.png new file mode 100644 index 0000000..b8d80cc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-25.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-26.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-26.png new file mode 100644 index 0000000..b930213 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-26.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-27.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-27.png new file mode 100644 index 0000000..19e16bb Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-27.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-28.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-28.png new file mode 100644 index 0000000..7b0faf9 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-28.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-29.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-29.png new file mode 100644 index 0000000..045e191 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-29.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-3.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-3.png new file mode 100644 index 0000000..768ccee Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-3.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-30.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-30.png new file mode 100644 index 0000000..071bd3e Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-30.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-31.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-31.png new file mode 100644 index 0000000..6ad2b2b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-31.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-32.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-32.png new file mode 100644 index 0000000..39240fc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-32.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-33.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-33.png new file mode 100644 index 0000000..9761933 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-33.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-34.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-34.png new file mode 100644 index 0000000..4815cbe Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-34.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-35.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-35.png new file mode 100644 index 0000000..45c4344 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-35.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-36.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-36.png new file mode 100644 index 0000000..c2089db Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-36.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-37.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-37.png new file mode 100644 index 0000000..856d317 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-37.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-38.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-38.png new file mode 100644 index 0000000..0d80548 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-38.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-39.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-39.png new file mode 100644 index 0000000..f9d1580 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-39.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-4.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-4.png new file mode 100644 index 0000000..23cf5bc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-4.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-40.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-40.png new file mode 100644 index 0000000..76ff049 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-40.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-41.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-41.png new file mode 100644 index 0000000..88d79fc Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-41.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-42.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-42.png new file mode 100644 index 0000000..beb1e3c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-42.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-43.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-43.png new file mode 100644 index 0000000..5c3d76b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-43.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-44.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-44.png new file mode 100644 index 0000000..b786a2a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-44.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-45.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-45.png new file mode 100644 index 0000000..3ca741f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-45.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-46.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-46.png new file mode 100644 index 0000000..c15ce8a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-46.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-47.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-47.png new file mode 100644 index 0000000..71e8750 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-47.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-48.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-48.png new file mode 100644 index 0000000..bba145c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-48.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-49.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-49.png new file mode 100644 index 0000000..a8a7ee2 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-49.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-5.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-5.png new file mode 100644 index 0000000..26d60e5 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-5.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-50.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-50.png new file mode 100644 index 0000000..16c8a90 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-50.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-51.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-51.png new file mode 100644 index 0000000..6aa563b Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-51.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-52.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-52.png new file mode 100644 index 0000000..579d5db Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-52.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-53.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-53.png new file mode 100644 index 0000000..feefcda Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-53.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-54.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-54.png new file mode 100644 index 0000000..68688fb Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-54.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-55.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-55.png new file mode 100644 index 0000000..f50d6e7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-55.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-56.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-56.png new file mode 100644 index 0000000..61903f7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-56.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-57.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-57.png new file mode 100644 index 0000000..c95fc91 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-57.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-6.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-6.png new file mode 100644 index 0000000..15e41a7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-6.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-7.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-7.png new file mode 100644 index 0000000..53300bb Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-7.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-8.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-8.png new file mode 100644 index 0000000..57530c5 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-8.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-9.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-9.png new file mode 100644 index 0000000..19452bd Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo-9.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo.gif b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo.gif new file mode 100644 index 0000000..c0c20be Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/PrimAlgDemo.gif differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/TAOCP_V3.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/TAOCP_V3.png new file mode 100644 index 0000000..08879d6 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/TAOCP_V3.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/dijkstra.jpg b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/dijkstra.jpg new file mode 100644 index 0000000..8ed81e3 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/dijkstra.jpg differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array.PNG new file mode 100644 index 0000000..1e4db8a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array_parent_procedure.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array_parent_procedure.PNG new file mode 100644 index 0000000..e88b32f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_array_parent_procedure.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_tree.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_tree.PNG new file mode 100644 index 0000000..6bc6e89 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heap_tree.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_example.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_example.PNG new file mode 100644 index 0000000..b85a02c Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_example.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_procedure.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_procedure.PNG new file mode 100644 index 0000000..e95dd23 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/heapsort_procedure.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/insert_example.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/insert_example.PNG new file mode 100644 index 0000000..fba9cc1 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/insert_example.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/operations_on_heap.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/operations_on_heap.PNG new file mode 100644 index 0000000..822c73f Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/operations_on_heap.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-EXTRACT-MAX.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-EXTRACT-MAX.PNG new file mode 100644 index 0000000..0db266a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-EXTRACT-MAX.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-INCREASE-KEY.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-INCREASE-KEY.PNG new file mode 100644 index 0000000..327bf51 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_HEAP-INCREASE-KEY.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_MAX-HEAP-INSERT.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_MAX-HEAP-INSERT.PNG new file mode 100644 index 0000000..38b7649 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_MAX-HEAP-INSERT.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_heap_maximum.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_heap_maximum.PNG new file mode 100644 index 0000000..6d7fbf3 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/pq_heap_maximum.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-pattern.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-pattern.png new file mode 100644 index 0000000..99abcd5 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-pattern.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-separate.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-separate.png new file mode 100644 index 0000000..b2d1821 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority-queue-separate.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority_queue_operations.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority_queue_operations.PNG new file mode 100644 index 0000000..cf122c7 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/priority_queue_operations.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/proof_correctness_build_max_heap.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/proof_correctness_build_max_heap.PNG new file mode 100644 index 0000000..474b34a Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/proof_correctness_build_max_heap.PNG differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/real_heap.png b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/real_heap.png new file mode 100644 index 0000000..b78eab8 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/real_heap.png differ diff --git a/2019/2019-2/2019-2-11-Heap&HeapSort/figs/tightbound_build_max_heap.PNG b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/tightbound_build_max_heap.PNG new file mode 100644 index 0000000..5e31228 Binary files /dev/null and b/2019/2019-2/2019-2-11-Heap&HeapSort/figs/tightbound_build_max_heap.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.pdf b/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.pdf new file mode 100644 index 0000000..88cf469 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.pdf differ diff --git a/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.tex b/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.tex new file mode 100644 index 0000000..db69aa1 --- /dev/null +++ b/2019/2019-2/2019-2-12_Hashing/2019-2-12_Hashing.tex @@ -0,0 +1,944 @@ +\documentclass[UTF8,11pt]{beamer} + +\input{../../../mj_preamble_lecturenote} +\mode +\begin{document} + \author{MA Jun} + \title{Problem Solving} + \subtitle{2-12 Hashing} + \logo{\includegraphics[width=0.05\textwidth]{../figs/ICS_LOGO_left.png}} + \institute{Institute of Computer Software} + %\date{March 31, 2020} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} +\begin{frame}[plain] + \maketitle +\end{frame} +\begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-2}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[hideallsubsections] +\end{frame} +\AtBeginSection[]{ + \begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-1}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[currentsection,hideallsubsections] + \end{frame} +} + +\begin{frame} +\frametitle{Applications of Hashing} +There are many applications of hashing \blue{(not limited to hash table)}, including modern day cryptography hash functions. Some of these applications are listed below: +\begin{itemize} + \item Message Digest + \item Password Verification + \item Data Structures (Programming Languages) + \item Compiler Operation + \item Rabin-Karp Algorithm + \item Linking File Name and Path Together +\end{itemize} +{\tiny + \href{https://www.geeksforgeeks.org/applications-of-hashing/}{https://www.geeksforgeeks.org/applications-of-hashing/} +} +\end{frame} + +\section{Hash-table: Basic Idea} + + +\begin{frame} +\begin{block}{} + \begin{center} + Many applications require a \textbf{\red{Dynamic Set}} that supports only the \textbf{\blue{dictionary}} operations \teal{\textproc{Insert}}, \teal{\textproc{Search}}, and \teal{\textproc{Delete}}. + \end{center} +\end{block} +\pause +\begin{block}{} + \begin{center} + Searching for an element in a hash table can take as long as searching for an element in a linked list— \teal{$\Theta(n)$} time in the \blue{worst case}. + \end{center} +\end{block} +\pause +\begin{block}{} + \begin{center} + Under reasonable assumptions, the \blue{average time} to search for an element in a hash table is \teal{$\Theta(1)$}. + \end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{Hashing: the idea} +\begin{center} + \question{}{ When should we use hash table? + + What situations is the hash table suitable for?} + + \begin{tikzpicture} + \pause + \node (b) at (4,0){\includegraphics[width=4cm]{figs/cloud.png}}; + \node at(4,-0.5) [color=blue]{Key Space}; + + \pause + \fill[ball color=red!60] (3,0.5) circle (0.1)node(x)[above,right]{$x$}; + \node at (4,2) [fill= yellow,text width=4cm]{\footnotesize{Very \red{large}, but only a \red{small part} is used in an application at a certain time.}}; + + + \pause + \foreach \y in{2,1.5,-1.5,-2}: + \draw (-4,\y-0.25) rectangle (-3,\y+0.25); + \draw (-4,-0.25) rectangle node(k){ } (-3,0.25); + \draw (-4,0.25) rectangle node{$\cdots$} (-3,1.25); + \draw (-4,-0.25) rectangle node{$\cdots$} (-3,-1.25); + \node at(-5,2){$E\left[0\right]$}; + \node at(-5,1.5){$E\left[1\right]$}; + \node at(-5,-2){$E\left[m-1\right]$}; + \node at (-4,3) [fill= yellow]{\footnotesize{Feasible size}}; + + \pause + \node (a)[color=black, draw,rectangle,fill=gray] at(-0.5,0) {Hash Function} ; + + \draw [dashed,color=red,thick,->](x)--(a); + \draw [dashed,color=red,thick,->](a)--(k); + \node at(-5,0){$E\left[{\color{red}k}\right]$}; + + \pause + \node at (-0.5,1.5) [fill= yellow,text width=4cm]{\footnotesize{ + \begin{itemize} + \item Index distribution + \item Collision handling + \end{itemize} + } + }; + \end{tikzpicture} +\end{center} +\end{frame} + + +\begin{frame} +\frametitle{Hashing: the idea} +\begin{center} + \question{}{ What is a Collision? When does it take place?} + + \pause + \begin{tikzpicture} + \filldraw [fill=gray](-2,-1) rectangle (1,1); + \node (a)[color=black] at(-0.5,0) {Hash Function} ; + + \node (b) at (4,0){\includegraphics[width=4cm]{figs/cloud.png}}; + \node at(4,-0.5) [color=blue]{Key Space}; + + + + + \foreach \y in{2,1.5,-1.5,-2}: + \draw (-4,\y-0.25) rectangle (-3,\y+0.25); + \draw (-4,-0.25) rectangle node(k){ } (-3,0.25); + \draw (-4,0.25) rectangle node{$\cdots$} (-3,1.25); + \draw (-4,-0.25) rectangle node{$\cdots$} (-3,-1.25); + \node at(-5,2){$E\left[0\right]$}; + \node at(-5,1.5){$E\left[1\right]$}; + \node at(-5,-2){$E\left[m-1\right]$}; + + \pause + \fill[ball color=red!60] (3,0.5) circle (0.1)node(x)[above,right]{$x$}; + \fill[ball color=red!60] (2.5,-0.2) circle (0.1)node(y)[above,right]{$y$}; + + \pause + \node at(-5,0){$E\left[{\color{red}k}\right]$}; + \draw [dashed,color=red,thick,->](x)--(k); + \draw [dashed,color=red,thick,->](y)--(k); + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Collision} +\begin{center} + \question{}{Given $n$ keys and $m$ slots, what is the expected number of keys hashed into the same slot? } + \begin{tikzpicture} + \filldraw [fill=gray](-2,-1) rectangle (1,1); + \node (a)[color=black] at(-0.5,0) {Hash Function} ; + + \node (b) at (4,0){\includegraphics[width=4cm]{figs/cloud.png}}; + \node at(4,-0.5) [color=blue]{Key Space}; + + + \fill[ball color=red!60] (3,0.5) circle (0.1)node(x)[above,right]{$x$}; + \fill[ball color=red!60] (2.5,-0.2) circle (0.1)node(y)[above,right]{$y$}; + + \foreach \y in{2,1.5,-1.5,-2}: + \draw (-4,\y-0.25) rectangle (-3,\y+0.25); + \draw (-4,-0.25) rectangle node(k){ } (-3,0.25); + \draw (-4,0.25) rectangle node{$\cdots$} (-3,1.25); + \draw (-4,-0.25) rectangle node{$\cdots$} (-3,-1.25); + \node at(-5,2){$E\left[0\right]$}; + \node at(-5,1.5){$E\left[1\right]$}; + \node at(-5,-2){$E\left[m-1\right]$}; + \node at(-5,0){$E\left[{\color{red}k}\right]$}; + \draw [dashed,color=red,thick,->](x)--(k); + \draw [dashed,color=red,thick,->](y)--(k); + \pause + \node at(0,-2) {\textbf{\color{red}It depends ...}}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Model \& Assumption} +\begin{block}{Model} + \begin{itemize} + \item Inserting {\color{blue}$n$} keys: sequence of {\color{blue}$n$} s independent trails. + \item Each insertion corresponds to a value from $\{0,1,\cdots,m-1\}$. + \end{itemize} +\end{block} + +\pause +\begin{block}{Assumption} + \begin{itemize} + \item For each insertion, the result is {\color{red}Uniformly Distributed}, i.e. each value from $\{0,1,\cdots,m-1\}$ is \red{equally} picked. + \end{itemize} +\end{block} + +\pause +\shadowbox{\parbox{\textwidth}{In hashing {\color{blue}$n$} items into a hash table of size {\color{blue}$m$}, the expected number of items that hash to any one location is {\color{blue}${\color{red}\alpha}=n/m$} ({\color{red}$\alpha$}: loading factor)}} +\end{frame} + +\begin{frame} +\frametitle{Empty location} +\begin{center} + \shadowbox{ + After inserting $n$ items into $m$ locations} +\end{center} + +\pause +\begin{block}{} + \question{}{ What is the probability of a given location is {\color{red}empty}?} + \pause + \begin{center} + \textbf{\color{red} $(1-\frac{1}{m})^n$} + \end{center} +\end{block} + +\pause +\begin{block}{} + \question{}{ What is the expected number of {\color{red}empty} locations?} + \begin{itemize} + \pause + \item $X_i=\left\lbrace \begin{array}{ll} + 1&, \text{location i is empty}\\ + 0&, \text{otherwise} + \end{array}\right. $ + \pause + \item $X=\sum\limits_{1\le i\le m}{X_i}$ + \pause + \item $E(X)=E(\sum\limits_{1\le i\le m}{X_i})=\sum\limits_{1\le i\le m}{E(X_i)}=\sum\limits_{1\le i\le m}{(1-1/m)^n}=m(1-1/m)^n$ + \end{itemize} +\end{block} +\end{frame} +\begin{frame} +\begin{center} + \shadowbox{ + After inserting $n$ items into a hashtable with $n$ locations} +\end{center} +\pause +\begin{block}{} + \question{}{ What is the expected number of items in a given location?} + \begin{center} + \begin{itemize} + \pause + \item $Y_i=\left\lbrace \begin{array}{ll} + 1&,\text{the }i\text{th item in the given location}\\ + 0&,\text{otherwise} + \end{array}\right. $ + \pause + \item $Y=\sum\limits_{1\le i\le n}{Y_i}$ + \pause + \item $E(Y)=E(\sum\limits_{1\le i\le n}{Y_i})=\sum\limits_{1\le i\le n}{E(Y_i)}=\sum\limits_{1\le i\le n}{1/n}={\color{red}1}$ + \end{itemize} + \end{center} +\end{block} + +\pause +\begin{block}{Expected number of empty locations: $n(1-1/n)^n=n/e \approx {\color{red}0.368n}$} +\end{block} + + +\begin{center} + \pause + \textbf{\LARGE{PARADOX?}} + + \pause + \fbox{\teal{collisions!}} +\end{center} +\end{frame} +\begin{frame}[t] +\frametitle{Expected number of collisions} +\begin{center} + \shadowbox{ + After inserting $n$ items into $m$ locations} + \begin{block}{} + \question{}{ What is the expected number of collisions?} + \pause + \[ + \begin{array}{ll} + E(\text{collisions})&=n-E(\text{occupied locations})\\\\ + \pause &=n-\left(m-E(\text{empty locations})\right)\\\\ + \pause &=n-\left(m-m\left(1-1/m\right)^n\right)\\\\ + &=n-m+m\left(1-1/m\right)^n + \end{array} + \] + \end{block} + \pause + \begin{block}{Example:} + When $n=100, m=100$, then $E(\text{collision})\approx37$ + \end{block} +\end{center} +\end{frame} + +\begin{frame}[t] +\begin{center} + \shadowbox{ + After inserting $n$ items into $m$ locations} +\begin{block}{} + \question{}{What is the expected number of items needed to fullfill all $m$ locations?} + \begin{columns} + \begin{column}{0.8\linewidth} + \begin{itemize} + \onslide<2->{\item $X_i$: the number of items to be added to increase the number of occupied locations from $i-1$ to $i$.} + \onslide<3->{\item Given $i-1$ occupied locations, \onslide<5->{the success probability for each trial is $(m-i+1)/m$}} + \onslide<6->{\item Thus, $E(X_i)=m/(m-i+1)$} + + \onslide<7->{ + \[ + \begin{array}{ll} + E(X) + &=\sum\limits_{i=1}^{m}{E(X_i)}=\sum\limits_{i=1}^{m}{m/(m-i+1)}\\\vspace{0.2cm} + &=m\sum\limits_{i=1}^{m}{1/(m-i+1)}\\\vspace{0.2cm} + &=m\sum\limits_{j=1}^{m}{1/j}={\color{red}\Theta(m\lg{m})} + \end{array} + \]} + \end{itemize} + \end{column} + \begin{column}{0.2\linewidth} + \begin{center} + \begin{tikzpicture}[scale=0.5] + + + \onslide<3->{ + \foreach \y in {-4,-3,...,4}{ + \draw (-0.75,\y-0.5) rectangle (0.75,\y+0.5); + } + \node at (0,-1) {$\cdots$}; + \foreach \y in {-4,-3,2}{ + \draw [color=red](-0.75,\y-0.5) rectangle (0.75,\y+0.5); + \filldraw [fill=red](0,\y) circle (0.2cm); + } + \foreach \y in {1,4}{ + \draw [color=red](-0.75,\y-0.5) rectangle (0.75,\y+0.5); + \foreach \x in{-0.3,0.3}{ + \filldraw [fill=red](\x,\y) circle (0.2cm); + } + } + \node at(-1.2,-5) {\footnotesize{$\#$}}; + \draw [color=red](-0.9,-5.3) rectangle (0.2,-4.7); + + \node [xshift=0.6cm]at(0,-5) {\footnotesize{$=i-1$}}; + } + \onslide<4->{ + \filldraw [fill=red](1.5,5) circle (0.2cm)node(n1){}; + + \foreach \y in {3,0,-1,-2}{ + \draw [color=blue,->,>=triangle 45] (n1)..controls (1.5,\y)..(0.75,\y); + } + } + \end{tikzpicture} + \end{center} + \end{column} + \end{columns} + +\end{block} +\end{center} +\end{frame} + +\section{Hash Functions} +\begin{frame} +\frametitle{Hashing: the idea} +\begin{center} + \begin{tikzpicture} + \node (a)[color=black, draw,rectangle,fill=gray] at(-0.5,0) {Hash Function} ; + \node at (-0.5,1.5) [fill= yellow,text width=4cm]{\footnotesize{ + \begin{itemize} + \item Index distribution + \item Collision handling + \end{itemize} + } + }; + \node (b) at (4,0){\includegraphics[width=4cm]{figs/cloud.png}}; + \node at(4,-0.5) [color=blue]{Key Space}; + \node at (4,2) [fill= yellow,text width=4cm]{\footnotesize{Very large, but only a small part is used in an application at a certain time.}}; + + \fill[ball color=red!60] (3,0.5) circle (0.1)node(x)[above,right]{$x$}; + \foreach \y in{2,1.5,-1.5,-2}: + \draw (-4,\y-0.25) rectangle (-3,\y+0.25); + \draw (-4,-0.25) rectangle node(k){ } (-3,0.25); + \draw (-4,0.25) rectangle node{$\cdots$} (-3,1.25); + \draw (-4,-0.25) rectangle node{$\cdots$} (-3,-1.25); + \node at(-5,2){$E\left[0\right]$}; + \node at(-5,1.5){$E\left[1\right]$}; + \node at(-5,-2){$E\left[m-1\right]$}; + \node at(-5,0){$E\left[{\color{red}k}\right]$}; + \node at (-4,3) [fill= yellow]{\footnotesize{In feasible size}}; + \draw [dashed,color=red,thick,->](x)--(a); + \draw [dashed,color=red,thick,->](a)--(k); + + \pause + \node at(0,-2) {{\color{red} Hash Function} is IMPORTANT!}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Two typical hash functions} + \begin{block}{\textbf{\color{red} Division Method}: map a key $k$ into one of $m$ slots by taking the remainder of $k$ divided by $m$.} + \[ + h(k)=k\mod m + \] + \end{block} + + \begin{block}{\textbf{\color{red} Multiplication Method}:} + \begin{itemize} + \item \textbf{\color{blue}Step-1}: multiply the $k$ by a constant $A$ in the range $0](x)--(k); + \draw [dashed,color=red,thick,->](y)--(k); + + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Collision Resolution} +\begin{columns} + \begin{column}{0.6\textwidth} + \begin{center} + \begin{block}{\textbf{Chaining (Closed Addressing)}} + \includegraphics[width=\textwidth]{figs/cr_chaining.png} + \end{block} + \end{center} + \end{column} + \begin{column}{0.35\textwidth} + + \begin{block}{\textbf{Open Addressing}} + \begin{center} + \includegraphics[width=0.25\textwidth]{figs/cr_open_addressing.png} + + \end{center} + \end{block} + \end{column} +\end{columns} +\end{frame} +\subsection{Chaining} +\begin{frame} +\frametitle{Collision Resolution by Chaining} +\begin{center} +\begin{tikzpicture} +\node at (0,0) {\includegraphics[width=0.7\textwidth]{figs/cr_chaining.png}}; +\node at (0,-3.6) {\fbox{\includegraphics[width=0.6\textwidth]{figs/cr_chaining_procedure.png}}}; +\pause +\draw [color=red,thick](-1,-2.8) rectangle +(0.7,0.4); +\end{tikzpicture} + + + +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Collision Resolution by Chaining: Unsuccessful Search} + +\question{}{What is the average cost of an \textbf{unsuccessful} search?} +\begin{block}{} + \begin{center} + \pause + \shadowbox{ + \begin{tikzpicture} + \node at (0,0) {\includegraphics[width=.9\textwidth]{figs/theorem-11-1.png}}; + \draw [color=red,thick](0.4,-0.5) rectangle +(5,0.3); + \end{tikzpicture} + } + + + \pause + + \shadowbox{ \parbox{0.7\textwidth}{ + For $j=0,1,2,...,m-1$, the average length of the list at $E[j]$ is $n/m=\alpha$. + }} + \begin{itemize} + \pause + \item Any key that is not in the table is \textbf{\blue{equally}} likely to hash to any of the $m$ addresses. + \pause + \item The \textbf{\blue{average cost}} to determine that the key is not in the list $E[h(k)]$ is the cost to search to the end of the list, which is $\alpha$. + \pause + \item Total cost is {$\Theta(\textcolor{red}{1}+{\color{blue}\alpha})$} + \end{itemize} + \end{center} +\end{block} +\begin{center} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Collision Resolution by Chaining: Successful Search} +\question{}{ What is the average cost of an \textbf{successful} search?} +\begin{block}{} + \begin{center} + \pause + \shadowbox{\includegraphics[width=.9\textwidth]{figs/theorem-11-2.png}} + \begin{itemize} + \pause\item \teal{$x_i$}: the $i$th element inserted into the table. + \pause\item The probability of that \teal{$x_i$} is searched is $1/n$. + \pause\item For a specific \teal{$x_i$}, the number of elements examined in a successful search is $\textcolor{red}{t}+1$ + \begin{itemize} + \pause\item $\textcolor{red}{t}$: the number of elements inserted into the same list as \teal{$x_i$}, \textbf{after} \teal{$x_i$} has been inserted. + \pause\item The probability of that $x_j$ is inserted into the \textbf{same} list of \teal{$x_i$} is $1/m$. + \pause\item The \textbf{\color{blue}expected number of elements examined} for a successful search of \teal{$x_i$} is {$(\textcolor{blue}{1}+\textcolor{red}{\sum\limits_{j=i+1}^{n}{\frac{1}{m}}})$} + \end{itemize} + \end{itemize} + \end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{Collision Resolution by Chaining: Successful Search} +\question{}{What is the average cost of a \textbf{successful} search?} +\begin{block}{} + \begin{center} + \begin{itemize} + \item Average \textbf{\color{blue}number of elements examined} for an successful search is \[ + \begin{array}{ll} + \frac{1}{n}\sum\limits_{i=1}^{n}{(\textcolor{blue}{1}+\textcolor{red}{\sum\limits_{j=i+1}^{n}{\frac{1}{m}}})} + \pause&=1+\frac{1}{n\textcolor{red}{m}}{(\textcolor{red}{\sum\limits_{j=i+1}^{n}{1}})}\\\vspace{0.2cm} + \pause&={1}+\frac{1}{nm}{({\sum\limits_{i=1}^{n}{n-i}})}\\\vspace{0.2cm} + \pause&={1}+\frac{1}{nm}{(n^2-{\sum\limits_{i=1}^{n}{i}})}\\\vspace{0.2cm} + \pause&={1}+\frac{1}{nm}{(n^2-\frac{n(n+1)}{2})}\\\vspace{0.2cm} + &={1}+\frac{n}{2m}-\frac{n}{2nm}\\\vspace{0.2cm} + &={1}+\alpha-\frac{\alpha}{2n} + \end{array}\] + \end{itemize} + \pause + \item Average \textbf{\color{blue}cost} for a successful search is ${\blue{\textbf{2}}}+\alpha-\frac{\alpha}{2n}=\Theta(1+\alpha)$ + \end{center} +\end{block} +\end{frame} + + +\begin{frame}[fragile] +\frametitle{Collision Resolution by Chaining: Example} +\begin{block}{JAVA 7 HashMap} + + \begin{columns} + \begin{column}{0.7\textwidth} +\begin{lstlisting}[style=styleJ] +static int hash(int h) { + h^= (h>>>20)^(h>>>12); + return h^(h>>>7)^(h>>>4); +} +\end{lstlisting} + \begin{itemize} + \item In \red{Java 7}, after calculating hash from hash function, if more then one element has same hash than they are searched by linear search, so it's complexity is $O(n)$. + + \item In \red{Java 8}, that search is performed by \textbf{\teal{binary search}} so the complexity will become $\log{n}$. + \end{itemize} + \end{column} + \begin{column}{0.25\textwidth} + \includegraphics[width=\linewidth]{figs/java7.png} + \end{column} + \end{columns} +\end{block} +\end{frame} + +\subsection{Open Addressing} +\begin{frame} +\frametitle{Open Addressing} +\begin{columns} + \begin{column}{0.2\linewidth} + \includegraphics[width=\linewidth]{figs/cr_open_addressing.png} + \end{column} + \begin{column}{0.85\linewidth} + \begin{itemize} + \item All elements are stored in the hash table, \textbf{no linked list is used}. So, $\alpha\le 1$. + + \pause + \item Collision is settled by ``\textbf{\color{red}rehashing}'': + \begin{itemize} + \pause\item A function used to get \textbf{a new hashing address for each collided address} + \pause\item The hash table slots are probed successively, until a valid location is found. + \end{itemize} + + \pause + \item The \textbf{\teal{probing sequence}} can be seen as a \textbf{\teal{permutation}} of $(0,1,2,\cdots, m-1)$$\rightarrow$$\left\langle h(k,0), h(k,1),\cdots, h(k,m-1)\right\rangle $ + + \end{itemize} + \end{column} +\end{columns} +\end{frame} + + +\begin{frame} +\frametitle{Open Addressing: Commonly Used Probings} + +\begin{block}{\textbf{\color{red}Linear Probing}: (\textbf{\color{blue}primary clustering} may occur)} +Given an auxiliary hash function $h'$, the hash function is: + \[h(k,i) = (h'(k)+i)\mod {m}, (i=0,1,...,m-1)\] +\end{block} +\pause +\begin{block}{\textbf{\color{red}Quadratic Probing}: (\textbf{\color{blue}secondary clustering} may occur)} +Given auxiliary function $h'$ and nonzero auxiliary constant $c_1$ and $c_2$, the hash function is: + \[h(k,i) = (h'(k)+c_1i+ c_2i^2) \mod m, (i=0,1,...,m-1)\] +\end{block} +\pause +\begin{block}{\textbf{\color{red}Double Hashing}:} +Given auxiliary functions $h_1$ and $h_2$, the hash function is: +\[h(k,i) = (h_1(k)+ ih_2(k)) \mod m, (i=0,1,...,m-1)\] +\end{block} +\end{frame} + + + +\begin{frame} +\frametitle{Linear Probing: an Example} +\begin{center} + \begin{tikzpicture} + \node (b) at (4,2){\includegraphics[width=4cm]{figs/cloud.png}}; + + + \foreach \y in{0,1,...,7}:{ + \draw (-4.5,\y*0.5-0.25) rectangle (-3,\y*0.5+0.25); + \node at(-5,3.5-\y*0.5){\y}; + } + \node at(-3.75,3.5)[color=blue]{1776}; + \node at(-3.75,2)[color=blue]{1055}; + \node (l4) at(-3.75,1.5)[color=blue]{1492}; + \node (l6)at(-3.75,0.5)[color=blue]{1918}; + \node at(2,4) {\shadowbox{Hasing function: $h(x)=5x\mod 8$}}; + \node at(2,0) {\shadowbox{Rehasing function: $rh(j)=(j+1)\mod 8$}}; + + %1812 + \pause + \fill[ball color=red!60] (3,2.5) circle (0.1)node(n1812)[above,right,color=red!80!black!80!]{$1812$}; + \pause + \draw [->,dashed,color=red,thick](n1812)--node[above]{hashing}(l4)[right=1cm]; + + + \pause + \node (l5)at(-3.75,1)[color=white]{\textbf{1812}}; + \draw [->,dashed,color=red,thick](l4)[left]..controls (-5,1.5) and (-5,1.0)..(l5)[left]; + \node at(-5.5,1.25)[color=red]{rehashing}; + \pause + \node at(-3.75,1)[color=red!80!black!80!]{\textbf{1812}}; + + %1945 + \pause + \fill[ball color=red!60] (2.5,1.8) circle (0.1)node(n1945)[above,right,color=green!80!black!80!]{$1945$}; + + \pause + \draw [->,dashed,color=green,thick](n1945)--node[below]{hashing}(l5)[right=1cm]; + \pause + \draw [->,dashed,color=green,thick](l5)[right]..controls (-2.25,1) and (-2.25,0.5)..(l6)[right]; + \node (l7) at(-3.75,0)[color=white]{\textbf{1945}}; + \pause + \draw [->,dashed,color=green,thick](l6)[right]..controls (-2.25,0.5)and(-2.25,0)..(l7)[right]; + \node at(-2,0.5)[color=green]{rehashing}; + \pause + \node at(-3.75,0)[color=green!80!black!80!]{\textbf{1945}}; + + + + + + + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Commonly Used Probings} +\question{}{How to evaluate the \textbf{goodness} of a probing?} +\begin{block}{} +\begin{center} + +\pause +\textbf{\color{red}Assumption} + +\shadowbox{\parbox{0.8\linewidth}{Each key is \textbf{equally} likely to have any of the $m!$ permutations of $(1,2,\cdots,m-1)$ as its probe sequence. +}} + +\begin{itemize} + \pause\item Both linear and quadratic probing have only {\color{blue}$m$ distinct probe sequences}, as determined by the first probe. + \begin{center} + $h(k,i) = (h'(k)+i)\mod {m}, (i=0,1,...,m-1)$ + + $h(k,i) = (h'(k)+c_1i+ c_2i^2) \mod m, (i=0,1,...,m-1)$ + \end{center} + \pause\item Double hashing improves over linear or quadratic probing in that {\color{blue}$\Theta(m^2)$ probe sequences} are used. + \[h(k,i) = (h_1(k)+ ih_2(k)) \mod m, (i=0,1,...,m-1)\] +\end{itemize} +\end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Deleting Element} +\question{}{Why Open Addressing is not suitable for situations where items might be deleted?} + \begin{center} + + \begin{itemize} + \pause\item The probing chain might be broken if an item is deleted. + \pause \item How to deal with it? + \end{itemize} + \end{center} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Unsuccessful Search} +\question{}{Assuming uniform hashing, what is the average number of probes in an \textbf{unsuccessful} search?} +\begin{center} + \pause + \shadowbox{\includegraphics[width=0.9\linewidth]{figs/theorem-11-6.png}} +\end{center} +\begin{itemize} + \pause + \item {\color{blue}$X$}: the number of probes made in an \textbf{unsuccessful} search + \pause + \[ + \begin{array}{ll} + E(X)&=\sum\limits_{i=0}^{\infty}{i\cdot Pr(X=i)}\\\vspace{0.2cm} + &=\sum\limits_{i=0}^{\infty}{i\cdot( Pr(X\ge i)-Pr(X\ge i+1))}\\\vspace{0.2cm} + &={\color{blue}\sum\limits_{i=1}^{\infty}{Pr(X\ge i)}} + \end{array} + \] +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Unsuccessful Search} +\question{}{How to compute $Pr(X\ge i)$?} +\begin{itemize} + \pause\item $A_i$: the $i$th probe occurs at an \teal{occupied} slot + \pause\item $X\ge i=A_1\cap A_2\cap\cdots\cap A_{i-1}$ + +\end{itemize} +\begin{proof}[] + \pause + {\footnotesize\[ + \begin{array}{ll} + Pr(X\ge i)&=Pr(A_1\cap A_2\cap\cdots\cap A_{i-1})\\\vspace{0.2cm} + &=Pr(A_1)\cdot Pr(A_2|A_1)\cdot Pr(A_3|A_1\cap A_2)\cdots Pr(A_{i-1}|A_1\cap A_2\cap\cdots\cap A_{i-2})\\\vspace{0.2cm} + &=\frac{n}{m}\cdot\frac{n-1}{m-1}\cdots\frac{n-i+2}{m-i+2}\\\vspace{0.2cm} + &\le (\frac{n}{m})^{i-1}\\\vspace{0.2cm} + &=\alpha^{i-1} + \end{array} + \] + } + \pause + Then, + $\begin{array}{ll} + E(x)={\color{blue}\sum\limits_{i=1}^{\infty}{Pr(X\ge i)}} + \le\sum\limits_{i=1}^{\infty}{\alpha^{i-1}} + =\le\sum\limits_{i=0}^{\infty}{\alpha^{i}}=\blue{\frac{1}{1-\alpha}} + \end{array}$ + +\end{proof} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Inserting an Element} +\question{}{What is the average cost for inserting an element into a table with load factor $\alpha$?} + +\begin{center} + \pause + \shadowbox{\includegraphics[width=0.9\linewidth]{figs/corollary-11-7.png}} + \begin{proof} + \begin{itemize} + \item An element is inserted only if there is room in the table, and thus $\alpha<1$. + \item Inserting a key requires an \teal{ unsuccessful} search followed by placing the key into the first empty slot found. + \item Thus, the expected number of \blue{probes} is at most $1/(1-\alpha)$ + \end{itemize} + + \end{proof} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Insertion/Unsuccessful Search} +\begin{center} + + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=0.5\linewidth]{figs/functiongraph1.png}}; + \filldraw [color=white](-3.6,-2.5)rectangle(-0.04,-2.2); + \node[fill=white] at(-2,1.5){\fbox{$\frac{1}{1-\alpha}$}}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Successful Search} +\question{}{What is the average number of probes in a \textbf{successful} search of an element in a table with load factor $\alpha$?} + +\begin{center} + \pause + \shadowbox{\includegraphics[width=0.9\linewidth]{figs/theorem-11-8.png}} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Open Addressing: Successful Search} +\question{}{what is the average number of probes in a successful search for an element in a table with load factor $\alpha$?} + +\begin{center} +\begin{proof} + \begin{itemize} + \pause\item A \textbf{\teal{search}} for a key $k$ reproduces the \textbf{same probe sequence} as when the element with key $k$ was \textbf{\teal{inserted}}. + \pause\item If $k$ is the (i+1)st key inserted into the table, the expected number of probes in a search for $k$ is at most $1/(1-\blue{i/m})=m/(m-i)$ + \pause\item The expected number of probes is: + \begin{tikzpicture} + \node at(0,0){ + $ + \begin{array}{ll} + \frac{1}{n}\sum\limits_{i=0}^{n-1}{\frac{m}{m-i}} + &=\frac{m}{n}\sum\limits_{i=0}^{n-1}{\frac{1}{m-i}} + =\frac{1}{\alpha}\sum\limits_{k=m-n+1}^{m}{\frac{1}{k}}\\\vspace{0.4cm} + &\le \frac{1}{\alpha}\int_{m-n}^{m}\frac{1}{x}dx=\frac{1}{\alpha}\ln{\frac{m}{m-n}}\\\vspace{0.3cm} + &=\frac{1}{\alpha}\ln{\frac{1}{1-\alpha}} + \end{array} + $ + }; + + \end{tikzpicture} + + \end{itemize} +\end{proof} +\end{center} +\end{frame} + + +\begin{frame} +\frametitle{Open Addressing: Successful Search} +\begin{center} + +\begin{tikzpicture} +\node at(0,0){\includegraphics[width=0.5\linewidth]{figs/functiongraph.png}}; +\filldraw [color=white](-3.6,-2)rectangle(-0.03,-1.8); +\filldraw [color=white](-4,1.8)rectangle(4,2.5); +\node[fill=white] at(-2,1.5){\fbox{$\frac{1}{\alpha}\ln{\frac{1}{1-\alpha}}$}}; +\node at(0,-3.3) {\fbox{\parbox{3.5cm}{\teal{For your reference}: + \begin{itemize} + \item $\alpha=0.5$: 1.387 + \item $\alpha=0.9$: 2.559 + \end{itemize} + +}}}; +\end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} + \begin{block}{ + \begin{center} + {\huge + Thank You! + + \vspace{0.3cm} + \textcolor[rgb]{1,0,0} {Questions?} + } + \end{center} + } + \end{block} + \begin{block}{} + \begin{center} + + Office 819 + + majun@nju.edu.cn + \end{center} + \end{block} + \end{frame} +\end{document} \ No newline at end of file diff --git a/2019/2019-2/2019-2-12_Hashing/figs/ICS_LOGO_left.png b/2019/2019-2/2019-2-12_Hashing/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/ICS_LOGO_left.png differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/cloud.png b/2019/2019-2/2019-2-12_Hashing/figs/cloud.png new file mode 100644 index 0000000..82116ca Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/cloud.png differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/corollary-11-7.PNG b/2019/2019-2/2019-2-12_Hashing/figs/corollary-11-7.PNG new file mode 100644 index 0000000..a66b326 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/corollary-11-7.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining.PNG b/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining.PNG new file mode 100644 index 0000000..7df6adc Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining_procedure.PNG b/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining_procedure.PNG new file mode 100644 index 0000000..7cebc80 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/cr_chaining_procedure.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/cr_open_addressing.PNG b/2019/2019-2/2019-2-12_Hashing/figs/cr_open_addressing.PNG new file mode 100644 index 0000000..8b4ea2b Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/cr_open_addressing.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/expected_probes_suc_search_open_addressing.PNG b/2019/2019-2/2019-2-12_Hashing/figs/expected_probes_suc_search_open_addressing.PNG new file mode 100644 index 0000000..e4af86b Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/expected_probes_suc_search_open_addressing.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/functiongraph.png b/2019/2019-2/2019-2-12_Hashing/figs/functiongraph.png new file mode 100644 index 0000000..7336949 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/functiongraph.png differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/functiongraph1.png b/2019/2019-2/2019-2-12_Hashing/figs/functiongraph1.png new file mode 100644 index 0000000..731c77d Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/functiongraph1.png differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/java7.png b/2019/2019-2/2019-2-12_Hashing/figs/java7.png new file mode 100644 index 0000000..a0d242a Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/java7.png differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/multiplication_hashing_function.PNG b/2019/2019-2/2019-2-12_Hashing/figs/multiplication_hashing_function.PNG new file mode 100644 index 0000000..053a306 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/multiplication_hashing_function.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-1.PNG b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-1.PNG new file mode 100644 index 0000000..32fee22 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-1.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-2.PNG b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-2.PNG new file mode 100644 index 0000000..8886345 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-2.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-6.PNG b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-6.PNG new file mode 100644 index 0000000..5465256 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-6.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-8.PNG b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-8.PNG new file mode 100644 index 0000000..acf945d Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/figs/theorem-11-8.PNG differ diff --git a/2019/2019-2/2019-2-12_Hashing/hashing_idea.PNG b/2019/2019-2/2019-2-12_Hashing/hashing_idea.PNG new file mode 100644 index 0000000..d40e277 Binary files /dev/null and b/2019/2019-2/2019-2-12_Hashing/hashing_idea.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/2-9-sorting_and_selection(handout).pdf b/2019/2019-2/2019-2-9-Sorting&Selection/2-9-sorting_and_selection(handout).pdf new file mode 100644 index 0000000..05c4c82 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/2-9-sorting_and_selection(handout).pdf differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.pdf b/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.pdf new file mode 100644 index 0000000..d5f8c24 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.pdf differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.tex b/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.tex new file mode 100644 index 0000000..1dfe087 --- /dev/null +++ b/2019/2019-2/2019-2-9-Sorting&Selection/2019-9-sorting_and_selection.tex @@ -0,0 +1,1026 @@ +\documentclass[UTF8,11pt,handout]{beamer} + +\input{../../../mj_preamble_lecturenote} +\mode +\begin{document} + \author{MA Jun} + \title{Problem Solving} + \subtitle{2-9 Sorting and Selection} + \logo{\includegraphics[width=0.05\textwidth]{figs/ICS_LOGO_left.png}} + \institute{Institute of Computer Software} + %\date{March 31, 2020} + %\subject{} + %\setbeamercovered{transparent} + %\setbeamertemplate{navigation symbols}{} +\begin{frame}[plain] + \maketitle +\end{frame} +\begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-2}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[hideallsubsections] +\end{frame} +\AtBeginSection[]{ + \begin{frame} %生成目录页,目录太长时加选项[shrink] + \addtocounter{framenumber}{-1}%---------位置放在beginframe之后,不然无效 + \frametitle{Contents} + \thispagestyle{empty} + \tableofcontents[currentsection] + \end{frame} +} +\section{Sorting} +\subsection{Quicksort} +\begin{frame}[t] + \frametitle{Quicksort} + \question{}{What is the \textcolor{red}{\textbf{KEY}} idea of Quicksort?} + \begin{center} + \begin{tikzpicture} + \pause{ + \filldraw [fill=green!30!black!30,draw=black,line width=0.5pt] (0,0) rectangle (3,0.7); + \filldraw [xshift=3.5cm,fill=blue!30!black!30,draw=black,line width=0.5pt] (0,0.35) circle (0.2cm); + \filldraw [xshift=4cm, fill=red!40!black!40,draw=black,line width=0.5pt] (0,0) rectangle (4.2,0.7); + \foreach \x in {1,2,...,5}{ + \filldraw [fill=white,draw=black,line width=0.5pt] (\x*0.6-0.3,0.35) circle (0.2cm); + } + \foreach \x in {1,2,...,7}{ + \filldraw [xshift=4cm,fill=white,draw=black,line width=0.5pt] (\x*0.6-0.3,0.35) circle (0.2cm); + } + \node at (4,1.2){\color{red!90!black!70!}pivot}; + \draw [line width=1pt,->,>= angle 60](4,1)--(3.5,0.55); + } + \pause{ + \node at (1.5,-1.5) {small}; + \draw [line width=1pt,->,>= angle 60](1.5,-1.3)--(1.5,-0.1); + \node at (-0.8,-1.2) [fill= yellow,text width=3cm]{for any element in this segment, the key is \emph{\color{red}not greater than pivot}.}; + } + \pause{ + \node at (6.1,-1.5) {large}; + \draw [line width=1pt,->,>= angle 60](6.1,-1.3)--(6.1,-0.1); + \node at (8.4,-1.2) [fill= yellow,text width=3cm]{for any element in this segment, the key is \emph{\color{red}greater than pivot}.}; + } + \pause{ + \node at (4,-2.5){\color{blue!90!black!90!}\textbf{To Be Sorted Recursively}}; + } + \end{tikzpicture} + \end{center} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort} + \question{}{What are the \textcolor{red}{\textbf{SIMILARITIES}} and \textcolor{red}{\textbf{DIFFERENCES}} between Quicksort and Mergesort?} + + \begin{center} + \begin{columns} + \column{0.45\textwidth} + \begin{center} + \includegraphics[width=0.9\textwidth]{figs/quicksort.png} + \end{center} + \column{0.1\textwidth} + \begin{center}\textbf{\color{red}VS} + \end{center} + \column{0.45\textwidth} + \begin{center} + \includegraphics[width=0.9\textwidth]{figs/mergesort.png} + \end{center} + \end{columns} + + \end{center} + \begin{block}{} + \begin{description} + \pause\item[Similarity:] both are {\color{red}\textbf{divide-and-conquer}} strategies. + \pause\item[Difference:] the process + \begin{center} + \begin{table}[] + \centering + \begin{tabular}{c|cc} + \textbf{} & \textbf{QuickSort} & \textbf{MergeSort} \\\hline + Partition & hard & {\color{blue}easy} \\ + Combination & {\color{blue}easy} & hard + \end{tabular} + \end{table} + \end{center} + \end{description} + \end{block} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: \textproc{Partition}} + \begin{columns} + + \column{0.5\textwidth} + \begin{block}{} + \begin{center} + \begin{tikzpicture}[scale=5/6] + \node at (0,0) {\includegraphics[width=0.9\textwidth]{figs/quicksort__partition_process.png}}; + \node (a) at(-3,0.6){ }; + \node (b) at(3.2,0.6){ }; + \node at(0.1,0.9)[color=orange]{$k$}; + \draw[decorate,decoration=brace,color=orange, line width=1pt] (a)--(b); + \node at (0,-3) {\includegraphics[width=.9\textwidth]{figs/quicksort_partition_procedure.png}}; + \onslide<2->\draw [color=red,thick](-2.5,-2.3) rectangle (-2.2,-1.8); + \onslide<3->\draw [color=red,thick](-1.8,-2.85) rectangle (-1.5,-2.35); + \onslide<4->\draw [color=gray,thick](-2.5,-2.35) rectangle (3.5,-4.4); + \end{tikzpicture} + \end{center} + \end{block} + + \column{0.5\textwidth} + \question{}{ How to prove the correctness of \textproc{Partition}?} + \begin{block}{} + \vspace{0.2cm} + \onslide<4->{ + At the beginning of each iteration of the loop of lines 3-6, for any array index $k$, we have: + + \vspace{0.2cm} + \fbox{ \includegraphics[width=.9\textwidth]{figs/correctness_quicksort_partition_procedure.png} + } + } + \end{block} + + \end{columns} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \question{}{What is the time complexity of \textproc{Quicksort}?} + \begin{center} + \includegraphics{figs/quicksort.png} + \end{center} + + \begin{center} + \pause \begin{block}{The recurrence: $T(n)=T(n_1)+T(n_2)+cn$} where: + \pause \[ + \begin{array}{ll} + n_1=q-1-p+1=q-p\\ + n_2=r-(q+1)+1=r-q\\ + n_1+n_2=r-p\\ + {\color{blue}initially}, p=1, r=n + \end{array} + \] + +\pause $n_1,n_2$ vary and depend on {\color{blue}$q=\textproc{Partition}(A,p,r)$} + \end{block} + \end{center} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \question{}{Which factor would affect the efficiency of \textproc{Quicksort}?} + \begin{center} + \begin{tikzpicture} + + \node at (0,0) { \includegraphics[height=0.7\textheight]{figs/recur_tree_quicksort.png}}; + \draw [color=red](-4.6,-0.2) rectangle (-3.6,0.2); + \draw [color=red](-4.0,0.8) rectangle (-3.1,1.2); + \node at(-2,3.5){\fbox{always produces a 9-to-1 split}}; + \pause\node at(-1,-2)[fill= yellow,text width=4.5cm] {the choice of {\color{blue}Pivot} would affect the tree height.}; + \end{tikzpicture} + + \end{center} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \question{}{Which factor would affect the efficiency of \textproc{Quicksort}?} + \begin{center} + \begin{tikzpicture} + \node at (0,0) { \includegraphics[height=0.7\textheight]{figs/recur_tree_quicksort.png}}; + \draw [color=red](-4.6,-0.2) rectangle (-3.6,0.2); + \draw [color=red](-4.0,0.8) rectangle (-3.1,1.2); + + \node at(-2,3.5){\fbox{always produces a 9-to-1 split}}; + \node at(-0.8,-1.8)[fill= green!30!black!30!,text width=5.8cm] {any split of \emph{\color{red}constant proportionality}\\ + \begin{itemize} + \item tree height: {\color{blue}$\Theta(\lg{n})$} + \item cost of each level: {\color{blue}$cn$} + \item total running time: {\color{blue}$O(n\lg{n})$} + \end{itemize}}; + \end{tikzpicture} + + \end{center} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \question{}{Which factor would affect the efficiency of \textproc{Quicksort}?} + \begin{center} + \begin{tikzpicture} + \node at (0,0) { \includegraphics[height=0.7\textheight]{figs/recur_tree_quicksort.png}}; + \draw [color=red](-4.6,-0.2) rectangle (-3.6,0.2); + \draw [color=red](-4.0,0.8) rectangle (-3.1,1.2); + \node at(-0.8,-1.4)[fill= green!30!black!30!,text width=5.8cm] {any split of {\color{red}\xout{\emph{constant proportionality}}}\\ + What is the {\color{red}WORST CASE}? + }; + \pause \node at(-1.6,-2.6)[fill= blue!30!black!30!] {\color{blue} + $T(n)=\max_{0\le q\le n-1}(T(q)+T(n-q-1))+\Theta(n)$}; + \end{tikzpicture} + \end{center} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \begin{block}{Worst Case: } + \begin{center} + $T(n)=\max_{0\le q\le n-1}(T(q)+T(n-q-1))+\Theta(n)$ + \end{center} + \end{block} + \question{}{When would the worst case happen?} + + \pause\begin{center} + The pivot is {\color{red}always} the \textcolor{blue}{greatest} or \textcolor{blue}{smallest} element for each recursion. + \end{center} + + \pause\begin{block}{\textbf{\color{red}Unlucky}: $T(n)=O(n^2)$ for the worst case!} + \end{block} + \pause\begin{block}{\textbf{\color{red}Lucky}: worst case seldom happens!} + \end{block} +\end{frame} + +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + + \onslide<1->\begin{block}{\textbf{\color{red}Impression \& Intuition}:\\ + } + \begin{center} + Quick sort performs quite well in practice.\\\vspace{0.3cm} + \pause We usually obtain an $O(n\lg{n})$ execution in most cases, rather than the worst case.\\\vspace{0.3cm} + \pause\textbf{\LARGE\color{red}WHY?}\\ + \pause {\color{blue}\textproc{Partition} produces a mix of ``good'' and ``bad'' splits.}\\ + + \includegraphics[height=.3\textheight]{figs/quicksort_binary_tree.png} + + \pause {\color{blue}$T(n)=O(n\lg{n})$} + \end{center} + \end{block} +\end{frame} +\begin{frame}[t] + \frametitle{Quicksort: Time Complexity} + \begin{block}{\textbf{\color{red}Critical operation?}} + \begin{itemize} + \item The key cost of Quicksort comes from {\color{blue}\textproc{Partition}} + \item The key cost of \textproc{Partition} comes from line {\color{blue}4}. + \end{itemize} + \end{block} + \begin{center} + \begin{columns} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{tikzpicture} + \node at(0,0) {\includegraphics[height=.25\textheight]{figs/quicksort.png}}; + + \draw [thick,color=blue] (-1.2,-0.2)--(2.2,-0.2); + \end{tikzpicture} + \end{column} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{tikzpicture} + \node at(0,0){\includegraphics[height=.4\textheight]{figs/quicksort_partition_procedure.png}}; + \draw [thick,color=blue] (-1.2,-0.2)--(0.2,-0.2); + + \end{tikzpicture} + + \end{column} + \end{columns} + + \end{center} +\end{frame} + +\begin{frame}[t] +\frametitle{Quicksort} +\begin{center} + \begin{lemma}[7.1] + Let {\color{blue}$X$} be the number of comparisons performed in line 4 of \textproc{Partition} over the entire execution of \textproc{Quicksort} on an $n$-element array. Then the running time of \textproc{Quicksort} is {\color{blue}$O(n+X)$}. + \end{lemma} + \begin{proof} + By the discussion above, the algorithm makes at most {\color{blue}$n$} calls to \textproc{Partition}, each of which does a constant amount of work and then executes the \textbf{\color{blue}for loop} some number of times. Each iteration of the \textbf{\color{blue}for loop} executes line $4$. + \end{proof} +\end{center} +\end{frame} + +\subsection{Randomized Quicksort} +\begin{frame}[t] + \frametitle{Randomized Quicksort} + \begin{columns} + + \begin{column}[T, onlytextwidth]{.5\textwidth} + \begin{block}{Randomized Quicksort} + \includegraphics[height=.23\textheight]{figs/randomized-quicksort.png} + \end{block} + \begin{block}{\textbf{\color{red}Goal:}} + To compute $X$, the \textbf{\color{blue}TOTAL} number of comparisons performed in \textbf{all} calls to \textproc{Partition}. + + We will \textbf{NOT} attempt to analyze how many comparisons are made in \textbf{\color{blue}EACH} call to \textproc{Partition}. + \end{block} + \end{column} + \begin{column}[T, onlytextwidth]{.4\textwidth} + \begin{block}{Randomized Partition} + + \begin{tikzpicture} + \node at(0,0) { \includegraphics[height=.2\textheight]{figs/randomized-partition-procedure.png}}; + + \draw [thick,color=blue] (-1.2,-0.7)--(2,-0.7); + \end{tikzpicture} + \begin{tikzpicture} + \node at(0,0){\includegraphics[height=.4\textheight]{figs/quicksort_partition_procedure.png}}; + \draw [thick,color=blue] (-1.2,-0.2)--(0.2,-0.2); + \end{tikzpicture} + \end{block} + \end{column} + + \end{columns} +\end{frame} + + + +\begin{frame}[t] +\frametitle{Randomized Quicksort: Expected Running Time} +\question{}{How to compute the expected value of X?} + \fbox{% + \parbox{\textwidth}{% + \begin{center} + $X$: the \textbf{\color{blue}TOTAL} number of comparisons performed in \textbf{all} calls to \textproc{Partition}. + \end{center} + }% + } + \begin{itemize} + \pause\item We must understand \textbf{when the algorithm compares two elements of the array and when it does not}. + \pause\item For ease of analysis, we rename the elements of the array $A$ as $\{z_1,z_2,...,z_n\}$, with $z_i$ being the $i$th smallest element. + \pause\item $Z_{ij}=\{z_i,z_{i+1},...,z_j\}$: the set of elements between $z_i$ and $z_j$, inclusive. + \end{itemize} + + +\end{frame} + +\begin{frame}[t] +\frametitle{Randomized Quicksort: Expected Running Time} +\question{}{When does the algorithm compare $z_i$ and $z_j$?} + \begin{itemize} + \item Each pair of elements is compared \textbf{\color{blue}at most once} + \item Elements are compared \textbf{\color{blue}only to the pivot element} + \item After a particular call of \textproc{Partition} finishes, \textbf{\color{blue}the pivot element} used in that call is \textbf{\color{blue}never again} compared to any other elements. + \end{itemize} +\pause\begin{block}{$X_{ij}$: indicator random variables} + \begin{center} + \fbox{ $X_{ij}=I\{z_i \text{ is compared to } z_j\}$} + \end{center} +\end{block} +\pause\begin{block}{Then, we have:} + \begin{center} + \fbox{$X=\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{X_{ij}}}$} + \end{center} +\end{block} +\end{frame} + +\begin{frame}[t] +\frametitle{Randomized Quicksort: Expected Running Time} +\question{}{ How to compute the expected value of $X$?} + \begin{center} + \fbox{$E\left[ X\right] =E\left[\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{X_{ij}}}\right] $} + \[ + \begin{array}{ll} + E\left[X\right]&=E\left[\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{X_{ij}}}\right]\\\vspace{1ex} + &{\color{green!80!black!80!}=\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{E\left[X_{ij}\right]}}}\\\vspace{1ex} + &=\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{\color{red}Pr\{z_i \text{ is compared to } z_j\}}}\\\vspace{1ex} + &{\color{green!80!black!60!}=\sum_{i=1}^{n-1}{\sum_{j=i+1}^{n}{\color{red}\frac{2}{j-i+1}}}}\\\vspace{1ex} + &=\sum_{i=1}^{n-1}{\sum_{k=1}^{n-i}{\frac{2}{k+1}}}\\\vspace{1ex} + &{\color{green!80!black!60!}<\sum_{i=1}^{n-1}{\sum_{k=1}^{n}{\frac{2}{k}}}}\\\vspace{1ex} + &=\sum_{i=1}^{n-1}{{O(\lg{n})}}\\\vspace{1ex} + &{\color{green!80!black!60!}=O(n\lg{n})}\\\vspace{1ex} + \end{array} + \] + \end{center} +\end{frame} + +\begin{frame}[t] +\frametitle{Randomized Quicksort: Expected Running Time} +\question{}{What is {\color{red}$Pr\{z_i \text{ is compared to } z_j\}$}?} +\begin{block}{} + \begin{center} + \begin{tikzpicture} + \node at(0,0){\includegraphics[width=.9\textwidth]{figs/Pr_zi_zj.png}}; + \pause\draw[color=red,thick](1.2,1.35)rectangle(2.7,1.75); + \draw[color=red,thick](0.4,0.85)rectangle(1.9,1.25); + + \filldraw [color=black,fill=lightgray] (-4,-3.5)rectangle (4,-3); + \filldraw [color=black,fill=green!20!] (-2.75,-3.5)rectangle (0.75,-3); + \fill[ball color=blue!60] (-2.5,-3.25) circle (0.2)node[color=white]{$z_i$}; + \fill[ball color=blue!60] (0.5,-3.25) circle (0.2)node[color=white]{$z_j$}; + \draw[->,>=triangle 45,color=orange] (-3.2,-2.5)--+(0,-0.5); + \draw[->,>=triangle 45,color=orange] (2.5,-2.5)--+(0,-0.5); + \draw[->,>=triangle 45,color=orange] (-1,-2.5)--+(0,-0.5); + \end{tikzpicture} + + \end{center} +\end{block} +\end{frame} + +\begin{frame}[t] +\frametitle{Top 10 Algorithms} +\begin{block}{The 10 Algorithms with the Greatest Influence on the Development and Practice of Science and Engineering in the 20th Century} + \begin{columns} + \begin{column}[T, onlytextwidth]{.55\textwidth} + \scriptsize{ + \begin{itemize} + \item Metropolis Algorithm for Monte Carlo + \item Simplex Method for Linear Programming + \item Krylov Subspace Iteration Methods + \item The Decompositional Approach to Matrix Computations + \item The Fortran Optimizing Compiler + \item QR Algorithm for Computing Eigenvalues + \item \small{\textbf{\color{red}Quicksort Algorithm for Sorting}} + \item Fast Fourier Transform + \item Integer Relation Detection + \item Fast Multipole Method + \end{itemize} + } + \end{column} + \begin{column}[T, onlytextwidth]{.45\textwidth} + \begin{center} + \includegraphics[width=.8\textwidth]{figs/top10.png} + + \includegraphics[width=.8\textwidth,height=0.3\textheight]{figs/top10_comments_on_quicksort.png} + \end{center} + \end{column} + \end{columns} + \begin{center} + \fbox{\parbox{\textwidth}{\tiny{ Jack Dongarra and Francis Sullivan. 2000. Guest Editors’ Introduction: The Top 10 Algorithms. Computing in Science and Engg. 2, 1 (January 2000), 22–23. DOI:https://doi.org/10.1109/MCISE.2000.814652}}} + \end{center} + +\end{block} +\end{frame} +\subsection{Comparison-based Sort} +\begin{frame} + \frametitle{Comparison-based Sort Algorithm} + \begin{theorem}[8.1]{ + Any comparison sort algorithm requires \textbf{\color{blue}$\Omega(n\lg{n})$} comparisons in the worst case. + + } + \end{theorem} + \begin{center} + \includegraphics[width=.6\textwidth]{figs/decision_tree_comparison_based_sorting.png} + \begin{itemize} + \item \textbf{\color{blue}$n!$} reachable leaves, each of which corresponds to a possible permutation + \item \textbf{\color{blue}$h$}: the height of the decision (binary) tree + \item $n!\le 2^h \Longrightarrow$ {\color{blue}$h\ge \lg{n!}=\Omega(n\lg{n})$} + \end{itemize} + \end{center} +\end{frame} + +\subsection{Sorting in Linear Time} +\begin{frame} +\frametitle{Sorting in Linear Time} +\begin{itemize} + \item Counting Sort + \item Radix Sort + \item Bucket Sort +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Sorting in Linear Time: Counting Sort} +\begin{center} +\begin{block}{Assumption} + \begin{center} + \fbox{ \parbox{0.95\textwidth}{% + \begin{center} + Each of the input elements is an integer in the {\color{blue}range $0$ to $k$}. + \end{center} + }% + } + +$T(n)=\Theta(n+k)$, and if $k=O(n)$, $T(n)=\Theta(n)$. + \end{center} + +\end{block} + + \begin{center} + \begin{tikzpicture} + \node at(-4,0){\fbox{\includegraphics[width=0.6\textwidth]{figs/counting_sort_procedure.png}}}; + \node at(2,1){ \includegraphics[width=0.3\textwidth]{figs/counting_sort_example_a.png} + }; + \node at(1.9,-1.2){ \includegraphics[width=.28\textwidth]{figs/counting_sort_example_b.png}}; + + \onslide<2>{ \draw [color=blue](-7,-0.2) rectangle ++(5.5,0.9) node[below](a){ }; + \draw[->,color=blue](a)--++(1.7,0); + } + \onslide<3>{\draw [color=red](-7,-1.08) rectangle ++(6.7,0.88) node[below](b){ }; + \draw[->,color=red](b)--++(0.6,-0.4); + } + \onslide<4->{\draw [color=purple](-7,-1.9) rectangle ++(3,0.88) node[below,right]{\color{red}Stable}; + } + \onslide<5->\node at (0,0.75) [fill= yellow,text width=7cm]{ \textbf{\color{red}stable:} \footnotesize{ numbers with the \textbf{\color{blue}same value} appear in the output array \textbf{\color{blue}in the same order} as they do in the input array. + } +}; + \end{tikzpicture} +\end{center} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Sorting in Linear Time: Counting Sort} +\begin{center} + \fbox{\includegraphics[width=4cm]{figs/counting_sort_procedure_output.png}} + \begin{tikzpicture} + \node at(-2.5,3){ \includegraphics[width=0.3\textwidth]{figs/counting_sort_example_a.png} + }; + \node at(2.5,3){ \includegraphics[width=.28\textwidth]{figs/counting_sort_example_b.png}}; + + + \node at(-4,0) {\includegraphics[width=0.31\textwidth]{figs/counting_sort_example_c.png}}; + \node at(0,0) {\includegraphics[width=0.3\textwidth]{figs/counting_sort_example_d.png}}; + \node at(4,0) {\includegraphics[width=0.3\textwidth]{figs/counting_sort_example_e.png}}; + \end{tikzpicture} +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Sorting in Linear Time: Radix Sort} +\begin{center} + \begin{block}{Assumption} + \begin{center} + \fbox{ \parbox{0.95\textwidth}{% + \begin{center} + \begin{itemize} + \item Each element in the $n$-element array $A$ has $d$ digits, where digit $1$ is the lowest-order digit and digit $d$ is the highest-order digit. + \item Each digit can take on up to $k$ possible values + \end{itemize} + \end{center} + } + } + \end{center} + + \end{block} + \begin{block}{} + \begin{center} + \begin{tikzpicture} + \node at (0,0) { \fbox{\includegraphics[width=.5\textwidth]{figs/radix_sort_procedure.png}}}; + \pause\draw [color=red,thick] (-1.5,-0.7) rectangle (0,-0.2); + \end{tikzpicture} + \includegraphics[width=.4\textwidth]{figs/radix_sort_example.png} + \end{center} + \end{block} + +\end{center} +\end{frame} + +\begin{frame} +\frametitle{Sorting in Linear Time: Radix Sort} +\begin{center} + \begin{lemma}[8.3] + Given $n$ $d$-digit numbers in which each digit can take on up to $k$ possible values, \textproc{Radix-Sort} correctly sorts these numbers in \textbf{\color{blue}$\Theta(d(n+k))$} time if the \textbf{\color{green!90!black!90!}stable sort} it uses takes \textbf{\color{green!90!black!90!}$\Theta(n+k)$} time. + \end{lemma} + + \begin{lemma}[8.4] + Given $n$ $b$-bit numbers and any positive integer {\color{red}$r$}$\le b$, \textproc{Radix-Sort} correctly sorts these numbers in $\Theta((b/r)(n+2^r))$ time if the \textbf{\color{green!90!black!90!}stable sort} it uses takes \textbf{\color{green!90!black!90!}$\Theta(n+k)$} time for inputs in the range $0$ to $k$. + \end{lemma} + \includegraphics[width=0.9\linewidth]{figs/proof_lemma_8-4.png} +\end{center} +\end{frame} +\begin{frame} +\frametitle{Sorting in Linear Time: Bucket Sort} +\begin{center} + \begin{block}{Assumption} + + \fbox{ \parbox{0.95\textwidth}{% + \begin{center} + The input is drawn from a \textbf{\color{blue}uniform distribution} + \end{center} + }} + + \end{block} + \begin{center} + \begin{tikzpicture} + \node at (0,0) {\fbox{\includegraphics[width=.8\textwidth]{figs/bucket_sort_procedure.png}}}; + \node at(4,0.2) {\includegraphics[width=.4\textwidth]{figs/bucket_sort_example.png}}; + \draw [color=red,thick](-1,-1.7) rectangle(1,-1.4); + \end{tikzpicture} + \end{center} +\end{center} +\end{frame} + + +\begin{frame} +\frametitle{Sorting in Linear Time: Bucket Sort} + \begin{center} + \begin{tikzpicture} + \node at (0,0) {\fbox{\includegraphics[width=.8\textwidth]{figs/bucket_sort_procedure.png}}}; + \draw [color=red,thick](-1,-1.7) rectangle(1,-1.4); + \pause\node at(1.5,-1.55){\color{blue}$O(n_i^2)$}; + \pause\node at (2.5,0) {\color{blue}$T(n)=\Theta(n)+\sum\limits_{i=0}^{n-1}{O(n_i^2)}$}; + \end{tikzpicture} + \end{center} +\begin{itemize} + \item All lines except line 8 take {\color{blue}$O(n)$} time in the worst case. + \item {\color{blue}$n_i$}: the number of elements placed in bucket $B\left[i\right]$. +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{Sorting in Linear Time: Bucket Sort} +\[ +\begin{array}{ll} +E\left[T(n)\right]&=E\left[\Theta(n)+\sum\limits_{i=0}^{n-1}{O(n_i^2)}\right]\\\vspace{0.2cm} +&=\Theta(n)+\sum\limits_{i=0}^{n-1}{E\left[O(n_i^2)\right]}\\\vspace{0.2cm} +&=\Theta(n)+{\color{blue}\sum\limits_{i=0}^{n-1}{O(E\left[n_i^2\right])}}\\\vspace{0.2cm} +&=\Theta(n) +\end{array} +\] +\begin{center} + \pause\begin{tikzpicture} + \node at(0,0) {\fbox{\includegraphics[width=0.5\textwidth]{figs/bucket_sort_Xij.png}}}; + \node at(6,0){\fbox{ ${\color{blue}\sum\limits_{i=0}^{n-1}{O(E\left[n_i^2\right])}=2-\frac{1}{n}}$}}; + \draw[color=blue!80!black!60!,->,>=triangle 45,line width=2pt] (3.2,0)--+(0.8,0); + \end{tikzpicture} + + +\end{center} +\end{frame} + + +\section{Selection} +\subsection{Minimum and Maximum} +\begin{frame} +\frametitle{Minimum and Maximum} +\begin{center} + \begin{problem}[Minimum or Maximum] + Given a subset of a total-order set, find the maximum \textbf{or} minimum element of the subset. + \begin{itemize} + \item requires \textbf{\color{blue}at least $n-1$} comparisons + \end{itemize} + \end{problem} + \includegraphics[width=0.4\textwidth]{figs/minimum_procedure.png} +\end{center} +\end{frame} +\begin{frame} +\frametitle{Minimum and Maximum} +\begin{center} + + \begin{problem}[Maximum \& minimum] + Given a subset of a total-order set, find both the maximum \textbf{and} minimum elements of the subset. + \begin{itemize} + \item does not require $2n-2$ comparisons + \end{itemize} + \end{problem} + +\pause \begin{proof}[A possible way for finding both maximum \& minimum] + \begin{itemize} + \item compare pairs of elements from the input first with each other + \item then compare the smaller with the current minimum and the larger to the current maximum + \item at most $3\lfloor n/2\rfloor$ comparisons + \end{itemize} + + \end{proof} +\end{center} +\end{frame} +\subsection{Selection in Expected Linear Time} +\begin{frame} +\frametitle{General Selection Problem} +\begin{problem}[General Selection] + Given a subset of a total-order set, find the {\color{red}$i$-th} smallest element of the subset. +\end{problem} +\end{frame} +\begin{frame} +\frametitle{Selection in Expected Linear Time + : \textproc{Randomized-Select}} +\begin{center} + \begin{tikzpicture} + \node at (0,0) {\includegraphics[width=.7\textwidth]{figs/randomized-selection-procedure.png}}; + \onslide<2->\node at (4,2) {\fbox{\includegraphics[width=.4\textwidth]{figs/randomized-quicksort.png}}}; + + \end{tikzpicture} + + \onslide<2->{ + Similar to \textproc{Randomized-QuickSort}, but only have to handle exact one sub-problem in each step of the recursion.} + +\end{center} +\end{frame} + +\begin{frame} +\frametitle{\textproc{Randomized-Select}: Expected Running Time} +\question{}{What is the expected running time of \textproc{Randomized-Select}?} +\begin{center} + \begin{columns} + \begin{column}[T, onlytextwidth]{.6\textwidth} + + \pause \begin{block}{indicator random variable \textbf{\color{red}$X_k$} :} + \begin{itemize} + \item \footnotesize{ + $X_k=I\{\text{the subarray }A\left[p..q\right] \text{ has exactly }k\text{ elements}\}$ + } + \item assuming the elements are distinct, we have $E\left[X_k \right]=1/n $ + \end{itemize} + + \end{block} + \end{column} + \begin{column}[T, onlytextwidth]{.4\textwidth} + \begin{tikzpicture} + \node at (0,0) {\fbox{\includegraphics[width=.9\textwidth]{figs/randomized-selection-procedure.png}}}; + + \end{tikzpicture} + \end{column} + + \end{columns} + \pause\begin{block}{$T(n)$: the running time on an input array of size $n$} + \begin{tikzpicture} + \node at (0,0){ \includegraphics[width=0.6\textwidth]{figs/randomized-selection-runtime-total.PNG}}; + \pause \draw [color=red,thick] (-2.6,0.3)rectangle ++(0.5,0.5); + \draw [color=red,thick] (-0.8,0.3)rectangle ++(3,0.5); + \end{tikzpicture} + + \end{block} + +\end{center} +\end{frame} + +\begin{frame} +\frametitle{\textproc{Randomized-Select}: Expected Running Time} + + \begin{block}{$E\left[ T(n)\right] $: the expected running time on an input array of size $n$} + \begin{center} + \includegraphics[width=0.8\textwidth]{figs/randomized-selection-expected-runtime-total.PNG} + + \pause Then, we could prove $E\left[ T(n)\right]=O(n)$ by substitution. Assuming: + \[ + {\color{blue} E\left[ T(n)\right]\le cn} + \] + + \end{center} + \end{block} +\end{frame} +\subsection{Selection in Worst-case Linear Time} +\begin{frame} +\frametitle{Selection in Expected Linear Time: \textproc{Select} } + +\begin{block}{\textproc{Select}} + \begin{center} +\begin{enumerate} + \item Divide the input array into {\color{blue}$\lceil n/5 \rceil$} groups of 5 elements each + \begin{itemize} + \item at most one group made up of the remaining $n$ mod 5 elements. + \end{itemize} + \item Find the \textbf{median} of each of the {\color{blue}$\lceil n/5 \rceil$} groups with \textbf{insertion-sort}. + \item Use \textproc{Select} recursively to find the \textbf{median} {\color{blue}$m^*$} of the medians found in step 2. + \item \textbf{\color{red}\textproc{Partition}} the input array around the \textbf{median-of-medians} $m^*$. + \item Assume that {\color{blue}$m^*$} is the $k$th smallest element. If $i=k$, then return $m^*$. Otherwise, use +\textproc{Select} recursively: + \begin{itemize} + \item if $ik$, find the $(i-k)$th smallest element on the high side + \end{itemize} +\end{enumerate} + \end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{\textproc{Select}} +\begin{block}{Step 1: Divide the input array into {\color{blue}$\lceil n/5 \rceil$} groups of 5 elements each } + \begin{center} + \begin{tikzpicture} + \foreach \x in {0.25,0.5,...,4}{ + \fill[ball color=gray!60] (\x,3) circle (0.1); + \fill[ball color=gray!60] (0-\x,3) circle (0.1); + } + \node at (0,3) {...}; + \draw[->,>=triangle 45,line width=4pt,color=green!90!black!70!] (0,2.8)--(0,1.2); + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \foreach \y in {-1,-0.5,0,0.5,1} + \fill[ball color=gray!60] (\x,\y) circle (0.1); + \node at (-1.5,0) {...}; + \node at (1.5,0){...}; + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} +\begin{frame} +\frametitle{\textproc{Select}} +\begin{block}{Step 2: Find the \textbf{median} of each of the {\color{blue}$\lceil n/5 \rceil$} groups with \textproc{insertion-sort}. } + \begin{center} + \begin{tikzpicture} + + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \foreach \y in {-1,-0.5,0,0.5,1} + \fill[ball color=gray!60] (\x,\y) circle (0.1); + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \fill[ball color=blue!60] (\x,0) circle (0.1); + + \node at (-1.5,0) {...}; + \node at (1.5,0){...}; + { + \draw [dashed] (-3.3,-0.25) rectangle (3.3,0.25); + \node at(4,0){medians}; + + } + \end{tikzpicture} + \end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{\textproc{Select}} +\begin{block}{Step 3: Use \textproc{Select} recursively to find the \textbf{median} {\color{blue}$m^*$} of the medians found in step 2. } + \begin{center} + \begin{tikzpicture} + + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \foreach \y in {-1,-0.5,0,0.5,1} + \fill[ball color=gray!60] (\x,\y) circle (0.1); + \foreach \x in {-3,-2.5,-0.5,0.5,2.5,3} + \fill[ball color=blue!40] (\x,0) circle (0.1); + + \node at (-1.5,0) {...}; + \node at (1.5,0){...}; + { + \draw [dashed] (-3.3,-0.25) rectangle (3.3,0.25); + \node at(4,0){medians}; + + } + \onslide<2-> { + \fill[ball color=red!60] (0,0) circle (0.15); + \node (a) [color=red]at(0.3,0.2) {$m^*$}; + \node [color=red] (b) at (0,1.5){median of medians}; + \draw [->,>=triangle 45,color=blue!60,line width=1pt](b)--(0,0.15); + } + + \onslide<3->{ + \draw [->,>=triangle 45,color=blue!60, line width=3pt](-4,-1)--node[left]{increasing}(-4,1) ; + \draw [->,>=triangle 45,color=blue!60,line width=3pt](-3,-1.5)--node[below]{increasing by medians}(3,-1.5) ; + } + + + + + \end{tikzpicture} + + \end{center} +\end{block} +\end{frame} +\begin{frame} +\frametitle{\textproc{Select}} +\begin{block}{Step 4: \textproc{Partition} the input array around $m^*$.} + \begin{center} + \begin{tikzpicture} + { + \filldraw [fill=blue!30,draw=black,line width=0.5pt] (-3.2,0.3) rectangle (-0.3,1.2); + + \filldraw [fill=green!30,draw=black,line width=0.5pt] (0.3,-1.2) rectangle (3.2,-0.3); + \filldraw [fill=purple!30,draw=black,line width=0.5pt] (-0.2,-0.2) rectangle (3.2, 1.2); + \filldraw [fill=orange!30,draw=black,line width=0.5pt] (-3.2,-1.2) rectangle (0.2,0.2); + } + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \foreach \y in {-1,-0.5,0,0.5,1} + \fill[ball color=gray!60] (\x,\y) circle (0.1); + \foreach \x in {-3,-2.5,-0.5,0.5,2.5,3} + \fill[ball color=blue!60] (\x,0) circle (0.1); + + \node at (-1.5,0) {...}; + \node at (1.5,0){...}; + { + \draw [dashed] (-3.3,-0.25) rectangle (3.3,0.25); + \node at(4,0){medians}; + + } + { + \fill[ball color=red!60] (0,0) circle (0.15); + \node (a) [color=red]at(0.3,0.2) {$m^*$}; + \node [color=red] (b) at (0,1.5){median of medians}; + \draw [->,>=triangle 45,color=blue!60,line width=1pt](b)--(0,0.15); + } + + { + \draw [->,>=triangle 45,color=blue!60, line width=3pt](-4,-1)--node[left]{increasing}(-4,1) ; + \draw [->,>=triangle 45,color=blue!60,line width=3pt](-3,-1.5)--node[below]{increasing by medians}(3,-1.5) ; + } + + + { + \node at(-1.5,0.75){A}; + \node at(-1.5,-0.75){C}; + \node at(1.5,0.75){B}; + \node at(1.5,-0.75){D}; + } + { + \node [color=blue]at(-1.5,-0.4) {$m^*$}; + } + \pause{ + \node [color=green!80!black]at (0,-2.5){$>m^*$ or $k$, find the $(i-k)$th smallest element on the high side + \end{itemize} + \end{itemize} + } + \begin{center} + \begin{tikzpicture} + { + \filldraw [fill=blue!30,draw=black,line width=0.5pt] (-3.2,0.3) rectangle (-0.3,1.2); + + \filldraw [fill=green!30,draw=black,line width=0.5pt] (0.3,-1.2) rectangle (3.2,-0.3); + \filldraw [fill=purple!30,draw=black,line width=0.5pt] (-0.2,-0.2) rectangle (3.2, 1.2); + \filldraw [fill=orange!30,draw=black,line width=0.5pt] (-3.2,-1.2) rectangle (0.2,0.2); + } + \foreach \x in {-3,-2.5,-0.5,0,0.5,2.5,3} + \foreach \y in {-1,-0.5,0,0.5,1} + \fill[ball color=gray!60] (\x,\y) circle (0.1); + \foreach \x in {-3,-2.5,-0.5,0.5,2.5,3} + \fill[ball color=blue!60] (\x,0) circle (0.1); + + \node at (-1.5,0) {...}; + \node at (1.5,0){...}; + { + \draw [dashed] (-3.3,-0.25) rectangle (3.3,0.25); + \node at(4,0){medians}; + + } + { + \fill[ball color=red!60] (0,0) circle (0.15); + \node (a) [color=red]at(0.3,0.2) {$m^*$}; + \node [color=red] (b) at (0,1.5){median of medians}; + \draw [->,>=triangle 45,color=blue!60,line width=1pt](b)--(0,0.15); + } + + { + \draw [->,>=triangle 45,color=blue!60, line width=3pt](-4,-1)--node[left]{increasing}(-4,1) ; + \draw [->,>=triangle 45,color=blue!60,line width=3pt](-3,-1.5)--node[below]{increasing by medians}(3,-1.5) ; + } + + + { + \node at(-1.5,0.75){A}; + \node at(-1.5,-0.75){C}; + \node at(1.5,0.75){B}; + \node at(1.5,-0.75){D}; + } + { + \node [color=blue]at(-1.5,-0.4) {$m^*$}; + } + + \pause { + \node at (4,1.5){$|B|\ge 3n/10-6$;}; + \node at (-5,-1.5){ $|C|\ge 3n/10-6$}; + } + \pause \node [color=blue!80!black]at (0,-2.5){calls \textproc{Select} recursively on at most {\color{blue}$7n/10+6$} elements. }; + \end{tikzpicture} + + \end{center} +\end{block} +\end{frame} + +\begin{frame} +\frametitle{The \textproc{Select} algorithm: Running Time in Worst-case} +\begin{block}{Counting the total number of comparisons} + \begin{center} + \begin{tikzpicture} + \node at (0,0){$T(n)\le{\color{green!90!black!90!}T(\lceil n/5\rceil)}+{\color{blue!90!black!90!}T(7n/10+6)}+{\color{red!90!black!90!}O(n)}$}; + \end{tikzpicture} + \begin{itemize} + \item {\color{green!90!black!90!}$T(\lceil n/5\rceil)$}: find the median of the medians + \item {\color{blue!90!black!90!}$T(7n/10+6)$}: maximum cost for calling \textproc{Select} recursively. + \item {\color{red!90!black!90!}$O(n)$}: + \begin{itemize} + \item divide the input array into 5-elements groups + \item find medians of all 5-elements groups, about $6*\lceil n/5\rceil$ + \item \textproc{Partition} with the pivot $m^*$ + \end{itemize} + \end{itemize} + \end{center} +\end{block} +\begin{block}{We could show that the running time {\color{red}$T(n)=O(n)$} by substitution} +\end{block} +\end{frame} +\begin{frame} + \begin{block}{ + \begin{center} + {\huge + Thank You! + + \textcolor[rgb]{1,0,0} {Questions?} + } + \end{center} + } + \end{block} + \begin{block}{} + \begin{center} + + Office 819 + + majun@nju.edu.cn + \end{center} + \end{block} + \end{frame} +\end{document} \ No newline at end of file diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/ICS_LOGO_left.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/ICS_LOGO_left.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/Pr_zi_zj.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/Pr_zi_zj.PNG new file mode 100644 index 0000000..2ededea Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/Pr_zi_zj.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_Xij.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_Xij.png new file mode 100644 index 0000000..b3b5969 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_Xij.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_example.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_example.png new file mode 100644 index 0000000..a9a8a9d Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_example.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_procedure.png new file mode 100644 index 0000000..31487fa Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/bucket_sort_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/correctness_quicksort_partition_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/correctness_quicksort_partition_procedure.png new file mode 100644 index 0000000..29c60a1 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/correctness_quicksort_partition_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_a.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_a.png new file mode 100644 index 0000000..acd3cd4 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_a.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_ab.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_ab.png new file mode 100644 index 0000000..58dde84 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_ab.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_b.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_b.png new file mode 100644 index 0000000..587f2df Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_b.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_c.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_c.png new file mode 100644 index 0000000..006e6de Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_c.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_d.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_d.png new file mode 100644 index 0000000..991d56e Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_d.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_e.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_e.png new file mode 100644 index 0000000..7ecde2d Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_example_e.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure.png new file mode 100644 index 0000000..0d9d4b5 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure_output.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure_output.png new file mode 100644 index 0000000..87fdfb7 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/counting_sort_procedure_output.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/decision_tree_comparison_based_sorting.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/decision_tree_comparison_based_sorting.png new file mode 100644 index 0000000..c18fad9 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/decision_tree_comparison_based_sorting.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/mergesort.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/mergesort.png new file mode 100644 index 0000000..023c871 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/mergesort.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/minimum_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/minimum_procedure.png new file mode 100644 index 0000000..f8328af Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/minimum_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/pq_heap_maximum.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/pq_heap_maximum.PNG new file mode 100644 index 0000000..5af96e2 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/pq_heap_maximum.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/proof_lemma_8-4.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/proof_lemma_8-4.png new file mode 100644 index 0000000..954c6f1 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/proof_lemma_8-4.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort.png new file mode 100644 index 0000000..1928d89 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort__partition_process.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort__partition_process.PNG new file mode 100644 index 0000000..5db4dd5 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort__partition_process.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_binary_tree.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_binary_tree.png new file mode 100644 index 0000000..ab5cf2a Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_binary_tree.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_partition_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_partition_procedure.png new file mode 100644 index 0000000..e2071c2 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_partition_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_process.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_process.png new file mode 100644 index 0000000..c16612c Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/quicksort_process.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_example.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_example.PNG new file mode 100644 index 0000000..b7f1944 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_example.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_procedure.png new file mode 100644 index 0000000..9580116 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/radix_sort_procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-partition-procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-partition-procedure.png new file mode 100644 index 0000000..b508652 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-partition-procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-quicksort.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-quicksort.png new file mode 100644 index 0000000..ba9d4a0 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-quicksort.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-expected-runtime-total.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-expected-runtime-total.PNG new file mode 100644 index 0000000..648db28 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-expected-runtime-total.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-procedure.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-procedure.png new file mode 100644 index 0000000..643129e Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-procedure.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-runtime-total.PNG b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-runtime-total.PNG new file mode 100644 index 0000000..bd56f43 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/randomized-selection-runtime-total.PNG differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/recur_tree_quicksort.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/recur_tree_quicksort.png new file mode 100644 index 0000000..06094e3 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/recur_tree_quicksort.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10.png new file mode 100644 index 0000000..196061d Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10_comments_on_quicksort.png b/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10_comments_on_quicksort.png new file mode 100644 index 0000000..61d00c1 Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/figs/top10_comments_on_quicksort.png differ diff --git a/2019/2019-2/2019-2-9-Sorting&Selection/top_10_algorithm.png b/2019/2019-2/2019-2-9-Sorting&Selection/top_10_algorithm.png new file mode 100644 index 0000000..196061d Binary files /dev/null and b/2019/2019-2/2019-2-9-Sorting&Selection/top_10_algorithm.png differ diff --git a/2019/2019-2/figs/ICS_LOGO_left.png b/2019/2019-2/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/2019/2019-2/figs/ICS_LOGO_left.png differ diff --git a/2021/2021-1/1-1 Why.pptx b/2021/2021-1/1-1 Why.pptx new file mode 100644 index 0000000..3244a9a Binary files /dev/null and b/2021/2021-1/1-1 Why.pptx differ diff --git a/2021/2021-1/2021-1-8-set/2021-1-8-set.pdf b/2021/2021-1/2021-1-8-set/2021-1-8-set.pdf new file mode 100644 index 0000000..bba1570 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/2021-1-8-set.pdf differ diff --git a/2021/2021-1/2021-1-8-set/2021-1-8-set.tex b/2021/2021-1/2021-1-8-set/2021-1-8-set.tex new file mode 100644 index 0000000..53a8220 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/2021-1-8-set.tex @@ -0,0 +1,26 @@ +% 2019-1-8-set.tex + +\documentclass[]{beamer} +\input{preamble} + +%%%%%%%%%% +\title[Set Theory: Axioms and Operations]{\titletext} +\subtitle{} + +\author[Jun Ma]{\large 马骏} + +\institute{majun@nju.edu.cn} +\date{2021年11月25日} +%%%%%%%%%% +\begin{document} + +\maketitle + +\input{parts/overview} +\input{parts/axioms} +\input{parts/operations} +\input{parts/conclusion} + +\thankyou{} +\end{document} +%%%%%%%%%% \ No newline at end of file diff --git a/2021/2021-1/2021-1-8-set/README.md b/2021/2021-1/2021-1-8-set/README.md new file mode 100644 index 0000000..414b20a --- /dev/null +++ b/2021/2021-1/2021-1-8-set/README.md @@ -0,0 +1,7 @@ +# 2019-1-8-set + +## Overview + +## Axioms + +## Operations \ No newline at end of file diff --git a/2021/2021-1/2021-1-8-set/figs/A-B-Cc.png b/2021/2021-1/2021-1-8-set/figs/A-B-Cc.png new file mode 100644 index 0000000..eb3e0f0 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/A-B-Cc.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/Fraenkel.jpg b/2021/2021-1/2021-1-8-set/figs/Fraenkel.jpg new file mode 100644 index 0000000..e81be99 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Fraenkel.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/Frege-old.jpg b/2021/2021-1/2021-1-8-set/figs/Frege-old.jpg new file mode 100644 index 0000000..8bbea54 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Frege-old.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/Frege.jpg b/2021/2021-1/2021-1-8-set/figs/Frege.jpg new file mode 100644 index 0000000..c6dab86 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Frege.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/Russell.png b/2021/2021-1/2021-1-8-set/figs/Russell.png new file mode 100644 index 0000000..3f1f6d9 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Russell.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/Zermelo-old.jpeg b/2021/2021-1/2021-1-8-set/figs/Zermelo-old.jpeg new file mode 100644 index 0000000..f83a9ef Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Zermelo-old.jpeg differ diff --git a/2021/2021-1/2021-1-8-set/figs/Zermelo.jpg b/2021/2021-1/2021-1-8-set/figs/Zermelo.jpg new file mode 100644 index 0000000..818929f Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/Zermelo.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/ambiguous.jpg b/2021/2021-1/2021-1-8-set/figs/ambiguous.jpg new file mode 100644 index 0000000..d9e21fa Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/ambiguous.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/calm-fix-it.png b/2021/2021-1/2021-1-8-set/figs/calm-fix-it.png new file mode 100644 index 0000000..b2d3d7a Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/calm-fix-it.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/cannot-see.gif b/2021/2021-1/2021-1-8-set/figs/cannot-see.gif new file mode 100644 index 0000000..6d853c4 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/cannot-see.gif differ diff --git a/2021/2021-1/2021-1-8-set/figs/cannot-see.png b/2021/2021-1/2021-1-8-set/figs/cannot-see.png new file mode 100644 index 0000000..b9acb1b Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/cannot-see.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/cantor-1870.jpg b/2021/2021-1/2021-1-8-set/figs/cantor-1870.jpg new file mode 100644 index 0000000..a65f914 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/cantor-1870.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/cantor-infinity.jpg b/2021/2021-1/2021-1-8-set/figs/cantor-infinity.jpg new file mode 100644 index 0000000..a01c365 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/cantor-infinity.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/cantor.jpg b/2021/2021-1/2021-1-8-set/figs/cantor.jpg new file mode 100644 index 0000000..37ba0fa Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/cantor.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/distributive-proof.png b/2021/2021-1/2021-1-8-set/figs/distributive-proof.png new file mode 100644 index 0000000..d346574 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/distributive-proof.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/do-not-know-either.png b/2021/2021-1/2021-1-8-set/figs/do-not-know-either.png new file mode 100644 index 0000000..e9ef2b3 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/do-not-know-either.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/elements-ch.jpeg b/2021/2021-1/2021-1-8-set/figs/elements-ch.jpeg new file mode 100644 index 0000000..4ea2d0f Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/elements-ch.jpeg differ diff --git a/2021/2021-1/2021-1-8-set/figs/fix-it.jpg b/2021/2021-1/2021-1-8-set/figs/fix-it.jpg new file mode 100644 index 0000000..c3572fc Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/fix-it.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/frege-arithmetic.jpeg b/2021/2021-1/2021-1-8-set/figs/frege-arithmetic.jpeg new file mode 100644 index 0000000..4866da9 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/frege-arithmetic.jpeg differ diff --git a/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.gif b/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.gif new file mode 100644 index 0000000..1aee7b2 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.gif differ diff --git a/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.png b/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.png new file mode 100644 index 0000000..ac2551b Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/have-to-fix-it.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/kiss.jpg b/2021/2021-1/2021-1-8-set/figs/kiss.jpg new file mode 100644 index 0000000..1074eae Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/kiss.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/known-unknown.jpg b/2021/2021-1/2021-1-8-set/figs/known-unknown.jpg new file mode 100644 index 0000000..cb56fc1 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/known-unknown.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/leng.jpg b/2021/2021-1/2021-1-8-set/figs/leng.jpg new file mode 100644 index 0000000..e70b332 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/leng.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/math-help.jpg b/2021/2021-1/2021-1-8-set/figs/math-help.jpg new file mode 100644 index 0000000..a44ddac Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/math-help.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/not-sure.jpg b/2021/2021-1/2021-1-8-set/figs/not-sure.jpg new file mode 100644 index 0000000..9dfe4b2 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/not-sure.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/powerset-2-x-notation.png b/2021/2021-1/2021-1-8-set/figs/powerset-2-x-notation.png new file mode 100644 index 0000000..f4fc97c Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/powerset-2-x-notation.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/powerset-example.png b/2021/2021-1/2021-1-8-set/figs/powerset-example.png new file mode 100644 index 0000000..02e17d9 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/powerset-example.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/powerset-example.svg b/2021/2021-1/2021-1-8-set/figs/powerset-example.svg new file mode 100644 index 0000000..0793cf0 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/figs/powerset-example.svg @@ -0,0 +1,394 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + {}, + {a,b,c} + {a}, {b}, {c}, + {a,b}, {a,c}, {b,c}, + {a,b,c} + + diff --git a/2021/2021-1/2021-1-8-set/figs/prove-it.jpg b/2021/2021-1/2021-1-8-set/figs/prove-it.jpg new file mode 100644 index 0000000..fbaef6b Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/prove-it.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/qrcode-problem-solving-class-tutorial-2019-1.png b/2021/2021-1/2021-1-8-set/figs/qrcode-problem-solving-class-tutorial-2019-1.png new file mode 100644 index 0000000..7a67ab4 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/qrcode-problem-solving-class-tutorial-2019-1.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/qrcode-ps-2017-1st.png b/2021/2021-1/2021-1-8-set/figs/qrcode-ps-2017-1st.png new file mode 100644 index 0000000..9969434 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/qrcode-ps-2017-1st.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/russell-nobel.jpg b/2021/2021-1/2021-1-8-set/figs/russell-nobel.jpg new file mode 100644 index 0000000..bb21b58 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/russell-nobel.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/russell-philosophy.jpg b/2021/2021-1/2021-1-8-set/figs/russell-philosophy.jpg new file mode 100644 index 0000000..8442142 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/russell-philosophy.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/russell-pm.jpg b/2021/2021-1/2021-1-8-set/figs/russell-pm.jpg new file mode 100644 index 0000000..639e296 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/russell-pm.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/russell-western.jpg b/2021/2021-1/2021-1-8-set/figs/russell-western.jpg new file mode 100644 index 0000000..b782a9f Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/russell-western.jpg differ diff --git a/2021/2021-1/2021-1-8-set/figs/set-theory-aspects.pdf b/2021/2021-1/2021-1-8-set/figs/set-theory-aspects.pdf new file mode 100644 index 0000000..9377765 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/set-theory-aspects.pdf differ diff --git a/2021/2021-1/2021-1-8-set/figs/tan90.gif b/2021/2021-1/2021-1-8-set/figs/tan90.gif new file mode 100644 index 0000000..676faf8 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/tan90.gif differ diff --git a/2021/2021-1/2021-1-8-set/figs/tan90.png b/2021/2021-1/2021-1-8-set/figs/tan90.png new file mode 100644 index 0000000..e1d5fc8 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/tan90.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/thankyou.png b/2021/2021-1/2021-1-8-set/figs/thankyou.png new file mode 100644 index 0000000..a4e553f Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/thankyou.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/think-be-careful.png b/2021/2021-1/2021-1-8-set/figs/think-be-careful.png new file mode 100644 index 0000000..674294e Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/think-be-careful.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/ud-set-op-laws.png b/2021/2021-1/2021-1-8-set/figs/ud-set-op-laws.png new file mode 100644 index 0000000..c7e6ddb Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/ud-set-op-laws.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/von-Neumann.gif b/2021/2021-1/2021-1-8-set/figs/von-Neumann.gif new file mode 100644 index 0000000..fe8f54c Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/von-Neumann.gif differ diff --git a/2021/2021-1/2021-1-8-set/figs/von-Neumann.png b/2021/2021-1/2021-1-8-set/figs/von-Neumann.png new file mode 100644 index 0000000..0cef929 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/von-Neumann.png differ diff --git a/2021/2021-1/2021-1-8-set/figs/wunai.jpg b/2021/2021-1/2021-1-8-set/figs/wunai.jpg new file mode 100644 index 0000000..d7a7372 Binary files /dev/null and b/2021/2021-1/2021-1-8-set/figs/wunai.jpg differ diff --git a/2021/2021-1/2021-1-8-set/parts/axioms-EE.tex b/2021/2021-1/2021-1-8-set/parts/axioms-EE.tex new file mode 100644 index 0000000..85cf750 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/axioms-EE.tex @@ -0,0 +1,47 @@ +% axioms-EE.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Axiom of Extensionality] + If two sets have exactly the same members, then they are equal. + \[ + \forall A\; \forall B\; \big(\forall \blue{x} (\blue{x} \in A \iff \blue{x} \in B) \implies A = B \big). + \] + \[ + \forall A\; \forall B\; \big(A \subseteq B \land B \subseteq A \implies A = B \big). + \] + \end{axiom} + + \pause + \vspace{0.30cm} + \[ + \forall A\; \forall B\; \big(A \subseteq B \land B \subseteq A \red{\iff} A = B \big). + \] +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Empty Set Axiom] + There is a set having no members: + + \[ + \red{\exists B}\; \forall x (x \notin B). + \] + \end{axiom} + + \pause + \vspace{0.50cm} + \begin{theorem}[Uniqueness of Empty Set] + There is only one empty set. + \end{theorem} + + \pause + \vspace{0.50cm} + \begin{definition}[``$\emptyset$''] + \[ + \emptyset \triangleq \text{ the \teal{unique} empty set}. + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/axioms-IC.tex b/2021/2021-1/2021-1-8-set/parts/axioms-IC.tex new file mode 100644 index 0000000..f8ea680 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/axioms-IC.tex @@ -0,0 +1,2 @@ +% axioms-IC.tex + diff --git a/2021/2021-1/2021-1-8-set/parts/axioms-PURP.tex b/2021/2021-1/2021-1-8-set/parts/axioms-PURP.tex new file mode 100644 index 0000000..383a0d6 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/axioms-PURP.tex @@ -0,0 +1,307 @@ +% axioms-PURP.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Paring Axiom] + For any sets $x$ and $y$, there is a set having as members just $x$ and $y$: + + \[ + \forall x\; \forall y\; \red{\exists B}\; \big(\forall z (z \in B \iff z = x \lor z = y)\big). + \] + \end{axiom} + + \pause + \begin{definition}[``$\set{x, y}$''] + \[ + \set{x, y} \triangleq \text{ the \teal{unique} set obtained by \blue{paring} } x \text{ and } y. + \] + \end{definition} + + \pause + \begin{theorem} + \[ + \set{x, y} = \set{y, x}. + \] + \end{theorem} + + \pause + \begin{definition}[``$\set{x}$''] + \[ + \set{x} \triangleq \set{x, x}. + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Union Axiom (Simplified Version)] + For any sets $x$ and $y$, there is a set whose members are + the elements belonging either to $x$ or to $y$ (or both): + + \[ + \forall x\; \forall y\; \red{\exists B}\; \big(\forall z (z \in B \iff z \;\blue{\in}\; x \lor z \;\blue{\in}\; y)\big). + \] + \end{axiom} + + \pause + \vspace{0.60cm} + \begin{definition}[``$x \cup y$''] + \[ + x \cup y \triangleq \text{ the \teal{unique} set obtained by \blue{unioning} } x \text{ and } y. + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{definition}[``$\set{x, y}$''] + \[ + \set{x, y} \triangleq \text{ the \teal{unique} set obtained by \blue{paring} } x \text{ and } y. + \] + \end{definition} + + \begin{definition}[``$\set{x}$''] + \[ + \set{x} \triangleq \set{x, x}. + \] + \end{definition} + + \pause + \vspace{0.60cm} + \begin{definition}[``$\set{x, y, z}$''] + \[ + \set{x, y, z} \triangleq \set{x, y} \cup \set{z}. + \] + \end{definition} + + \pause + \begin{center} + We can use \blue{pairing} and \blue{union} together to form \red{finite sets}. + \end{center} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Union Axiom (Extended Version)] + For any set $A$, there is a set $B$ such that: + \[ + \forall x\; (x \in B \iff x \text{ belongs to some member of } A). + \] + \[ + \forall x \big( x \in B \iff \exists y \in A (x \in y) \big). + \] + \end{axiom} + + \pause + \begin{definition}[``$\bigcup A$'' (Arbitrary Union)] + \[ + \bigcup A \triangleq \text{ the \teal{unique} set obtained by \blue{unioning} } A. + \] + \end{definition} + + \pause + \begin{theorem} + \[ + \bigcup \set{x, y} = x \cup y. + \] + \end{theorem} + + \pause + \begin{theorem} + \[ + \bigcup \emptyset = \emptyset. + \] + \end{theorem} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Replacement Axioms (Simplified Version: Subset Axioms; Separation Axioms)] + \red{Let $\psi$ be a predicate.} + For any set $u$, there is a set $B$ + which is a subset of $u$ such that each element $x$ of $B$ satisfies $\psi(x)$: + + \[ + \forall u\; \red{\exists B}\; \big( \forall x (x \in B \iff x \in u \land \psi(x)) \big). + \] + \end{axiom} + + \begin{definition}[``$\set{x \in u \mid \psi(x)}$''] + \[ + \set{x \in u \mid \psi(x)} \triangleq \text{ the \teal{unique} set obtained by \blue{separating} from } u \text{ with } \psi. + \] + \end{definition} + + \pause + \begin{definition}[``$u \cap v$''] + \[ + u \cap v \triangleq \set{x \in u \mid x \in v}. + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[``$\bigcap A$'' (Arbitrary Intersection)] + \red{For any nonempty set $A$}, there is a unique set $B$ such that + \[ + \forall x\; (x \in B \iff x \text{ belongs to every member of } A). + \] + \[ + \forall x\; \big(x \in B \iff \forall y \in A (x \in y) \big). + \] + \end{theorem} + + \pause + \begin{proof} + \begin{center} + Let $c$ be a fixed member of $A$. + \end{center} + + \pause + \vspace{-0.50cm} + \[ + \bigcap A \triangleq \set{x \in c \mid x \text{ belongs to every other member of } A}. + \] + \end{proof} + + \pause + \begin{alertblock}{``$\bigcap \emptyset$''} + \pause + \[ + \bigcap \emptyset \text{ is \red{\it not} a set}. + \] + \pause + \[ + \forall X\forall y\left(y\in\bigcap X\leftrightarrow\forall x\left(x\in X\rightarrow y\in x\right)\right) + \] + \end{alertblock} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[No Universal Set] + There is no universal set. + + \[ + \red{\nexists B} \big(\forall x (x \in B) \big). + \] + \end{theorem} + + \pause + \begin{proof} + \begin{center} + \red{For any set $A$, we construct a set not in $A$.} + \end{center} + + \pause + \[ + \blue{B = \set{x \in A \mid x \notin x}} + \] + \pause + \vspace{-0.30cm} + \[ + B \in B \iff B \in A \land B \notin B + \] + + \pause + \[ + \red{\boxed{B \notin A}} + \] + + \pause + \vspace{-0.30cm} + \[ + B \in A \implies (B \in B \iff B \notin B) + \] + \end{proof} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +% \begin{frame}{} +% \begin{theorem}[Russell's Paradox] +% \[ +% \set{x \mid x \notin x} \text{ is \red{\it not} a set.} +% \] +% \end{theorem} +% +% \pause +% \[ +% B = \set{x \in A \mid x \notin x} +% \] +% \begin{center} +% does \red{\it not} lead to contradiction. +% \end{center} +% \end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{definition}[``$u \setminus v$'' \red{(Relative Complement)}] + \[ + u \setminus v \triangleq \set{x \in u \mid x \notin v}. + \] + \end{definition} + + \pause + \begin{theorem}[No ``Absolute Complement''] + For any set $B$, the following is \red{\it not} a set: + \[ + \set{x \mid x \notin B}. + \] + \end{theorem} + + \pause + \begin{proof} + \begin{center} + \red{By Contradiction.} + \end{center} + + \pause + \vspace{-0.50cm} + \[ + \set{x \mid x \notin B} \cup B \text{ would be a universal set}. + \] + \end{proof} + + \pause + \begin{quote} + We can never look for objects ``not in $B$'' \red{unless we know where to start looking}. + \hfill --- UD (Chapter 6; Page 64) + \end{quote} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{axiom}[Power Set Axiom] + For any set $A$, there is a set whose members are the subsets of $A$: + \[ + \forall A\; \red{\exists B}\; \forall x (x \in B \iff x \subseteq A). + \] + \end{axiom} + + \pause + \vspace{0.50cm} + \begin{definition}[``$\mathcal{P}(A)$''] + \[ + \mathcal{P}(A) \triangleq \text{ the \teal{unique} power set of } A. + \] + \end{definition} + + \pause + \vspace{0.50cm} + \begin{alertblock}{The is \red{\it not} correct!} + \[ + \mathcal{P}(A) \triangleq \set{x \mid x \subseteq A} + \] + \end{alertblock} +\end{frame} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/axioms.tex b/2021/2021-1/2021-1-8-set/parts/axioms.tex new file mode 100644 index 0000000..6f29aaa --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/axioms.tex @@ -0,0 +1,133 @@ +% axioms.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + {\Large Axiomatic Set Theory \blue{(ZFC)}} + \end{center} + + \vspace{0.80cm} + \begin{columns} + \column{0.45\textwidth} + \fig{width = 0.50\textwidth}{figs/Zermelo}{\centerline{Ernst \blue{Z}ermelo (1871--1953)}} + \column{0.45\textwidth} + \fig{width = 0.48\textwidth}{figs/Fraenkel}{\centerline{Abraham \blue{F}raenkel (1891--1965)}} + \end{columns} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +% \begin{frame}{} +% \begin{center} +% {\Large First-order Language} +% \end{center} +% +% \begin{columns} +% \column{0.30\textwidth} +% \column{0.40\textwidth} +% \begin{description}[Connectives:] +% \item[Parentheses:] $(,)$ +% \item[Variables:] $x, y, z, \cdots$ +% \item[Connectives:] $\land$, $\lor$, $\lnot$, $\to$, $\leftrightarrow$ +% \item[Quantifiers:] $\forall$, $\exists$ +% \item[Equality:] $=$ +% \pause \vspace{0.50cm} +% \item[Constants:] $a, b, c, \cdots$ +% \item[Functions:] $f, g, h, \cdots$ +% \item[Predicates:] $R, P, Q, \cdots$ +% \end{description} +% \column{0.30\textwidth} +% \end{columns} +% \end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + {\Large First-order Language for Sets \red{$\lset{} = \set{\in}$}} + \end{center} + + \begin{columns} + \column{0.30\textwidth} + \column{0.40\textwidth} + \begin{description}[Connectives:] + \item[Parentheses:] $(,)$ + \item[Variables:] \textcolor<2->{red}{$x, y, z, \cdots$} + \item[Connectives:] $\land$, $\lor$, $\lnot$, $\to$, $\leftrightarrow$ + \item[Quantifiers:] $\forall$, $\exists$ + \item[Equality:] $=$ + \vspace{0.50cm} + \item[Constants:] + \item[Functions:] + \item[Predicates:] \red{$\in$} + \end{description} + \column{0.30\textwidth} + \end{columns} + + \uncover<3->{ + \begin{center} + \red{\large Everything we consider in $\lset{}$ is a set.} + \end{center} + } +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + \red{$Q:$ What is \blue{``$\in$''}?} \\[10pt] + \red{$Q:$ What are \blue{``sets''}?} \\[40pt] + + \pause + We don't define them directly. \\[10pt] + We only describe their properties in an \red{axiomatic} way. + \end{center} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \fig{width = 0.30\textwidth}{figs/elements-ch} + + \begin{enumerate}[(1)] + \item To draw a straight line from any point to any point. + \item To extend a finite straight line continuously in a straight line. + \item To describe a circle with any center and radius. + \item That all right angles are equal to one another. + \item The parallel postulate. + \end{enumerate} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +% \begin{frame}{} +% \[ +% E, E; P, U, R, P; I, C; F +% \] +% \end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{definition}[$\notin$] + \[ + x \notin A \triangleq \lnot (x \in A). + \] + \end{definition} + + \pause + \vspace{0.50cm} + \begin{definition}[$\subseteq$] + \[ + A \subseteq B \triangleq \forall x (x \in A \implies x \in B) + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\input{parts/axioms-EE} +\input{parts/axioms-PURP} +% \input{parts/axioms-IC} +% \input{parts/axioms-F} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/conclusion.tex b/2021/2021-1/2021-1-8-set/parts/conclusion.tex new file mode 100644 index 0000000..0442309 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/conclusion.tex @@ -0,0 +1,9 @@ +% conclusion.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \centerline{\Large \textcolor{teal}{Video:}} + \vspace{0.20cm} + \centerline{\large \textcolor{teal}{\href{https://www.youtube.com/watch?v=HXuvEeecZtU}{Message To Future Generations --- Bertrand Russell}}} +\end{frame} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/operations-powerset.tex b/2021/2021-1/2021-1-8-set/parts/operations-powerset.tex new file mode 100644 index 0000000..ff1a82a --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/operations-powerset.tex @@ -0,0 +1,122 @@ +% operations-powerset.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + {\Large Set Operations (III)} + \end{center} + + \[ + \ps{X} + \] + + % \pause + % \[ + % 2^{X} = \set{0,1}^{X} + % \] + + % \fig{width = 0.50\textwidth}{figs/powerset-2-x-notation} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \[ + \red{\boxed{S \in \ps{X} \iff S \subseteq X}} + \] +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{exampleblock}{} + Prove that for any set $S$: + \[ + \set{\emptyset, \set{\emptyset}} \in \ps{\ps{\ps{S}}} + \] + \end{exampleblock} + + \begin{proof} + \pause + \[ + \set{\emptyset, \set{\emptyset}} \in \ps{\ps{\ps{S}}} \iff \set{\emptyset, \set{\emptyset}} \subseteq \ps{\ps{S}} + \] + + \pause + \hrule + \begin{columns} + \column{0.50\textwidth} + \[ + \red{\emptyset \in \ps{\ps{S}}} + \] + + \uncover<4->{ + \[ + \iff \emptyset \subseteq \ps{S} + \] + } + \column{0.50\textwidth} + \[ + \red{\set{\emptyset} \in \ps{\ps{S}}} + \] + + \uncover<5->{ + \[ + \iff \set{\emptyset} \subseteq \ps{S} + \] + } + \uncover<6->{ + \[ + \iff \emptyset \in \ps{S} + \] + } + \uncover<7->{ + \[ + \iff \emptyset \subseteq S + \] + } + \end{columns} + \end{proof} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{exampleblock}{UD Exercise $9.4$} + \[ + \ps{A} \cap \ps{B} = \ps{A \cap B} + \] + \end{exampleblock} + + \pause + \begin{proof} + \begin{align*} + \onslide<2->{&\textcolor{white}{\iff}\;\; x \in \ps{A} \cap \ps{B} \\} + \onslide<3->{&\iff x \in \ps{A} \land x \in \ps{B} \\} + \onslide<4->{&\iff x \subseteq A \land x \subseteq B \\} + \onslide<5->{&\iff x \subseteq A \cap B \\} + \onslide<6->{&\iff x \in \ps{A \cap B}} + \end{align*} + \end{proof} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{exampleblock}{UD Problem $9.9$} + \[ + \bigcap_{\alpha \in I} \ps{A_{\alpha}} = \ps{\bigcap_{\alpha \in I} A_{\alpha}} + \] + \end{exampleblock} + + \begin{proof} + \begin{align*} + \onslide<2->{&\textcolor{white}{\iff}\;\; x \in \bigcap_{\alpha \in I} \ps{A_{\alpha}} \\} + \onslide<3->{&\iff \forall \alpha \in I: x \in \ps{A_{\alpha}} \\} + \onslide<4->{&\iff \forall \alpha \in I: x \subseteq A_{\alpha} \\} + \onslide<5->{&\iff x \subseteq \bigcap_{\alpha \in I} A_{\alpha} \\} + \onslide<6->{&\iff x \in \ps{\bigcap_{\alpha \in I} A_{\alpha}}} + \end{align*} + \end{proof} +\end{frame} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/operations-set-family.tex b/2021/2021-1/2021-1-8-set/parts/operations-set-family.tex new file mode 100644 index 0000000..da3ab9f --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/operations-set-family.tex @@ -0,0 +1,76 @@ +% operations-set-family.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + {\Large Set Operations (II)} + % {\Large Set Family $\set{A_{\alpha}: \alpha \in I}$} + \end{center} + + \[ + \text{\Large $\bigcap \qquad \bigcup$} + \] +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \[ + \bigcup_{j = 1}^{n} A_j \triangleq A_1 \cup A_2 \cup \cdots \cup A_n \qquad + \bigcap_{j = 1}^{n} A_j \triangleq A_1 \cap A_2 \cap \cdots \cap A_n + \] + + \pause + \vspace{1.00cm} + \[ + \bigcup_{j = 1}^{\infty} A_j \triangleq A_1 \cup A_2 \cup \cdots \qquad + \bigcap_{j = 1}^{\infty} A_j \triangleq A_1 \cap A_2 \cap \cdots + \] + + \pause + \[ + \bigcup_{\alpha \in I} A_{\alpha} \triangleq \Big\{x \mid \red{\exists} \alpha \in I: x \in A_{\alpha}\Big\} \qquad + \bigcap_{\alpha \in I} A_{\alpha} \triangleq \Big\{x \mid \red{\forall} \alpha \in I: x \in A_{\alpha}\Big\} + \] +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[DeMorgan's Law (UD Exercise $8.9$)] + \[ + X \setminus \bigcup_{\alpha \in I} A_{\alpha} = \bigcap_{\alpha \in I} (X \setminus A_{\alpha}) + \] + + \[ + X \setminus \bigcap_{\alpha \in I} A_{\alpha} = \bigcup_{\alpha \in I} (X \setminus A_{\alpha}) + \] + \end{theorem} + + \pause + \fig{width = 0.35\textwidth}{figs/prove-it} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{exampleblock}{DeMorgan's Law (UD Problem $8.14$)} + \[ + A = \mathbb{R} \setminus \bigcap_{n \in \mathbb{Z}^{+}} (\mathbb{R} \setminus \set{-n, -n+1, \cdots, 0, \cdots, n-1, n}) + \] + \end{exampleblock} + + \pause + \[ + X_n = \set{-n, -n+1, \cdots, 0, \cdots, n-1, n} + \] + + \pause + \begin{align*} + \onslide<3->{A &= \mathbb{R} \setminus \bigcap_{n \in \mathbb{Z}^{+}} (\mathbb{R} \setminus X_n) \\} + \onslide<4->{&= \mathbb{R} \setminus \Big(\mathbb{R} \setminus \bigcup_{n \in \mathbb{Z}^{+}} X_n \Big) \\} + \onslide<5->{&= \mathbb{R} \setminus \Big(\mathbb{R} \setminus \mathbb{Z} \Big) \\} + \onslide<6->{&= \mathbb{Z}} + \end{align*} +\end{frame} +%%%%%%%%%%%%%%% \ No newline at end of file diff --git a/2021/2021-1/2021-1-8-set/parts/operations-simple.tex b/2021/2021-1/2021-1-8-set/parts/operations-simple.tex new file mode 100644 index 0000000..44971dd --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/operations-simple.tex @@ -0,0 +1,62 @@ +% operations-simple.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \centerline{\Large Set Operations (I)} + + \[ + \text{\Large $\cap \qquad \cup \qquad \setminus$} + \] +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \fig{width = 0.65\textwidth}{figs/ud-set-op-laws} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[Distributive Property (Theorem $7.4\; (13)$)] + \[ + A \cup (B \cap C) = (A \cup B) \cap (A \cup C) + \] + \end{theorem} + + \begin{columns} + \column{0.50\textwidth} + \pause + \fig{width = 0.90\textwidth}{figs/distributive-proof} + \column{0.50\textwidth} + \pause + \fig{width = 0.80\textwidth}{figs/kiss} + \end{columns} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[DeMorgan's Law (Theorem $7.4\; (15)$)] + Let $X$ denote a set, and $A, B \subseteq X$. + + \[ + X \setminus (A \cup B) = (X \setminus A) \cap (X \setminus B) + \] + \end{theorem} + + \pause + \vspace{0.50cm} + \[ + \red{Q: A, B \subseteq X?} + \] + + \begin{theorem}[DeMorgan's Law] + Let $A, B, C$ be three sets. + + \[ + C \setminus (A \cup B) = (C \setminus A) \cap (C \setminus B) + \] + \end{theorem} +\end{frame} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/operations.tex b/2021/2021-1/2021-1-8-set/parts/operations.tex new file mode 100644 index 0000000..1388757 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/operations.tex @@ -0,0 +1,7 @@ +% operations.tex + +%%%%%%%%%%%%%%% +\input{parts/operations-simple} +\input{parts/operations-set-family} +\input{parts/operations-powerset} +%%%%%%%%%%%%%%% diff --git a/2021/2021-1/2021-1-8-set/parts/overview.tex b/2021/2021-1/2021-1-8-set/parts/overview.tex new file mode 100644 index 0000000..996cfe1 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/parts/overview.tex @@ -0,0 +1,131 @@ +% overview.tex + +%%%%%%%%%%%%%%% +\begin{frame}{} + \fig{width = 0.85\textwidth}{figs/set-theory-aspects} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{columns} + \column{0.45\textwidth} + \fig{width = 0.50\textwidth}{figs/Frege-old}{\centerline{Gottlob Frege (1848--1925)}} + \begin{center} + ``现代逻辑之父'' + \end{center} + \column{0.45\textwidth} + \fig{width = 0.40\textwidth}{figs/frege-arithmetic} + \begin{center} + {``Basic Laws of Arithmetic'' \\ (1893 \& 1903)} + \end{center} + \end{columns} + + \pause + \vspace{0.80cm} + \begin{quote} + 对于一个科学工作者来说,最不幸的事情莫过于: + 当他的工作接近完成时, 却发现那大厦的基础已经动摇。 + + \hfill --- 《附录二》, 1902 + \end{quote} +\end{frame} +%%%%%%%%%%%%%%% + +% \begin{quote} +% 就正直与风度而言,我认为在我所知的范围内, +% 无人可超越 Frege 对于真理的献身精神。 +% \end{quote} + +%%%%%%%%%%%%%%% +\begin{frame}{} + \fig{width = 0.20\textwidth}{figs/Russell}{\vspace{-0.30cm}\centerline{Bertrand Russell (1872--1970)}} + + \begin{columns} + \pause + \column{0.30\textwidth} + \fig{width = 0.60\textwidth}{figs/russell-philosophy} + \pause + \column{0.30\textwidth} + \fig{width = 0.60\textwidth}{figs/russell-pm} + \pause + \column{0.30\textwidth} + \fig{width = 0.80\textwidth}{figs/russell-nobel} + \end{columns} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{quote} + 我们将集合理解为 + 任何将我们思想中那些确定而彼此独立的对象放在一起而形成的聚合。 + + \hfill --- Georg Cantor《超穷数理论基础》 + \end{quote} + + \fig{width = 0.15\textwidth}{figs/cantor}{\centerline{Georg Cantor (1845--1918)}} + + \pause + \begin{theorem}[概括原则] + \blue{For any predicate $\psi(x)$}, there is a \red{set} $X$: + \[ + X = \set{x \mid \psi(x)} + \] + \end{theorem} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{theorem}[概括原则] + \blue{For any predicate $\psi(x)$}, there is a \red{set} $X$: + \[ + X = \set{x \mid \psi(x)}. + \] + \end{theorem} + + \pause + \begin{definition}[Russell's Paradox] + \[ + \blue{\psi(x) \triangleq ``x \notin x"} + \] + + \pause + \[ + R = \set{x \mid x \notin x} + \] + + \pause + \[ + \red{Q: R \in R\;?} + \] + \end{definition} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + \red{$Q:$ } 既然朴素集合论存在悖论,你是如何做作业的? + \vspace{0.60cm} + \fig{width = 0.20\textwidth}{figs/cannot-see} + \end{center} +\end{frame} +%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%% +\begin{frame}{} + \begin{center} + \fig{width = 0.40\textwidth}{figs/have-to-fix-it} + + \pause + \vspace{0.20cm} + \begin{theorem}[Russell's Paradox] + \[ + \set{x \mid x \notin x} \text{ is \red{\it not} a set.} + \] + \end{theorem} + \end{center} +\end{frame} +%%%%%%%%%%%%%%% \ No newline at end of file diff --git a/2021/2021-1/2021-1-8-set/preamble.tex b/2021/2021-1/2021-1-8-set/preamble.tex new file mode 100644 index 0000000..7939775 --- /dev/null +++ b/2021/2021-1/2021-1-8-set/preamble.tex @@ -0,0 +1,80 @@ +% preamble.tex + +\usepackage{lmodern} + +\usepackage{xeCJK} +\usetheme{CambridgeUS} % try Madrid, Pittsburgh +\usecolortheme{beaver} +\usefonttheme[]{serif} % try "professionalfonts" + +\setbeamertemplate{itemize items}[default] +\setbeamertemplate{enumerate items}[default] + +\usepackage{amsmath, amsfonts, latexsym, mathtools} +\newcommand{\set}[1]{\{#1\}} +\DeclareMathOperator*{\argmin}{\arg\!\min} + +\definecolor{bgcolor}{rgb}{0.95,0.95,0.92} + +\usepackage{listings} +\lstdefinestyle{CStyle}{ + language = C, + basicstyle = \ttfamily\bfseries, + backgroundcolor = \color{bgcolor}, + keywordstyle = \color{blue}, + stringstyle = \color{red}, + commentstyle = \color{cyan}, + breakatwhitespace = false, + breaklines = true, + mathescape = true, + escapeinside = ||, + morekeywords = {repeat, until}, + showspaces = false, + showstringspaces = false, + showtabs = false, +} + +% colors +\newcommand{\red}[1]{\textcolor{red}{#1}} +\newcommand{\redoverlay}[2]{\textcolor<#2>{red}{#1}} +\newcommand{\green}[1]{\textcolor{green}{#1}} +\newcommand{\blue}[1]{\textcolor{blue}{#1}} +\newcommand{\blueoverlay}[2]{\textcolor<#2>{blue}{#1}} +\newcommand{\teal}[1]{\textcolor{teal}{#1}} +\newcommand{\purple}[1]{\textcolor{purple}{#1}} + +% colorded box +\newcommand{\rbox}[1]{\red{\boxed{#1}}} +\newcommand{\gbox}[1]{\green{\boxed{#1}}} +\newcommand{\bbox}[1]{\blue{\boxed{#1}}} +\newcommand{\pbox}[1]{\purple{\boxed{#1}}} + +\usepackage{pifont} +\usepackage{wasysym} + +\newcommand{\cmark}{\green{\ding{51}}} +\newcommand{\xmark}{\red{\ding{55}}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% for fig without caption: #1: width/size; #2: fig file +\newcommand{\fig}[2]{ + \begin{figure}[htp] + \centering + \includegraphics[#1]{#2} + \end{figure} +} + +\newcommand{\titletext}{1-8 Set Theory: Axioms and Operations} + +\newcommand{\lset}{\mathcal{L}_{\textsl{Set}}} +\newcommand{\ps}[1]{\mathcal{P}(#1)} +\newtheorem{axiom}{Axiom} + +\newcommand{\thankyou}{ +\begin{frame}[noframenumbering]{} + \fig{width = 0.50\textwidth}{figs/thankyou.png} + \centering + Thank + Hengfeng Wei (hfwei@nju.edu.cn) + for the slides. +\end{frame} +} \ No newline at end of file diff --git a/commonres/figs/ICS_LOGO_left.png b/commonres/figs/ICS_LOGO_left.png new file mode 100644 index 0000000..c918a3d Binary files /dev/null and b/commonres/figs/ICS_LOGO_left.png differ diff --git a/mj_preamble_lecturenote.tex b/mj_preamble_lecturenote.tex new file mode 100644 index 0000000..c338c60 --- /dev/null +++ b/mj_preamble_lecturenote.tex @@ -0,0 +1,144 @@ +%for hyper link +%\usepackage[colorlinks, linkcolor=blue]{hyperref} + +\usepackage[utf8]{inputenc} + + +\usepackage{latexsym} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage[english]{babel} +\usepackage{amsmath} +\usepackage{amsfonts} +\usepackage{amssymb} + + + + +%for graphs and pics +\usepackage{graphicx} +\usepackage{tikz} +\usetikzlibrary{matrix,shapes,arrows,positioning,fit,backgrounds,calc} +\usepackage{overpic} +%for animation +\usepackage[dvipdfmx]{animate} + + +%boxes +\usepackage[normalem]{ulem} +\usepackage[most]{tcolorbox} +\usepackage{fancybox} + +\usepackage{bbding} +\usepackage{pifont} + +%for tables +\usepackage{booktabs} +%for algorithms +\makeatletter +\newif\if@restonecol +\makeatother +\let\algorithm\relax +\let\endalgorithm\relax +\usepackage[linesnumbered,ruled,noend,noline]{algorithm2e} +\usepackage{algpseudocode} +\usepackage{amsmath} +\renewcommand{\algorithmicrequire}{\textbf{Input:}} % Use Input in the format of Algorithm +\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the +\SetAlCapNameFnt{\scriptsize} +\SetAlCapFnt{\scriptsize} + +% for Chinese +\usepackage{CJK} +\usepackage{zhnumber} + + + +%for codes +\usepackage{listings} +\lstset{% + alsolanguage=Java, + %language={[ISO]C++}, %language为,还有{[Visual]C++} + %alsolanguage=[ANSI]C, %可以添加很多个alsolanguage,如alsolanguage=matlab,alsolanguage=VHDL等 + %alsolanguage= tcl, + alsolanguage= XML, + tabsize=4, % + frame=shadowbox, %把代码用带有阴影的框圈起来 + commentstyle=\color{red!50!green!50!blue!50},%浅灰色的注释 + rulesepcolor=\color{red!20!green!20!blue!20},%代码块边框为淡青色 + keywordstyle=\color{blue!90}\bfseries, %代码关键字的颜色为蓝色,粗体 + showstringspaces=false,%不显示代码字符串中间的空格标记 + stringstyle=\ttfamily, % 代码字符串的特殊格式 + keepspaces=true, % + breakindent=22pt, % + numbers=left,%左侧显示行号 往左靠,还可以为right,或none,即不加行号 + stepnumber=1,%若设置为2,则显示行号为1,3,5,即stepnumber为公差,默认stepnumber=1 + %numberstyle=\tiny, %行号字体用小号 + numberstyle={\color[RGB]{0,192,192}\tiny} ,%设置行号的大小,大小有tiny,scriptsize,footnotesize,small,normalsize,large等 + numbersep=8pt, %设置行号与代码的距离,默认是5pt + basicstyle=\footnotesize, % 这句设置代码的大小 + showspaces=false, % + flexiblecolumns=true, % + breaklines=true, %对过长的代码自动换行 + breakautoindent=true,% + breakindent=4em, % + escapebegin=\begin{CJK*}{GBK}{hei},escapeend=\end{CJK*}, + aboveskip=1em, %代码块边框 + tabsize=2, + showstringspaces=false, %不显示字符串中的空格 + backgroundcolor=\color[RGB]{245,245,244}, %代码背景色 + %backgroundcolor=\color[rgb]{0.91,0.91,0.91} %添加背景色 + escapeinside=``, %在``里显示中文 + %% added by http://bbs.ctex.org/viewthread.php?tid=53451 + fontadjust, + captionpos=t, + framextopmargin=2pt,framexbottommargin=2pt,abovecaptionskip=-3pt,belowcaptionskip=3pt, + xleftmargin=4em,xrightmargin=4em, % 设定listing左右的空白 + texcl=true, + % 设定中文冲突,断行,列模式,数学环境输入,listing数字的样式 + extendedchars=false,columns=flexible,mathescape=true + % numbersep=-1em +} + +\lstdefinestyle{styleJ}{ + language=[AspectJ]Java, + keywordstyle=\color{keywordcolor}\bfseries, + commentstyle=\color{blue} \textit, + showstringspaces=false, + numbers=left, + numberstyle=\small +} +\lstdefinestyle{styleP}{ + language=Python, + numbers=right, + frame=single, + numberstyle=\small , +} +\usetikzlibrary{decorations.pathreplacing} +\usetheme{Eastlansing} +\newcommand{\fallingfactorial}[1]{% + ^{\underline{#1}}% +} +\newcommand{\cmark}{\ding{51}} +\newcommand{\xmark}{\ding{55}} +\newcommand{\question}[2]{ + {\color{blue!60!black!90!}\large\textbf{Q #1}: #2} +} + +%for colors + +\usepackage{color,xcolor} +% predefined colors +\newcommand{\red}[1]{\textcolor{red}{#1}} % usage: \red{text} +\newcommand{\blue}[1]{\textcolor{blue}{#1}} +\newcommand{\teal}[1]{\textcolor{teal}{#1}} +\newcommand{\green}[1]{\textcolor{green}{#1}} +\definecolor{keywordcolor}{rgb}{0.1,0.1,0.8} +\definecolor{webgreen}{rgb}{0,.5,0} +\definecolor{bgcolor}{rgb}{0.92,0.92,0.92} + +%for arrows +\usepackage{extarrows} + +%for math function font +\usefonttheme[onlymath]{serif} \ No newline at end of file