npueyo_hw1.tex 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. % Short Sectioned Assignment
  3. % LaTeX Template
  4. % Version 1.0 (5/5/12)
  5. %
  6. % This template has been downloaded from:
  7. % http://www.LaTeXTemplates.com
  8. %
  9. % Original author:
  10. % Frits Wenneker (http://www.howtotex.com)
  11. %
  12. % License:
  13. % CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
  14. %
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. %----------------------------------------------------------------------------------------
  17. % PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
  18. %----------------------------------------------------------------------------------------
  19. \documentclass[paper=a4, fontsize=11pt]{scrartcl} % A4 paper and 11pt font size
  20. \usepackage[colorlinks=true, allcolors=red]{hyperref}
  21. \usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
  22. %\usepackage{fourier} % Use the Adobe Utopia font for the document - comment this line to return to the LaTeX default
  23. \usepackage[english]{babel} % English language/hyphenation
  24. \usepackage{mathtools} % More complete math support in Latex than amsthm
  25. \usepackage{amsmath,amsfonts,amsthm} % Math packages
  26. \usepackage{amssymb} % Additional math symbols.
  27. \usepackage{graphicx} % Graphics with e.g. \includegraphics{file.png}.
  28. %\usepackage{subfigures} % Have multiple figures in one.
  29. \usepackage{caption} % Customize caption formatting.
  30. \usepackage{subcaption} % Subfigures.
  31. \usepackage{tabularx} % Width controlled tabulars.
  32. \usepackage{sectsty} % Allows customizing section commands
  33. \allsectionsfont{\centering \normalfont\scshape} % Make all sections centered, the default font and small caps
  34. \usepackage{tikz}
  35. \usetikzlibrary{automata,positioning}
  36. \usepackage{fancyhdr} % Custom headers and footers
  37. \pagestyle{fancyplain} % Makes all pages in the document conform to the custom headers and footers
  38. \fancyhead{} % No page header - if you want one, create it in the same way as the footers below
  39. \fancyfoot[L]{} % Empty left footer
  40. \fancyfoot[C]{} % Empty center footer
  41. \fancyfoot[R]{\thepage} % Page numbering for right footer
  42. \renewcommand{\headrulewidth}{0pt} % Remove header underlines
  43. \renewcommand{\footrulewidth}{0pt} % Remove footer underlines
  44. \setlength{\headheight}{13.6pt} % Customize the height of the header
  45. \numberwithin{equation}{section} % Number equations within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
  46. \numberwithin{figure}{section} % Number figures within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
  47. \numberwithin{table}{section} % Number tables within sections (i.e. 1.1, 1.2, 2.1, 2.2 instead of 1, 2, 3, 4)
  48. \setlength\parindent{0pt} % Removes all indentation from paragraphs - comment this line for an assignment with lots of text
  49. %\usepackage{mathtools}
  50. %\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
  51. %\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
  52. \newcommand{\heads}{\textsc{h}}
  53. \newcommand{\tails}{\textsc{t}}
  54. \newcommand{\logten}{\log} %\mathrm{log}\hspace{0.05in}}
  55. \newcommand{\logtwo}{\lg} %\mathrm{lg}\hspace{0.05in}}
  56. \newcommand{\loge}{\ln} %\mathrm{ln}\hspace{0.05in}}
  57. \theoremstyle{definition}
  58. \newtheorem*{solution}{Solution}
  59. \usepackage{algpseudocode, algorithm}
  60. %----------------------------------------------------------------------------------------
  61. % TITLE SECTION
  62. %----------------------------------------------------------------------------------------
  63. \newcommand{\horrule}[1]{\rule{\linewidth}{#1}} % Create horizontal rule command with 1 argument of height
  64. \title{
  65. \normalfont \normalsize
  66. \textsc{ECS60 \hfill Dept. of Computer Science, University of California, Davis} % Your university, school and/or department name(s)
  67. \horrule{0.5pt} \\[0.4cm] % Thin top horizontal rule
  68. \huge Homework \#1 \\ % The assignment title
  69. \horrule{2pt} \\[0.5cm] % Thick bottom horizontal rule
  70. }
  71. \author{Natalie Pueyo Svoboda, 997466498} % Put your name here
  72. \date{\today}
  73. \begin{document}
  74. \maketitle
  75. %Classmate collaborator(s): If you collaborated with fellow students, you \emph{must} list them here.
  76. \section{First Problem}
  77. \begin{solution}
  78. To prove that $f(n)=\mathcal{O}(n^2)$, if $f(n)=3n^2+2n+4$, I have to prove that there are constants $c$ and $M$ such that $\forall n \geq M$, $f(n) \leq c \cdotp g(n)$, where $g(n)=n^2$.
  79. In other words, there is a constant, $c$ that when multiplied $g(n)$, will allow $g(n)$ to always overtake $f(n)$ $\forall n \geq M$.
  80. In this case, $f(n)=3n^2+2n+4 \leq c \cdotp n^2$.
  81. To make the proof easier, I chose $M=1$ such that $n \geq 1$.
  82. I can then use this definition to find a term greater than each term in $f(n)$ so that $f(n)=3n^2+2n+4 \leq c \cdotp n^2$.
  83. The resulting terms have to deal with the constants in $f(n)$.
  84. Because $n$ was defined such that $n \geq 1$, we can then multiply both sides by $n$ to show that $n^2 \geq n$ resulting in
  85. \begin{equation*}
  86. n^2 \geq n \geq 1
  87. \end{equation*}
  88. by multiplying each term in the inequality by the constant we want to remove, we can show that:
  89. \begin{equation*}
  90. 2n^2 \geq 2n \geq 2
  91. \end{equation*}
  92. and
  93. \begin{equation*}
  94. 4n^2 \geq 4n \geq 4
  95. \end{equation*}
  96. which takes care of the $2n$ and $4$ constants respectivelly.
  97. To find a value greater than $f(n)$'s first term, we use the definition of the $\geq$ operator: $3n^2 \geq 3n^2$ by definition.
  98. This leads to the following inequality:
  99. \begin{equation*}
  100. 3n^2+2n+4 \leq 3n^2+2n^2+4n^2
  101. \end{equation*}
  102. Each term on the right is greater than or equal to its corresponding term on the left which makes the sum of all the right terms greater than $f(n)$.
  103. \begin{equation*}
  104. 3n^2+2n+4 \leq 9n^2
  105. \end{equation*}
  106. This means that if $g(n)$ is multiplied by the constant $c=9$, after $n \leq M$, where $M=1$, $f(n) \leq c \cdotp g(n)$ proving that $f(n)=\mathcal{O}(n^2)$.
  107. % https://math.stackexchange.com/questions/437098/big-o-notation-prove-that-n2-2n-3-is-mathcal-on2
  108. % by AleksandrH
  109. % and use definition on hw page
  110. \end{solution}
  111. \section{Second Problem}
  112. \begin{solution}
  113. If $f(n)=log(n)$ and $f(n)=\mathcal{O}(g(n))$ it can be proven that $g(n)=n$ if $lim_{n \rightarrow \infty} \frac{log(n)}{n} = c$ for some constant $c \geq 0$.
  114. Using L'Hopital's rule \[lim_{n \rightarrow \infty} \frac{f(n)}{g(n)}=\frac{f'(n)}{g'(n)}\] such that
  115. \begin{equation*}
  116. \begin{split}
  117. lim_{n \rightarrow \infty} \frac{log(n)}{n} & = lim_{n \rightarrow \infty} \frac{f'(n)}{g'(n)} = c\\
  118. & = lim_{n \rightarrow \infty} \frac{1}{n} \cdotp \frac{1}{1} = c\\
  119. & = lim_{n \rightarrow \infty} \frac{1}{n} = c\\
  120. & = 0 = c
  121. \end{split}
  122. \end{equation*}
  123. Which satisfies the condition that $c \geq 0$ proving that $log(n)=\mathcal{O}(n)$.
  124. This proof was done with the assumption that $log(n)$ was $ln(n)$.
  125. However, it is also true for other bases because the addition of a base just adds a constant which is ignored in Big-O notation.
  126. This can also be used to prove that $n^k log(n) = \mathcal{O}(n^{k+1})$ for any constant $k$.
  127. \begin{equation*}
  128. \begin{split}
  129. lim_{n \rightarrow \infty} \frac{n^k log(n)}{n^{k+1}} & = lim_{n \rightarrow \infty} \frac{f'(n)}{g'(n)} = c\\
  130. & = lim_{n \rightarrow \infty} \frac{n^{k-1} (k \cdotp log(n) + 1}{(k+1)n^k} = c\\
  131. & = lim_{n \rightarrow \infty} \frac{k \cdotp log(n) + 1}{n(k+1)} = c\\
  132. & = \frac{1}{k+1} lim_{n \rightarrow \infty} \frac{k \cdotp log(n) + 1}{n} = c\\
  133. & = lim_{n \rightarrow \infty} \frac{f'(n)}{g'(n)}\\
  134. & = \frac{1}{k+1} lim_{n \rightarrow \infty} \frac{k}{n} \cdotp \frac{1}{1} = c\\
  135. & = \frac{k}{k+1} lim_{n \rightarrow \infty} \frac{1}{n} = c\\
  136. & = \frac{k}{k+1} \cdotp 0 = 0 = c
  137. \end{split}
  138. \end{equation*}
  139. This also satisfies the condition that $c \geq 0$ proving that $n^k log(n) = \mathcal{O}(n^{k+1})$.
  140. For this second proof it was necessary to use L'Hopital's Rule a second time to make the proof possible.
  141. \end{solution}
  142. \section{Third Problem}
  143. \begin{solution}
  144. The logarithmic identity to change the base of a logarithm is \[log_a x = \frac{log_b x}{log_b a}\]
  145. Using this identity we can prove that if we have two constants $a$ and $b$, and $f(n)=log_a n$, then $log_a n = \mathcal{O}(log_b n)$ and that $log_b n = \mathcal{O}(log_a n)$.
  146. By using the identity we can show that \[log_a n = \mathcal{O} \left(\frac{log_b n}{log_b a}\right)\] and since $log_b a$ is a constant it gets discarded from the Big-O notation.
  147. This results in \[log_a n = \mathcal{O}(log_b n)\]
  148. The same excercise can be done for $f(n)=log_b n$ where \[log_b n = \mathcal{O}\left(\frac{log_a n}{log_a b}\right)\] where again we discard the constant $log_a b$ resulting in \[log_b n = \mathcal{O}(log_a n)\]
  149. \end{solution}
  150. \section{Fourth Problem}
  151. \begin{solution}
  152. If we imply that $f_i=\mathcal{O}(f_{i+1})$ for all $1 \leq i \leq 5$
  153. \begin{center}
  154. \begin{tabular}{l | l}
  155. $f(n)$ & $\mathcal{O}(g(n))$ \\ \hline
  156. $n^3+2n+1$ & $\mathcal{O}(n^3)$ \\
  157. $n log(n^2)$ & $\mathcal{O}(n \cdotp log(n^2))$ \\
  158. $n^2 log(n)$ & $\mathcal{O}(n^2 log(n))$ \\
  159. $2^n$ & $\mathcal{O}(2^n)$ \\
  160. $3^n$ & $\mathcal{O}(3^n)$ \\
  161. $1023n^2+2n+45$ & $\mathcal{O}(n^2)$ \\
  162. \end{tabular}
  163. \end{center}
  164. The $\mathcal{O}(g(n))$ of each given formula was plotted in R to determine which ones grew faster asymptotically.
  165. This would make it easy to rank them such that $f_i=\mathcal{O}(f_{i+1})$ for all $1 \leq i \leq 6$.
  166. Figure~\ref{fig:growth}.1 shows how all 6 equations act as $n$ grows larger.
  167. \begin{figure*}[ht]
  168. \centering
  169. \begin{subfigure}[t]{0.5\textwidth}
  170. \centering
  171. \includegraphics[height=2.5in]{big-o_graphs_closup.jpeg}
  172. \caption{$g(n)$ plots when $n=80$}
  173. \end{subfigure}%
  174. ~
  175. \begin{subfigure}[t]{0.5\textwidth}
  176. \centering
  177. \includegraphics[height=2.5in]{big-o_graphs.jpeg}
  178. \caption{$g(n)$ plots when $n=1000$}
  179. \end{subfigure}
  180. \caption{Plots of $\mathcal{O}(g(n))$ for the various $f(n)$ equations as $n$ grows larger}
  181. \end{figure*}
  182. \label{fig:growth}
  183. % I wonder if I have to justify it? Worry later
  184. \end{solution}
  185. With the plots the equations can be ranked according to the speed of their growth as:
  186. \[n \cdotp log(n^2), n^2, n^2 \cdotp log(n), n^3, 2^n, 3^n\]
  187. Making $f_1=n \cdotp log(n^2)$, $f_2=1023n^2+2n+45$, $f_3=n^2 \cdotp log(n)$, $f_4=n^3+2n+1$, $f_5=2^n$, and $f_6=3^n$.
  188. \section{Fifth Problem}
  189. \begin{solution}
  190. To get the Big-O of a sum, one has to first find the resulting formula of the sum.
  191. The sum's for this problem is: $\sum_{i=0}^n i$ which expanded gives:
  192. \[S = \sum_{i=0}^n i = 1 + 2 + \ldots + (n-1) + n\]
  193. To solve for the formula,
  194. \begin{equation*}
  195. \begin{split}
  196. 2 \cdotp S = 2 \cdotp \sum_{i=0}^n i & = (1 + 2 + \ldots + (n-1) + n) + (1 + 2 + \ldots + (n-1) + n)\\
  197. & = (1 + 2 + \ldots + (n-1) + n) + (n + (n-1) + \ldots + 2 + 1)\\
  198. & = [1+n] + [2+(n-1)] + ... + [(n-1) + 2] + [n + 1]\\
  199. & = n \cdotp (n+1)
  200. \end{split}
  201. \end{equation*}
  202. When solving for $S$, the result is $S = \sum_{i=0}^n i = \frac{n \cdotp (n+1)}{2}$.
  203. This can then be used to prove that $\sum_{i=0}^n i =\mathcal{O}(n^2)$ because the dominant term of $\frac{n \cdotp (n+1)}{2}$ is $n^2$ from simplifying $S$ to $\frac{1}{2}(n^2+n)$.
  204. \end{solution}
  205. \section{Sixth Problem}
  206. \begin{solution}
  207. For any positive integer $n$ and assuming that $\sum_{i=0}^n 3^i \leq 3^{n+1}$,
  208. \begin{enumerate}
  209. \item Base step: $\sum_{i=0}^0 3^i = 3^0 \leq 3^{0+1} = 3^1$ is true.
  210. \item Inductive step: assuming $\sum_{i=0}^{n+1} 3^i = \sum_{i=0}^n 3^i + 3^{n+1}$
  211. \end{enumerate}
  212. \begin{equation*}
  213. \begin{split}
  214. \sum_{i=0}^n 3^i + 3^{n+1} & \leq 3^{n+1} + 3^{n+1}\\
  215. & \leq 2 \cdotp 3^{n+1}\\
  216. & \leq 3^{(n+1)+1}
  217. \end{split}
  218. \end{equation*}
  219. so the inductive step holds true as well, so by induction $\sum_{i=0}^n 3^i \leq 3^{n+1}$ for any positive integer $n$.
  220. % induction stuff https://www.math.ku.edu/~jhart/Induction_Sum.pdf
  221. % https://math.stackexchange.com/questions/734934/prove-by-induction-sum-i-0n-3i-frac-3n1-12
  222. \end{solution}
  223. \end{document}