Skip to content

Commit 447c0f2

Browse files
More practice problems
1 parent 5263259 commit 447c0f2

23 files changed

Lines changed: 163 additions & 17 deletions

OMSCS/Courses/GA/00.7 - Common Course Runtimes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ In this course, we will always treat graphs as adjacency lists, with an indexabl
6767
- If the graph is a clique
6868
- $m=n(n-1)/2=O(n^2)$
6969
- $O(n+m)=O(n+n^2)=O(n^2)$
70+
o

OMSCS/Courses/GA/Office Hours/2026-03-15 - TA Office Hours - Exam 2.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ tags:
77
This OH covers the following strategies, outlined below. It also covers the following practice problems:
88
- [[4.3 - Squares]]
99
- [[5.9 - Properties of Weighted Undirected Graphs]]
10-
- [[7.22 -]]
11-
- [[7.24 -]]
10+
- [[7.22 - Fast Max-Flow Recomputation (TODO)]]
11+
- [[7.24 - Direct Bipartite Matching (TODO)]]
1212

1313
## Graph Strategies
1414
- Check for connectivity with BFS or DFS
@@ -34,7 +34,7 @@ This OH covers the following strategies, outlined below. It also covers the foll
3434

3535
## Max-Flow Strategies
3636
- Convert to flow network
37-
- [[7.3 -]]
37+
- [[7.3 - Cargo Plane (TODO)]]
3838
- Adding new source and sink
3939
- Updating capacities
4040
- infinite capacity

OMSCS/Courses/GA/Practice Problems/4.3 - Squares.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,5 @@ However, this doesn't work for fully-connected graphs. In a fully connected grap
8282
1. Run FW
8383
2. Find $iter[1][\cdot][\cdot]=2$
8484
1. Index 1 is the number of intermediate nodes
85-
2.
86-
3.
8785

8886
![[Pasted image 20260316155849.png]]

OMSCS/Courses/GA/Practice Problems/5.20 - Perfect Matching Tree.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ I believe this works, but it doesn't use a black box from [[04.0.1 - Graphs - Bl
4141

4242
## Justifications
4343
- Iterating over vertices by descending order of preorder number prioritizes vertices which are "fringe" vertices. The vertex with the highest preorder number has only one edge.
44-
- We walk "up" the tree from those fringe vertices, towards the arbitrary starting vertex, removing connected pairs from the tree as we go.
44+
- We walk "up" the *tree* from those fringe vertices, towards the arbitrary starting vertex, removing connected pairs from the tree as we go.
4545
- We run into an issue when 2 vertices $v_1$ and $v_2$ share the same parent ($u=prev[v_1]=prev[v_2]$), and are independently selected as $v \in V_{pre}$ in our algorithm. This indicates that the DFS from $s$ encountered a branch at $u$. $u$ is the root of of a subtree $T_u$ of $G$, and removing $u$ from $T_u$ produces at least 2 additional subtrees. At least 2 of these subtrees, symbolized $T_{u,a}$ and $T_{u,b}$, are both independently incapable of producing a $PM$ set of edges. Therefore, both must include an edge to $u$ in order to produce a $PM$ set. However, this would require that the $PM$ set of $G$ contains $u$ at least twice, which is a contradiction in the definition of what a $PM$ set of edges is.
4646

4747
## Runtime
@@ -50,4 +50,12 @@ I believe this works, but it doesn't use a black box from [[04.0.1 - Graphs - Bl
5050
- Creating $V_{pre}$: $O(n)$
5151
- Iterating over $V_{pre}$: $O(n)$
5252

