
diff -r 1796e8ba2c1e -r a20bf59d1775 tex/theory1_ex6.tex
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tex/theory1_ex6.tex	Sun Jun 26 19:46:12 2011 +0200
@@ -0,0 +1,75 @@
+\documentclass[a4paper, 10pt, pagesize, smallheadings]{article}  
+\usepackage{graphicx}
+%\usepackage[latin1]{inputenc}
+\usepackage{amsmath, amsthm, amssymb}
+\usepackage{typearea}
+\usepackage{algorithm}
+\usepackage{algorithmic}
+\usepackage{fullpage}
+\usepackage{mathtools}
+\usepackage[all]{xy}
+\title{Theory I, Sheet 6 Solution}
+\author{Eugen Sawin}
+\renewcommand{\familydefault}{\sfdefault}
+\include{pythonlisting}
+
+\pagestyle{empty}
+\begin{document}
+\maketitle
+
+\section*{Exercise 6.1}
+\[\Phi(T) = |2 \cdot num - size|\]
+\[a_i = \Phi_i - \Phi_{i-1} + t_i\]
+\[a_i = |2k_i - s_i| - |2k_{i-1} - s_{i-1}| + t_i\]
+We calculate the amortized costs for the two distinct cases.
+
+\subsection*{case 1 (no contraction required)}
+Since there was no contraction we know that $s_i = s_{i-1}$ and it follows that $\frac{1}{3}s_i \leq k_i \leq s_i - 1$. Since we have deleted an element we know that $k_i = k_{i-1} - 1$. Because we have only removed an element it follows that $t_i = 1$. We reduce the formula using these substitutions.
+\[a_i = |2k_i - s_i| - |2k_{i-1} - s_{i-1}| + t_i\]
+\[= |2k_i - s_i| - |2k_i + 2 - s_i| + 1\]
+Now we look for the minimum and maximum value of the above formula. We choose the obvious values for $k_i$ which are within valid range.
+\[(k_i = \frac{s_i}{2}) \implies a_i = |s_i - s_i| - |s_i - s_i + 2| + 1\]
+\[= 0 - 2 + 1 = -1\]
+
+\[(k_i = \frac{s_i}{2} - 1) \implies a_i = |s_i - 2 - s_i| - |s_i - 2 - s_i + 2| + 1\]
+\[= 2 - 0 + 1 = 3\]
+
+\[\implies -1 \leq a_i \leq 3\]
+\subsection*{case 2 (contraction required)}
+Since there was a contraction we know that $s_i = \frac{2}{3}s_{i-1}$ and it follows that $k_i = \frac{1}{3}s_{i-1} - 1$. Since we have deleted an element we know that $k_i = k_{i-1} - 1$. Because we have removed an element and additionally copied all previously contained elements it follows that $t_i = \frac{1}{3}s_{i-1} + 1$. We reduce the formula again using these substitutions.
+\[a_i = |2k_i - s_i| - |2k_{i-1} - s_{i-1}| + t_i\]
+\[= |2k_i - \frac{2}{3}s_{i-1}| - |2k_i + 2 - s_{i-1}| + t_i\]
+\[= |\frac{2}{3}s_{i-1} - 2 - \frac{2}{3}s_{i-1}| - |\frac{2}{3}s_{i-1} - 2 + 2 - s_{i-1}| + \frac{1}{3}s_{i-1} + 1\]
+\[= |-2| - |-\frac{1}{3}s_{i-1}| + \frac{1}{3}s_{i-1} + 1\]
+\[(\text{since } s_{i-1} > 0) \implies a_i = 2 - \frac{1}{3}s_{i-1} + \frac{1}{3}s_{i-1} + 1\]
+\[= 2 + 1 = 3 \leq 3\]
+By calculating the amortized costs for both Table-Delete cases, we have have shown that the amortized costs are bounded by constant 3. \qed
+
+\section*{Exercise 6.2}
+\[\alpha = \frac{k}{s}\]
+\[\Phi(T) = 
+\left\{ 
+\begin{array}{l l} 
+  2k-s & \text{if $\alpha \geq \frac{1}{2}$}\\
+  \frac{s}{2}-k & \text{if $\alpha < \frac{1}{2}$}\\
+\end{array} \right.\]
+
+We show $\sum a_i \geq \sum t_i$.
+\[a_i = \Phi_i - \Phi_{i-1} + t_i\]
+\[\implies \sum_{i=1}^{n}a_i = \sum_{i=1}^{n}\Phi_i - \Phi_{i-1} + t_i\]
+\[= \sum_{i=1}^{n}\Phi_i - \sum_{i=0}^{n-1}\Phi_i + \sum_{i=1}^{n}t_i\]
+\[= \Phi_n - \Phi_0 + \sum_{i=1}^{n}t_i\]
+
+By definition we know that $\Phi_0 = -1$ and since $2k-s \geq 0$ for $\alpha \geq \frac{1}{2}$ and $\frac{s}{2}-k \geq 0$ for $\alpha < \frac{1}{2}$ it follows that $\Phi_n - \Phi_0 >= 0$.
+\[\implies \Phi_n - \Phi_0 + \sum_{i=1}^{n}t_i \geq \sum t_i\]\qed
+
+\section*{Exercise 6.3}
+We show
+\[\sum_{k=2}^{n-1}k\,lg\,k \leq \frac{1}{2}n^2\,lg\,n - \frac{1}{8}n^2\]
+\[\sum_{k=2}^{n-1}k\,lg\,k = \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k\,lg\,k\ + \sum_{k=\lceil \frac{n}{2} \rceil}^{n-1}k\,lg\,k\]
+\[\leq \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k\,lg\,\lceil \frac{n}{2} \rceil + \sum_{k=\lceil \frac{n}{2} \rceil}^{n-1}k\,lg\,n\]
+\[= lg\,\lceil \frac{n}{2} \rceil \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k + lg\,n \sum_{k=\lceil \frac{n}{2} \rceil}^{n-1}k\]
+\[= (lg\,n - lg\,2) \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k + lg\,n \sum_{k=\lceil \frac{n}{2} \rceil}^{n-1}k\]
+\[= lg\,n \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k - \sum_{k=2}^{\lceil \frac{n}{2} \rceil - 1}k + lg\,n \sum_{k=\lceil \frac{n}{2} \rceil}^{n-1}k\]
+\[= lg\,n \frac{(n-1)(n-2)}{2} - \]
+\end{document}




