diff --git a/src/teaching/cse-250/2022fa/index.erb b/src/teaching/cse-250/2022fa/index.erb
index 9d6ef673..d9e60ef5 100644
--- a/src/teaching/cse-250/2022fa/index.erb
+++ b/src/teaching/cse-250/2022fa/index.erb
@@ -217,7 +217,7 @@ schedule:
special: "No Class: Labor Day"
dow: Mon
- date: 09/07/22
- topic: Runtime Analysis
+ topic: Runtime Analysis - Intuitions
due: AI Quiz
dow: Wed
section_a:
@@ -226,33 +226,44 @@ schedule:
section_b:
slides: slide/3b-FunctionAnalysis.html
- date: 09/09/22
- topic: Runtime Analysis (contd...)
+ topic: Runtime Analysis - Formalism
dow: Fri
due: PA0
+ section_a:
+ slides: slide/4b-AsymptoticNotation.html
section_b:
slides: slide/4b-AsymptoticNotation.html
- week: 3
lectures:
- date: 09/12/22
- topic: Collections, Sequences, ADTs
dow: Mon
+ topic: Runtime Analysis - Formalism (contd...)
+ topic:
+ section_a:
+ slides: slide/4b-AsymptoticNotation.html
+ section_b:
+ slides: slide/4b-AsymptoticNotation.html
- date: 09/14/22
- topic: Array Lists
+ topic: Runtime Analysis - Examples
dow: Wed
+ section_b:
+ slides: slide/6b-AsymptoticExamples.html
- date: 09/16/22
- topic: Linked Lists
+ topic: Collections, Sequences, ADTs
dow: Fri
due: PA1
+ section_b:
+ slides: slide/7b-ADTsandSequences.html
- week: 4
lectures:
- date: 09/19/22
- topic: Recursion Intro
+ topic: Collections, Sequences, ADTs (contd...)
dow: Mon
- date: 09/21/22
- topic: Divide and Conquer, Tail Recursion
+ topic: Collections, Sequences, ADTs (contd...)
dow: Wed
- date: 09/23/22
- topic: Recursion (contd...)
+ topic: Recursion Intro
dow: Fri
due: WA0
- week: 5
diff --git a/src/teaching/cse-250/2022fa/slide/4b-AsymptoticNotation.erb b/src/teaching/cse-250/2022fa/slide/4b-AsymptoticNotation.erb
index dd2b0bb0..fab574bc 100644
--- a/src/teaching/cse-250/2022fa/slide/4b-AsymptoticNotation.erb
+++ b/src/teaching/cse-250/2022fa/slide/4b-AsymptoticNotation.erb
@@ -1,7 +1,7 @@
---
template: templates/cse250_2022_slides.erb
title: Asymptotic Notation
-date: Sept 7, 2022
+date: Sept 7 and 12, 2022
textbook: "Ch. 7.3-7.4"
---
@@ -342,6 +342,17 @@ textbook: "Ch. 7.3-7.4"
Upper, Lower Bounds
diff --git a/src/teaching/cse-250/2022fa/slide/6b-AsymptoticExamples.erb b/src/teaching/cse-250/2022fa/slide/6b-AsymptoticExamples.erb
new file mode 100644
index 00000000..f23bfefd
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/6b-AsymptoticExamples.erb
@@ -0,0 +1,241 @@
+---
+template: templates/cse250_2022_slides.erb
+title: Asymptotic Notation Examples
+date: Sept 14, 2022
+textbook: "Ch. 7.3-7.4"
+---
+
+
+ Big-_ Notation Recap
+
+
+ Big-ϴ
+ Growth Functions in the same complexity class.
+ If $f(n) \in \Theta(g(n))$, then an algorithm that takes $f(n)$ steps is exactly as fast as one that takes $g(n)$ steps.
+
+ Big-O
+ Growth Functions in the same or smaller complexity class.
+ If $f(n) \in O(g(n))$, then an algorithm that takes $f(n)$ steps is as fast as or faster than one that takes $g(n)$ steps.
+
+ Big-Ω
+ Growth Functions in the same or bigger complexity class.
+ If $f(n) \in \Omega(g(n))$, then an algorithm that takes $f(n)$ steps is as slow as or slower than one that takes $g(n)$ steps.
+
+
+
+
+ Common Runtimes
+
+
+ Constant Time: $\Theta(1)$
+ e.g., $T(n) = c$ (runtime is independent of $n$)
+
+ Logarithmic Time: $\Theta(\log(n))$
+ e.g., $T(n) = c\log(n)$ (for some constant $c$)
+
+ Linear Time: $\Theta(n)$
+ e.g., $T(n) = c_1n + c_0$ (for some constants $c_0, c_1$)
+
+ Quadratic Time: $\Theta(n^2)$
+ e.g., $T(n) = c_2n^2 + c_1n + c_0$
+
+ Polynomial Time: $\Theta(n^k)$ (for some $k \in \mathbb Z^+$)
+ e.g., $T(n) = c_kn^k + \ldots + c_1n + c_0$
+
+ Exponential Time: $\Theta(c^n)$ (for some $c \geq 1$)
+
+
+
+
+ Constants vs Asymptotics
+
+
+
+ Constant-Factor Speedups
+
+
+ for(i ← 0 until n) { /* do work */ }
+
+
+
+
+
+ $c$ and $n_0$
+
+ Compare $T_1(n) = 100n$ vs $T_2(n) = n^2$
+
+ $100n = O(n^2)$ ($T_2$ is the slower runtime)
+ ... but $c_{high} = 1$, $n_0 = 100$
+ Until inputs of size 100 or more, $T_2$ is the faster runtime
+
+
+
+
+ $c$ and $n_0$
+
+ Asymptotically slower runtimes can be better.
+
+ An algorithm with runtime $T_2$ is better on small inputs.
+ An algorithm with runtime $T_2$ might be easier to implement or maintain
+ An algorithm with runtime $T_1$ might not exist.
+ (sometimes we can prove this, see CSE 331)
+
+
+
+
+
+ ... but from now on, if $T_2(n)$ is in a bigger complexity class, then $T_1(n)$ is better/faster/stronger.
+
+
+
+
+
+ Bubble Sort
+
+ bubblesort(seq: Seq[Int]):
+ 1. n ← seq length
+ 2. for i ← n-2 to 0, by -1:
+ 3. for j ← i to n-1:
+ 4. if seq(j+1) < seq(j):
+ 5. swap seq(j) and seq(j+1)
+
+ What is the runtime complexity class of Bubble Sort?
+
+
+
+ Summation Rules
+
+
+ $\sum_{i=j}^{k}c = (k - j + 1)c$
+
+ $\sum_{i=j}^{k}(cf(i)) = c\sum_{i=j}^{k}f(i)$
+
+ $\sum_{i=j}^{k}(f(i) + g(i)) = \left(\sum_{i=j}^{k}f(i)\right) + \left(\sum_{i=j}^{k}g(i)\right)$
+
+ $\sum_{i=j}^{k}(f(i)) = \left(\sum_{i=\ell}^{k}(f(i))\right) - \left(\sum_{i=\ell}^{j-1}(f(i))\right)$ (for any $\ell < j$)
+
+ $\sum_{i=j}^{k}f(i) = f(j) + f(j+1) + \ldots + f(k-1) + f(k)$
+
+ $\sum_{i=j}^{k}f(i) = f(j) + \ldots + f(\ell - 1) + \left(\sum_{i=\ell}^k f(i)\right)$ (for any $j < \ell \leq k$)
+
+ $\sum_{i=j}^{k}f(i) = \left(\sum_{i=j}^{\ell}f(i)\right) + f(\ell+1) + \ldots + f(k)$ (for any $j \leq \ell < k$)
+
+ $\sum_{i=1}^{k}i = \frac{k(k+1)}{2}$
+
+ $\sum_{i=0}^{k}2^i = 2^{k+1}-1$
+
+ $n! \leq c_sn^n$ is a tight upper bound (Sterling: Some constant $c_s$ exists)
+
+
+
+
+ Bubble Sort
+
+ bubblesort(seq: Seq[Int]):
+ 1. n ← seq length
+ 2. for i ← n-2 to 0, by -1:
+ 3. for j ← i to n-1:
+ 4. if seq(j+1) < seq(j):
+ 5. swap seq(j) and seq(j+1)
+
+ Note: We can ignore the exact number of steps required by any step in the algorithm, as long as we know its complexity
+ Can we safely say this algorithm is $\Theta(n^2)$?
+
+
+
+ Bubble Sort (for Mutable Sequences)
+
+ def sort(seq: mutable.Seq[Int]): Unit =
+ {
+ val n = seq.length
+ for(i <- n - 2 to 0 by -1; j <- i to n)
+ {
+ if(seq(n) < seq(j))
+ {
+ val temp = seq(j+1)
+ seq(j+1) = seq(j)
+ seq(j) = temp
+ }
+ }
+ }
+
+
+
+
+ Bubble Sort (for Im mutable Sequences)
+
+ def sort(seq: Seq[Int]): Seq[Int] =
+ {
+ val newSeq = seq.toArray
+ val n = seq.length
+ for(i <- n - 2 to 0 by -1; j <- i to n)
+ {
+ if(newSeq(n) < newSeq(j))
+ {
+ val temp = newSeq(j+1)
+ newSeq(j+1) = newSeq(j)
+ newSeq(j) = temp
+ }
+ }
+ return newSeq.toList
+ }
+
+
+
+
+ Searching Sequences
+
+ def indexOf[T](seq: Seq[T], value: T, from: Int): Int =
+ {
+ for(i <- from until seq.length)
+ {
+ if(seq(i).equals(value)) { return i }
+ }
+ return -1
+ }
+
+
+
+
+ Searching Sequences
+
+ def count[T](seq: Seq[T], value: T): Int =
+ {
+ var count = 0;
+ var i = indexOf(seq, value, 0)
+ while(i != -1)
+ {
+ count += 1;
+ i = indexOf(seq, value, i+1)
+ }
+ return count
+ }
+
+
+
+
+ Searching Sorted Sequences
+
+ ... with $O(1)$ access to elements ('random access')
+
+
+ To search $[begin, end)$:
+ compare $target$ to $seq[middle]$ ($middle = \frac{end+begin}{2}$
+ If $seq[middle] = target$ return $middle$
+ If $target < seq[middle]$ search $[begin, middle)$
+ If $seq[middle] < target$ search $[middle+1, end)$
+ If $begin = end$, the value doesn't exist.
+
+
+
+ What if no random access is available?
+
\ No newline at end of file
diff --git a/src/teaching/cse-250/2022fa/slide/7b-ADTsandSequences.erb b/src/teaching/cse-250/2022fa/slide/7b-ADTsandSequences.erb
new file mode 100644
index 00000000..969a449e
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/7b-ADTsandSequences.erb
@@ -0,0 +1,196 @@
+---
+template: templates/cse250_2022_slides.erb
+title: Asymptotic Notation Examples
+date: Sept 16, 2022
+textbook: "Ch. 7.1, 1.7.2"
+---
+
+
+
+
+ Sequences
+
+
+ The Fibonacci Sequence
+ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
+
+ Characters of a String
+ 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'
+
+ Lines of a file.
+
+
+
+
+ What can you do with a Sequence?
+
+
+ Enumerate every element of the sequence.
+ Get the 'n'th element.
+ Modify the 'n'th element (mutable only).
+
+
+
+
+ Abstract Data Types (ADTs)
+
+
+
+
+
+ The Seq ADT
+
+
+ apply(idx : Int): [A]
+ Get the element (of type A) at position idx .
+
+ iterator: Iterator[A]
+ Get access to all elements in the seq, in order, once.
+
+ length: Int
+ Count the number of elements in the seq.
+
+
+
+
+ The mutable.Seq ADT
+
+
+ apply(idx : Int): [A]
+ Get the element (of type A) at position idx .
+
+ iterator: Iterator[A]
+ Get access to all elements in the seq, in order, once.
+
+ length: Int
+ Count the number of elements in the seq.
+
+ insert(idx : Int, elem : A): Unit
+ Insert an element at position idx with value elem .
+
+ remove(idx : Int): A
+ Remove the element at position idx and return the removed value.
+
+
+
+
+ ... so how do we implement it?
+
+
+
+ RAM (CSE 220 crossover)
+
+
+
+
+
+ RAM
+
+
+ new T()
+ Find some unused part of memory big enough to fit a T , mark it used, and return the address of that location.
+
+
+
+
+ var arr = new Array[Int](50)
+
+ allocates $50 * 4 = 200$ bytes of memory (Java
Int is 4 bytes).
+
+
+ If arr is at address $a$, where should you look for arr(19) ? arr(55) ?
+
+
+
+ Array[T] : Seq[T]
+
+ An Array of $n$ items of type T :
+
+
+ 4 bytes for $n$ (optional)
+ 4 bytes for $\textt{sizeof}(\texttt{T})$) (optional).
+ $n \times \texttt{sizeof}(\texttt{T})$ bytes of memory.
+
+
+
+
+
+ Array[T] : Seq[T]
+
+ How do we implement...
+
+ apply(idx : Int): [A]
+ Get the element (of type A) at position idx .
+
+ length: Int
+ Count the number of elements in the seq.
+
+ insert(idx : Int, elem : A): Unit
+ Insert an element at position idx with value elem .
+
+ remove(idx : Int): A
+ Remove the element at position idx and return the removed value.
+
+
+
+
+ Insert and remove don't make sense on arrays...
+ Idea Reserve extra space in the array!
+
+
+
+ ArrayBuffer[T] : Buffer[T]
+
+ An ArrayBuffer of $n$ items of type T :
+
+
+ 4 bytes for $n$ (optional)
+ 4 bytes for $\textt{sizeof}(\texttt{T})$) (optional).
+ 4 bytes for the number of fields $used$
+ $n \times \texttt{sizeof}(\texttt{T})$ bytes of memory.
+
+
+
+
+
\ No newline at end of file
diff --git a/src/teaching/cse-250/2022fa/slide/graphics/04b/class-bounds.svg b/src/teaching/cse-250/2022fa/slide/graphics/04b/class-bounds.svg
index cd696ec8..7d9efa6f 100644
--- a/src/teaching/cse-250/2022fa/slide/graphics/04b/class-bounds.svg
+++ b/src/teaching/cse-250/2022fa/slide/graphics/04b/class-bounds.svg
@@ -2,9 +2,9 @@
+ transform="translate(-19.088647,-26.515478)">
+
+ f(n)
+ chigh g(n)
+ clow g(n)
+ n0
+
diff --git a/src/teaching/cse-250/2022fa/slide/graphics/07b/adt_opaque_box.svg b/src/teaching/cse-250/2022fa/slide/graphics/07b/adt_opaque_box.svg
new file mode 100644
index 00000000..4a7af677
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/graphics/07b/adt_opaque_box.svg
@@ -0,0 +1,175 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Read 'n'th item
+ Read Everything
+ Update 'n'th item
+
+
+
+
+ Data are in an opaque box (no specified layout)
+
+
+
+ Access goverened by semantics (what) not implementation (how)
+
+
+
+
diff --git a/src/teaching/cse-250/2022fa/slide/graphics/07b/array.svg b/src/teaching/cse-250/2022fa/slide/graphics/07b/array.svg
new file mode 100644
index 00000000..5fdf6e72
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/graphics/07b/array.svg
@@ -0,0 +1,185 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ n
+ |T|
+ a[0]
+ a[1]
+ a[2]
+ a[3]
+ a[4]
+ ...
+
+
+
diff --git a/src/teaching/cse-250/2022fa/slide/graphics/07b/arraybuffer.svg b/src/teaching/cse-250/2022fa/slide/graphics/07b/arraybuffer.svg
new file mode 100644
index 00000000..b6ae6eb6
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/graphics/07b/arraybuffer.svg
@@ -0,0 +1,253 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ n
+ |T|
+ a[0] or None
+ ...
+
+ u
+ a[1] or None
+ a[2] or None
+ a[3] or None
+ a[4] or None
+
+
+
diff --git a/src/teaching/cse-250/2022fa/slide/graphics/07b/ram.svg b/src/teaching/cse-250/2022fa/slide/graphics/07b/ram.svg
new file mode 100644
index 00000000..50ea9eee
--- /dev/null
+++ b/src/teaching/cse-250/2022fa/slide/graphics/07b/ram.svg
@@ -0,0 +1,3214 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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