today's slides

pull/2/head
Oliver Kennedy 2022-09-19 10:04:30 -04:00
parent d4dc6d813a
commit f231b852a1
Signed by: okennedy
GPG Key ID: 3E5F9B3ABD3FDB60
2 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,10 @@ date: Sept 7 and 12, 2022
textbook: "Ch. 7.3-7.4"
---
<!--
2022 by OK: It would be worth adding a slide on what it means for bounds to be "tight"
-->
<section>
<h4 class="slide_title">When is an algorithm "fast"?</h4>
<ul style="font-size: 80%">

View File

@ -238,8 +238,8 @@ textbook: "Ch. 6.4"
<pre><code>
def append(elem: T): Unit =
{
if(used == data.size){
/* 🙁 case; assume newLength > data.size, but pick it later */
if(used == data.size){ /* 🙁 case */
/* assume newLength > data.size, but pick it later */
val newData = Array.copyOf(original = data, newLength = ???)
/* Array.copyOf doesn't init elements, so we have to */
for(i <- data.size until newData.size){ newData(i) = None }
@ -354,7 +354,7 @@ textbook: "Ch. 6.4"
<section>
<h4 class="slide_title">newLength = data.size × 2</h4>
<p>How many boxes for $n$ inserts? <span class="fragment">$\log(n)$</span></p>
<p>How many boxes for $n$ inserts? <span class="fragment">$\Theta(\log(n))$</span></p>
<p class="fragment">How much work for box $j$?
<center>
<span class="fragment">
@ -364,7 +364,7 @@ textbook: "Ch. 6.4"
</center>
</p>
<p class="fragment">How much work for $n$ inserts?
$$\sum_{j = 0}^{\log(n)}\Theta(2^j)$$
$$\sum_{j = 0}^{\Theta(\log(n))}\Theta(2^j)$$
</p>
<p class="fragment"><b>Total for $n$ insertions: </b> $\Theta(n)$</p>
@ -388,4 +388,13 @@ textbook: "Ch. 6.4"
<p class="fragment">e.g., the amortized runtime of <tt>append</tt> is $O(\frac{n}{n}) = O(1)$</p>
<p class="fragment">(even though the worst-case runtime is $O(n)$)</p>
</section>
<section>
<h4 class="slide_title">Next time...</h4>
<ul>
<li>Linked Lists</li>
<li>Iterators</li>
<li>Access-by-reference</li>
</ul>
</section>