You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notes/courses/CSCI-UA-310/15-16-greedy.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,7 @@ GREEDY-ACTIVITY-SELECTOR(s, f)
65
65
Let $A = \{a_1, a_2, \dots, a_k\}$ (greedy solution, sorted by finish time) and $O = \{o_1, o_2, \dots, o_m\}$ (any optimal solution, sorted by finish time). We show $|A| = |O|$, i.e., $k = m$.
66
66
67
67
**Key Lemma**: For each $i = 1, \dots, k$: $f(a_i) \leq f(o_i)$.
68
+
68
69
* Base: Greedy picks the activity with the smallest finish time overall, so $f(a_1) \leq f(o_1)$.
69
70
* Inductive step: Since $f(a_i) \leq f(o_i) \leq s(o_{i+1})$, activity $o_{i+1}$ is also compatible with $a_i$. The greedy algorithm could have picked something with finish time $\leq f(o_{i+1})$, so $f(a_{i+1}) \leq f(o_{i+1})$.
70
71
@@ -149,6 +150,7 @@ Sort jobs by start time. Maintain a set of machines. For each job, assign it to
149
150
**Input**: An alphabet $C = \{c_1, \dots, c_n\}$ where character $c_i$ has frequency $f_i$.
150
151
151
152
**Goal**: Assign a binary codeword to each character such that:
153
+
152
154
* The code is **prefix-free** (no codeword is a prefix of another).
153
155
* The **total encoding length** $\sum_{c \in C} f_c \cdot d_T(c)$ is minimized, where $d_T(c)$ is the depth of $c$ in the code tree $T$.
Copy file name to clipboardExpand all lines: notes/courses/CSCI-UA-310/19-20-shortest-paths.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ $$\delta(s, v) = \min \{ w(p) : s \xrightarrow{p} v \}$$
27
27
and $\delta(s, v) = \infty$ if no path exists.
28
28
29
29
**Shortest-path properties**:
30
+
30
31
***Optimal substructure**: Any subpath of a shortest path is itself a shortest path.
31
32
***Triangle inequality**: $\delta(s, v) \leq \delta(s, u) + w(u, v)$ for all edges $(u,v)$.
32
33
***No negative cycles**: If a negative cycle is reachable from $s$, shortest paths are undefined (can be made arbitrarily small).
@@ -38,6 +39,7 @@ and $\delta(s, v) = \infty$ if no path exists.
38
39
All SSSP algorithms maintain estimates $v.d \geq \delta(s,v)$ and predecessors $v.\pi$.
39
40
40
41
**Initialization**:
42
+
41
43
```text
42
44
INITIALIZE-SINGLE-SOURCE(G, s)
43
45
1. for each v in V
@@ -47,6 +49,7 @@ INITIALIZE-SINGLE-SOURCE(G, s)
47
49
```
48
50
49
51
**Relaxation** of edge $(u, v)$:
52
+
50
53
```text
51
54
RELAX(u, v, w)
52
55
1. if v.d > u.d + w(u, v)
@@ -55,6 +58,7 @@ RELAX(u, v, w)
55
58
```
56
59
57
60
**Key properties**:
61
+
58
62
* After `RELAX(u, v, w)`: $v.d \leq u.d + w(u,v)$.
59
63
* If $u.d = \delta(s, u)$ at the time of relaxation, then afterwards $v.d \leq \delta(s, v)$.
60
64
* $v.d$ never increases.
@@ -150,6 +154,7 @@ BELLMAN-FORD(G, w, s)
150
154
**Theorem**: After $k$ iterations of the outer loop, $v.d \leq$ the weight of the shortest path from $s$ to $v$ using **at most $k$ edges**.
151
155
152
156
**Proof by induction**:
157
+
153
158
* After 0 iterations: $s.d = 0 = \delta_0(s,s)$ and $v.d = \infty$ for $v \neq s$. Correct (no 0-edge paths to others).
154
159
* After $k$ iterations: Assume $v.d \leq \delta_{k-1}(s,v)$ for all $v$ after $k-1$ iterations. When we relax edge $(u,v)$: $v.d \leq u.d + w(u,v) \leq \delta_{k-1}(s,u) + w(u,v) = \delta_k(s,v)$.
Copy file name to clipboardExpand all lines: notes/courses/CSCI-UA-310/21-22-min-spanning-tree.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -83,6 +83,7 @@ MST-KRUSKAL(G, w)
83
83
## 4. Union-Find (Disjoint Set Union)
84
84
85
85
Kruskal's algorithm needs efficient support for:
86
+
86
87
*`MAKE-SET(x)`: Create a singleton set $\{x\}$.
87
88
*`FIND-SET(x)`: Return the representative of $x$'s set.
88
89
*`UNION(x, y)`: Merge the sets containing $x$ and $y$.
@@ -133,6 +134,7 @@ since $|E| \leq |V|^2$ so $\log E = O(\log V)$.
133
134
**Why safe**: At each step, the cut $(S, V \setminus S)$ where $S$ is the current tree respects $A$. The lightest crossing edge is safe by the safe-edge theorem.
134
135
135
136
Each vertex $v \notin S$ maintains:
137
+
136
138
*`v.key`: minimum weight of any edge connecting $v$ to a vertex in $S$ (or $\infty$ if none).
137
139
*`v.Ο`: the vertex in $S$ that achieves `v.key`.
138
140
@@ -164,6 +166,7 @@ When $u$ is extracted, `u.key` = $w(u, u.\pi)$ is the minimum-weight edge from $
164
166
Graph: $V = \{a,b,c,d,e,f,g,h,i\}$, with edges of various weights.
Copy file name to clipboardExpand all lines: notes/courses/CSCI-UA-310/23-apsp-floyd-warshall.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,7 @@ Better, but Floyd-Warshall achieves $O(|V|^3)$ with a different subproblem defin
70
70
**Subproblem**: $D[u, v, i]$ = shortest path from $u$ to $v$ using only vertices from $\{v_1, \dots, v_i\}$ as intermediate vertices.
71
71
72
72
**Key observation**: For the shortest $u \to v$ path using only $\{v_1,\dots,v_i\}$:
73
+
73
74
***Case 1**: $v_i$ is **not** on the path. Then $D[u,v,i] = D[u,v,i-1]$.
74
75
***Case 2**: $v_i$ **is** on the path. Then the sub-paths $u \to v_i$ and $v_i \to v$ both use only $\{v_1,\dots,v_{i-1}\}$. So $D[u,v,i] = D[u,v_i,i-1] + D[v_i,v,i-1]$.
75
76
@@ -103,6 +104,7 @@ FLOYD-WARSHALL(W)
103
104
Graph with $V = \{v_1, v_2, v_3, v_4, v_5, v_6\}$:
104
105
105
106
Computing $D[v_3, v_5, i]$ through successive iterations:
107
+
106
108
* $D[v_3, v_5, 0] = \infty$ (no direct edge)
107
109
* $D[v_3, v_5, 1] = \infty$ (no path through $v_1$ only)
Copy file name to clipboardExpand all lines: notes/courses/CSCI-UA-310/25-26-27-complexity.md
+16-6Lines changed: 16 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,7 @@ These lectures ask two foundational questions: **which problems can computers so
29
29
We focus on **decision problems**: problems whose answer is "yes" or "no."
30
30
31
31
**Examples**:
32
+
32
33
***MST**: Given graph $G$, weights $w$, and integer $k$: is the MST of $G$ of weight $\leq k$?
33
34
***Halting**: Given program $P$ and input $x$: does $P(x)$ terminate?
34
35
***Wang Tiling**: Given a set of colored tile types, can they tile the infinite 2D plane such that adjacent tiles share the same color on touching sides?
@@ -38,10 +39,12 @@ We focus on **decision problems**: problems whose answer is "yes" or "no."
38
39
## 2. Decidability
39
40
40
41
**Notation**:
42
+
41
43
* $\langle P \rangle$ = the source code of program $P$ (in some fixed language).
42
44
* $P(x)$ = running program $P$ on input $x$.
43
45
44
46
**Definition**: An algorithm $A$ **solves** problem $\Pi$ if for all inputs:
47
+
45
48
* If the answer is "yes," $A$ outputs "yes" and terminates.
46
49
* If the answer is "no," $A$ outputs "no" and terminates.
0 commit comments