53-
Overall: $O(n+m)$
53+
Overall: $O(n+m)$
54+
55+
## Notes from TA Solution
56+
> It's a little bit more creative \[than running MST\].
57+
58+
- We know by the problem statement that there needs to be $\ge 2$ leaves. If the graph only has 2 connected vertices, then the graph only has 1 edge.
59+
- Tim mentions the "degree" of each vertex in the resulting $G=(V,E')$. In the resulting graph, each $v \in V$ will have degree 1.
60+
- The approach is based on taking the leaf edges and then re-evaluating the graph. Take a leaf and the vertex it connects to. Remove both from the tree. Keep going until you have an empty graph or an isolated vertex.
61+
- The TA solution follows the procedure outlined in the **Exploration** section above, which unfortunately does not use a black-box algorithm.

OMSCS/Courses/GA/Practice Problems/5.22 - Fast MST Recomputation.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,28 @@ tags:
88
![[Pasted image 20260316211257.png]]
99

1010
## 5.22a
11-
Do nothing. $e$ is already not in the MST of G, and now it's a worse option.
11+
> $e$ is not currently part of the MST, and the new weight of $e$ is now higher.
12+
13+
Do nothing. $e$ is already not in the MST of G, and now it's a worse option. $T$ is still the MST.
1214

1315
## 5.22b
16+
> $e$ is not currently part of the MST, and the new weight of $e$ is now lower.
17+
1418
- Add $e$ to $E'$
1519
- Find the cycle in $T$ containing $e$
1620
- Remove max edge in $C$.
1721

1822
## 5.22c
19-
Do nothing. $e$ is already in the MST of G, and now $e$ is/was an even better choice across the cut of $S$ and $\overline{S}$, where $e=(u,v)$ and $u \in S$ and $v \in \overline{S}$.
23+
> $e$ is currently part of the MST, and the new weight of $e$ is now lower.
24+
25+
Do nothing. $e$ is already in the MST of G, and now $e$ is/was an even better choice across the cut of $S$ and $\overline{S}$, where $e=(u,v)$ and $u \in S$ and $v \in \overline{S}$. $T$ is still the MST.
26+
27+
## 5.22d
28+
> $e$ is currently part of the MST, and the new weight of $e$ is now higher.
2029
21-
## 5.23d
2230
$e=(u,v)$ defines a $cut(S,\overline{S})$ where $u \in S$ and $v \in \overline{S}$. We need to find $\hat{e}=\min\{ cut(S, \overline{S}) \}$. Add $\hat{e}$ to $E'$. Remove $e$ from $E$.
2331

24-
How do we find $\hat{e}=\min\{ cut(S, \overline{S}) \}$ in linear time? If we remove $e$ from $E'$, we can run DFS on $T$, to produce a `ccnum[]`, which identifies $S$ and $\overline{S}$. We can then iterate over $\hat{e}=(u,v) \in E$, filtering out any $\hat{e}$ where $ccnum[u]=ccnum[v]$. Those options for $\hat{e}$ do not cross $cut(S, \overline{S})$, and therefore create a cycle within $S$ or $\overline{S}$, and do not complete the MST. For the options for $\hat{e}$ that remain, we take the one with the lowest edge weight.
32+
How do we find $\hat{e}=\min\{ cut(S, \overline{S}) \}$ in linear time? If we remove $e$ from $E'$, we can run DFS on $T$, to produce a `ccnum[]`, which identifies $S$ and $\overline{S}$. We can then iterate over $\hat{e}=(u,v) \in E$, filtering out any $\hat{e}$ where $ccnum[u]=ccnum[v]$. Those options for $\hat{e}$ do not cross $cut(S, \overline{S})$, and therefore create a cycle within $S$ or $\overline{S}$, and do not complete the MST. For the options for $\hat{e}$ that remain, we take the one with the lowest edge weight.
33+
34+
## Notes from TA Solution
35+
**For 5.22b**, instead of adding $e$ first, we can find the cycle that $e$ **would be** apart of if $e$ is added to the MST. For the given edge $e=(u,v)$, we run a DFS from $u$. This will find $v$ through some other path $P$. We can then reconstruct that path to find the heaviest edge $e' \in P$. If $e'$ is heaver than $e$, we remove $e'$ from $T$ and add $e$ to $T$.

OMSCS/Courses/GA/Practice Problems/5.23 - Light Spanning Trees.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ tags:
1313
1. We make a copy of $G$, $G'=(V',E')$, removing all $v \in U$ from $V'$.
1414
2. We check for connectivity by running DFS on $G'$. If $G'$ is not connected, then we can't make a tree where all of the vertices in $U$ are leaves of a light spanning tree of $G$.
1515
3. We run Kruskal's on $G'$ to produce an MST of $G'$: $T=(V',E'')$
16-
4. We then iterate over all $u \in U$, and find the minimum edge $e_u$ between $u$ and a vertex in $V'$. This edge represents the $\min\{cut(V', \{u\}\}$. We add $e_u$ to a new set $E_u$.
16+
4. We then iterate over all $u \in U$, and find the minimum edge $e_u$ between $u$ and a vertex in $V'$. This edge represents the $\min\{cut(V', \{u\}\}$.
17+
1. If $e_u$ does not exist, then $u$ must only connect to other vertices in $U$. Therefore, we cannot satisfy the prompt.
18+
2. Otherwise, we add $e_u$ to a new set $E_u$.
1719
5. We add all edges in $E_u$ to $E''$
1820

1921
## Justification
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 7.18 - Max Flow Variations (TODO)
8+
![[Pasted image 20260317230911.png]]
9+
10+
## 7.18a
11+
> There are many sources and many sinks, and we wish to maximize the total flow from all sources to all sinks.
12+
13+
If there are multiple sources, we can add a super source $SS$ that connects to all sources $S$. The capacity of the edges from SS to each $s \in S$ should be at least the sum of the flow leaving $s$. The capacity of these edges can be made infinite. Same for multiple sinks. Just make one big sink.
14+
15+
Before sending the flow to the asker, remove the edges which connect from the super source, and the edges which connect to the super sink.
16+
17+
## 7.18b
18+
> Each vertex also has a capacity on the maximum flow that can enter it.
19+
20+
For each vertex, duplicate it, and add an edge between the 2 copies of the vertex. That edge should have capacity equal to the max flow that can enter the vertex.

OMSCS/Courses/GA/Practice Problems/7.18 -.md

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 7.19 - Max Flow Validation
8+
> Suppose someone presents you with a solution to a max-flow problem on some network. Give a linear time algorithm to determine whether the solution does indeed give a maximum flow.
9+
10+
- What is the solution to a max flow problem?
11+
- [[04.0.1 - Graphs - Black Box Algorithms]]
12+
- The outputs are
13+
- `flow[]` - A list of edges representing the amount capacity used per each indexed edge such that the flow is maximized from the starting vertex to the terminating vertex
14+
- `C` - the total flow.
15+
16+
We need to reconstruct the residual network and check if there exists a path from $s$ to $t$ in the residual network (an "st-path").
17+
18+
How to reconstruct the residual:
19+
20+
- From: [[05.2 - Max Flow - MF MC]]
21+
- Original flow network is directed $G=(V,E)$ with capacities $c_e \in C : e \in E$
22+
- Construct a residual graph containing the vertices of $G$ but no edges ($G^f=(V, \emptyset)$)
23+
- For each edge $e=(v,w) \in E$
24+
- Add $vw$ to $G^f$
25+
- Add $wv$ to $G^f$
26+
- Set $c^f_{vw}=c_{vw}-f_e$
27+
- Set $c^f_{wv}=f_e$
28+
29+
We can then run DFS to check for an st-path in $G^f$. If none exists, then the flow through $G$ is already maximized.

OMSCS/Courses/GA/Practice Problems/7.19 -.md

Whitespace-only changes.

0 commit comments

Comments
 (0)