Skip to content

Commit d9e1e7b

Browse files
More notes and PPs
1 parent eaaf1e9 commit d9e1e7b

27 files changed

Lines changed: 811 additions & 79 deletions

OMSCS/Courses/GA/04.2 - Graphs - 2-SAT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Simplification Example
8383
- **Satisfiable:** $X=[F,T,T,F]$
8484

8585
## Graph of Implications
86-
- Take $f$ with all clauses of size 2.\
86+
- Take $f$ with all clauses of size 2.
8787
- $n$ variables
8888
- $m$ clauses
8989
- Create a directed graph
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
---
6+
# 06.6 - NP - Known NP-Complete Problems
7+
8+
## SAT
9+
- **Input:** $f$
10+
- a boolean expression in CNF
11+
- $n$ variables and $m$ clauses
12+
- **Output:**
13+
- A satisfying assignment $S$ of $f$ if one exists, such that $f$ evaluates as true.
14+
- No otherwise.
15+
16+
## 3SAT
17+
- **Input:** $f$
18+
- a boolean expression in CNF
19+
- $n$ variables and $m$ clauses
20+
- Each clause has up to 3 literals
21+
- **Output**
22+
- A satisfying assignment $S$ of $f$ if one exists, such that $f$ evaluates as true.
23+
- No otherwise.
24+
25+
## Clique
26+
$S$ is an Clique of $G=(V,E)$ if $\forall_{a,b \in S}((a,b) \in E)$. Put simply, the induced subgraph $S$ of $G$ contains edges between all pairs of vertices.
27+
28+
- **Input:**
29+
- $G=(V,E)$
30+
- goal $g$
31+
- **Output:**
32+
- $S \subset V$ where $S$ is a clique of size $|S| \ge g$, if one exists, and "NO" otherwise.
33+
34+
## Independent Set (IS)
35+
$S$ is an IS of $G=(V,E)$ if $\forall_{a,b \in S}((a,b) \notin E)$. Put simply, the induced subgraph $S$ of $G$ contains no edges.
36+
37+
- **Input:**
38+
- Undirected $G=(V,E)$
39+
- Goal $g$
40+
- **Output:**
41+
- Independent set $S$ where $|S| \ge g$ (if one exists), "No" otherwise
42+
43+
## Vertex Cover (VC)
44+
$S$ "covers" $G$ if $\forall_{a,b \in E} \space (a \in S) \vee (b \in S)$. Put simply, all edges in $G$ connect to at least one vertex in $S$.
45+
46+
- **Input**
47+
- $G=(V,E)$
48+
- budget $b$
49+
- **Output**
50+
- vertex cover $S$ of size $|S| \le b$ if one exists
51+
- No otherwise
52+
53+
## Subset Sum (SSS)
54+
- **Input**
55+
- A set of values $V$
56+
- A goal $g$
57+
- **Output**
58+
- A subset of $S \subseteq V$ whose sum equals $g$
59+
- No otherwise
60+
61+
## Rudrata Path
62+
This is the hamiltonian cycle problem, but renamed because he was centuries too late to claim the name of the problem.
63+
64+
- **Input:**
65+
- A simple graph $G=(V,E)$
66+
- **Output:**
67+
- A path through $G$ which touches all vertices exactly once
68+
- No otherwise
69+
70+
## Rudrata st-Path
71+
This is an extension of the Rudrata Path problem.
72+
73+
- **Input:**
74+
- A simple graph $G=(V,E)$
75+
- A pair of vertices $s$ and $t$
76+
- **Output:**
77+
- A path through $G$ which touches all vertices exactly once
78+
- The path starts at $s$ and ends at $t$
79+
- No otherwise
80+
81+
## Rudrata Cycle
82+
This is an extension of the Rudrata Path problem.
83+
84+
- **Input:**
85+
- A simple graph $G=(V,E)$
86+
- **Output:**
87+
- A cycle in $G$ which touches all vertices exactly once
88+
- No otherwise
89+
90+
## Integer Linear Programming (ILP)
91+
- **Input:** A linear program (LP) in standardized form
92+
- $\max \space c^Tx$
93+
- s.t. $Ax \le b$
94+
- s.t. $x \ge 0$
95+
- **Output:**
96+
- An assignment to the variables of the LP, which maximizes the objective function within the given constraints, where the variables are all integers.
97+
- No otherwise.
98+
99+
## Zero-One Equations
100+
This is a special case of ILP.
101+
102+
- **Input:**
103+
- Matrix $A$ of size $m \times n$, containing only 0s and 1s
104+
- **Output:**
105+
- An $n \times 1$ vector $x$
106+
- $x$ contains only 0s and 1s
107+
- such that $Ax=1$
108+
- where $1$ is an $m \times 1$ vector containing only 1s
109+
- No otherwise.
110+
111+
## 3D Matching
112+
> You've heard of bipartite, now get ready for TRIPARTITE.
113+
114+
- **Input**
115+
- A set of triples defining the potential 3-groupings between 3 categories, each of size $n$
116+
- **Output**
117+
- A set of $n$ disjoint triples from the given set of triples, such that all items are covered.
118+
- No otherwise
119+
120+
## Traveling Salesman Problem
121+
- **Input**
122+
- A graph $G=(V,E)$
123+
- A set of edge weights/costs/lengths $w$
124+
- A budget $b$
125+
- A starting vertex $s$ (optional?)
126+
- **Output**
127+
- A cycle in $G$ (which starts and ends at $s$, if provided), which has total cost $\le b$.
128+
- No otherwise.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
---
6+
# 2026-04-12 - TA Office Hours - Exam 3
7+
- The Dual LP is a "certificate of optimality" for the Primal LP
8+
- We use the Dual to prove Feasibility and Boundedness
9+
- When checking for infeasibility, "try to find at least one contradiction"
10+
- In the example $(\max \space x,x \le -3, x \ge 0)$, we can see that $x$ has no valid values.
11+
- In the example $(\max \space x+y, x+y \le 1, x+y \ge 3, x,y \ge 0)$, then if we change it to standard form, we have the following conflicting expressions:
12+
- $x+y \le 1$
13+
- $-(x+y) \le 3$
14+
- We can't always check $(0,0)$
15+
- Primal is Unbounded -> Dual is Infeasible
16+
- Primal is Infeasible -> Dual is Unbounded OR Infeasible
17+
- Primal is Bounded -> Dual is Bounded AND Feasible
18+
- Dual of Dual is the Primal
19+
- LP's cannot be Infeasible AND Bounded.
20+
21+
## Optimal Solution Example
22+
- $\max 5x+3y$
23+
- s.t.
24+
- $5x - 2y \ge 0$
25+
- $x+y \le 7$
26+
- $x \le 5$
27+
- $x, y \ge 0$
28+
29+
## Max Flow as LP
30+
![[Pasted image 20260412153326.png]]
31+
32+
![[Pasted image 20260412153443.png]]
33+
34+
## Graph Transformation Ideas (NP Proofs)
35+
- Transforming each vertex/edge
36+
- Duplicate the original graph
37+
- Add a structure to every existing vertex.
38+
- Bowtie -> clique to every vertex
39+
- The kite problem -> add a tail to every vertex
40+
- Create a "complement" graph
41+
- $\overline{G}$
42+
- Clique and IS are complements of each other
43+
- Be mindful to remember the budget/target.
44+
45+
## Graph Transformation Pitfalls
46+
- Attempting to find the structure in the graph, where finding that structure is NP-Complete.
47+
- Adding edges to every vertex, which may break the induced subgraph
48+
- Forgetting the budget and/or target
49+
- Pseudo-polynomial runtimes that reference the budget or target. If you use $O(g^2)$, make sure to assert $g \le n$.
50+
- Removing added vertices. Example, in the Bowtie problem, the original G may have contained a bowtie. Removing all added vertices doesn't necessarily mean you've converted the bowtie solution to a clique. Make sure the output matches the output for the NP-Complete problem.
51+
52+
## SAT Transformation Ideas
53+
- $(A)$ - Add a unit clause
54+
- $(A \vee \overline{A})$ - Add a tautology.
55+
- "Exactly one of A or B" - $(A \vee B)(\overline{A} \vee \overline{B})$
56+
- "At most one of A or B" - $(\overline{A} \vee \overline{B})$
57+
- "At least one of A or B" - $(A \vee B)$
58+
59+
## SAT Transformation Pitfalls
60+
- Cannot add true/false constants
61+
- Need to maintain CNF
62+
- Variables do not exist in the boolean formula (they're called literals)
63+
- Literals do not exist in the satisfying assignment (they're variables)
64+
65+
## 3SAT Verification Runtime
66+
- $\le 3$ literals per clause
67+
- We can lookup variable assignment in $O(1)$
68+
- There are $m$ clauses.
69+
- We need at most 3 lookups per clause
70+
- $O(3m) = O(m)$
71+
72+
The SAT runtime require $O(nm)$ runtime, since we don't have a restriction on the number of literals per clause, apart from the number of variables ($n$) in the problem.
73+
74+
## Set Transformations
75+
- Create the equivalent sets (e.g. Homework 10)
76+
- Watch out for set membership checks ($O(n)$)
77+
- "Don't worry about optimizing everything with boolean arrays"
78+
- Watch for terms $n$ and $m$. Use $|S|$, $|V|$, $|D|$, etc.
79+
123 KB
Loading
336 KB
Loading
328 KB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 6.17 - Making Change (TODO)
8+
> Given an unlimited supply of coins of denominations $x_1,x_2,...,x_n$, we wish to make change for a value $v$; that is, we wish to find a set of coins whose total value is $v$. This might not be possible: for instance, if the denominations are 5 and 10 then we can make change for 15 but not for 12.
9+
>
10+
> Give an $O(nv)$ dynamic-programming algorithm for the following problem.
11+
12+
**Input:** $[x_1,x_2,...,x_n];\space v$
13+
**Question:** Is it possible to make change for $v$ using coins of denominations $x_1,...,x_n$?

OMSCS/Courses/GA/Practice Problems/7.25 - The Dual of Maximum Flow (TODO).md

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 7.25 - The Dual of Maximum Flow
8+
Consider the following network with edge capacities.
9+
10+
```mermaid
11+
graph LR
12+
13+
S --[1]--> A
14+
A --[1]--> B
15+
S --[3]--> B
16+
A --[2]--> T
17+
B --[1]--> T
18+
```
19+
20+
1. Write the problem of finding the maximum flow from S to T as a linear program.
21+
2. Write down the dual of this linear program. There should be a dual variable for each edge of the network and for each vertex other than $S,T$.
22+
23+
## Max-Flow as LP
24+
This is a laborious process in which we remodel the flow network as a series of equalities, which must then be converted to inequalities to satisfy the format of an LP. We can introduce variables for the in/out flow for each vertex ($S_o,A_i,A_o,B_i,B_o,T_i \ge 0$), but someone on the course forum showed that we can shortcut a little bit by encoding those flows directly from edge to edge.
25+
26+
- Objective: $\max \{AT + BT\}$
27+
- s.t.
28+
- $SA,SB,AB,AT,BT \ge 0$
29+
- $SA \le 1$
30+
- $SB \le 3$
31+
- $AB \le 1$
32+
- $AT \le 2$
33+
- $BT \le 1$
34+
- $SA = AB + AT$
35+
- $SA - AB - AT = 0$
36+
- $SA - AB - AT \le 0$
37+
- $-SA + AB + AT \le 0$
38+
- $SB + AB = BT$
39+
- $SB+AB-BT=0$
40+
- $SB+AB-BT \le 0$
41+
- $-SB-AB+BT \le 0$
42+
43+
$$
44+
\begin{matrix}
45+
\max\{c^Tx\} \\
46+
Ax \le b \\
47+
x \ge 0 \\
48+
49+
\end{matrix} \space\space
50+
x=\begin{bmatrix}SA \\ SB \\ AB \\ AT \\ BT\end{bmatrix} \space\space
51+
c=\begin{bmatrix}0 \\ 0 \\ 0 \\ 1 \\ 1\end{bmatrix}
52+
\space\space
53+
b=\begin{bmatrix}1 \\ 3 \\ 1 \\ 2 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0\end{bmatrix}
54+
\space\space
55+
A=\begin{bmatrix}
56+
1 & 0 & 0 & 0 & 0 \\
57+
0 & 1 & 0 & 0 & 0 \\
58+
0 & 0 & 1 & 0 & 0 \\
59+
0 & 0 & 0 & 1 & 0 \\
60+
0 & 0 & 0 & 0 & 1 \\
61+
1 & 0 & -1 & -1 & 0 \\
62+
-1 & 0 & 1 & 1 & 0 \\
63+
0 & 1 & 1 & 0 & -1 \\
64+
0 & -1 & -1 & 0 & 1 \\
65+
\end{bmatrix}
66+
$$
67+
68+
## Dual LP
69+
$$
70+
\begin{matrix}
71+
\min\{b^Ty\} \\
72+
A^Ty \ge c \\
73+
y \ge 0 \\
74+
75+
\end{matrix} \space : \space
76+
y=\begin{bmatrix}y_1 \\ y_2 \\ y_3 \\ y_4 \\ y_5 \\ y_6 \\ y_7 \\ y_8 \\ y_9 \end{bmatrix} \space\space
77+
c=\begin{bmatrix}0 \\ 0 \\ 0 \\ 1 \\ 1\end{bmatrix}
78+
\space\space
79+
b=\begin{bmatrix}1 \\ 3 \\ 1 \\ 2 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0\end{bmatrix}
80+
\space\space
81+
A=\begin{bmatrix}
82+
1 & 0 & 0 & 0 & 0 \\
83+
0 & 1 & 0 & 0 & 0 \\
84+
0 & 0 & 1 & 0 & 0 \\
85+
0 & 0 & 0 & 1 & 0 \\
86+
0 & 0 & 0 & 0 & 1 \\
87+
1 & 0 & -1 & -1 & 0 \\
88+
-1 & 0 & 1 & 1 & 0 \\
89+
0 & 1 & 1 & 0 & -1 \\
90+
0 & -1 & -1 & 0 & 1 \\
91+
\end{bmatrix}
92+
$$

OMSCS/Courses/GA/Practice Problems/7.26 - Satisfiable System of Linear Inequalities (TODO).md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,29 @@ tags:
55
- Practice
66
---
77
# 7.26 - Satisfiable System of Linear Inequalities (TODO)
8+
9+
In a satisfiable system of linear inequalities
10+
11+
$$\begin{matrix}
12+
a_{11}x_1 + ... + a_{1n}x_n & \le & b_1 \\
13+
& \vdots & \\
14+
a_{m1}x_1 + ... + a_{mn}x_n & \le & b_m \\
15+
\end{matrix}
16+
$$
17+
18+
we describe the $j$th inequality as *forced-equal* if it is satisfied with equality by *every* solution $x=(x_1,...,x_n)$ of the system. Equivalently, $\sum_i a_{ji}x_i \le b_j$ is *not* forced-equal if there exists an $x$ that satisfies the whole system and such that $\sum_i a_{ji}x_i \lt b_j$.
19+
20+
For example, in
21+
$$\begin{matrix}
22+
x_1 + x_2 & \le & 2 \\
23+
-x_1 - x_2 & \le & -2 \\
24+
x_1 & \le & 1 \\
25+
-x_2 & \le & 0 \\
26+
\end{matrix}
27+
$$
28+
29+
the first two inequalities are forced-equal, while the third and fourth are not. A solution $x$ to the system is called *characteristic* if, for every inequality $I$ that is not forced-equal, $x$ satisfies $I$ without equality. In the instance above, such a solution is $(x_1,x_2)=(-1,3)$ for which $x_1 \lt 1$ and $-x_2 \lt 0$ while $x_1+x_2=2$ and $-x_1-x_2=-2$.
30+
31+
1. Show that any satisfiable system has a characteristic solution.
32+
2. Given a satisfiable system of linear inequalities, show how to use linear programming to determine which inequalities are forced-equal, and to find a characteristic solution.
33+

0 commit comments

Comments
 (0)