Skip to content

Commit a34bf91

Browse files
More PPs
1 parent 0e75545 commit a34bf91

5 files changed

Lines changed: 128 additions & 67 deletions

OMSCS/Courses/GA/Practice Problems/8.13 - NP-Complete Spanning Tree Problems (TODO).md

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 8.13 - NP-Complete Spanning Tree Problems
8+
Determine which of the following problems are NP-complete and which are solvable in polynomial time. In each problem you are given an undirected graph $G=(V,E)$, along with...
9+
10+
## Subproblem (a)
11+
> ...a set of nodes $L \subseteq V$, and you must find a spanning tree such that its set of leaves includes the set $L$.
12+
13+
- $G'$ is a copy of $G$
14+
- For all vertices $v \in L$, remove $v$ from $G'$
15+
- Find a spanning tree $T=(V-L,E')$ of $G'$
16+
- For all vertices $u \in L$, find an edge from $u$ to any vertex $v \in (V-L)$, where $(u,v) \in E$. Add $u$ to and $(u,v)$ to $T$.
17+
18+
If any of these steps fail, the problem is not possible.
19+
20+
## Subproblem (b)
21+
> ...a set of nodes $L \subseteq V$, and you must find a spanning tree such that its set of leaves is precisely the set $L$.
22+
23+
This one is NP-Complete, because you can use a graph G and $L=[s,t]$ in order to find an s-t Rudrata Path in G.
24+
25+
## Subproblem (c)
26+
> ...a set of nodes $L \subseteq V$, and you must find a spanning tree such that its set of leaves is included in the set $L$.
27+
28+
This variant is more permissive than Subproblem B, but you can still use $L=[s,t]$ in order to find an s-t Rudrata Path in G. You can't have a spanning tree with less than 2 leaves, so the permissiveness of this problem variant is immaterial.
29+
30+
## Subproblem (d)
31+
> ...an integer $k$, and you must find a spanning tree with $k$ or fewer leaves.
32+
33+
This one is NP-Complete, because you can use a graph G and $k=2$ in order to find a Rudrata Path in G. You can't have a tree with less than 2 leaves, so the "or fewer" permissiveness of this problem variant is immaterial.
34+
35+
## Subproblem (e)
36+
> ...an integer $k$, and you must find a spanning tree with $k$ or more leaves.
37+
38+
The issue with this problem is you need to select a subset of vertices $L \subseteq V$ where $|L| \ge k$ such that $\forall_{u \in L} \exists_{v \in (V-L)} (u,v) \in E$. Essentially, you can't select a vertex to join $L$ if it only connects to vertices which are already in L. If you have a "star" graph $G^*$ with $n$ vertices, and $k=n-1$, the obvious thing to do is let $L$ contain all vertices which aren't the central point. However, if a naive algorithm selects the central vertex first, it won't be able to find a 2nd vertex to add to $L$, requiring backtracking. In the worst case, it keeps coming back to that central vertex, only to find that it can't grow $L$.
39+
40+
We can validate a solution to this variant of the problem by checking the degree of all vertices, and making sure that there are at least $k$ vertices with degree 1. We can also run DFS on the graph to make sure every vertex is reachable from a single starting vertex, and then ensuring that no back-edges exist in $G$. Therefore, this variant of the problem is definitely in NP.
41+
42+
Unclear how to proceed. Thankfully this problem variant isn't even on the list of recommended practice problems.
43+
44+
## Subproblem (f)
45+
> ...an integer $k$, and you must find a spanning tree with exactly $k$ leaves.
46+
47+
This one is NP-Complete, because you can use a graph G and $k=2$ in order to find a Rudrata Path in G.
48+
49+
## Hint
50+
All the NP-completeness proofs are by generalization, except for one.

OMSCS/Courses/GA/Practice Problems/8.15 - Maximum Common Subgraph (TODO).md

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
tags:
3+
- OMSCS
4+
- Algorithms
5+
- Practice
6+
---
7+
# 8.15 - Maximum Common Subgraph
8+
9+
Show that the following problem is NP-complete.
10+
- **Maximum Common Subgraph (MCS)**
11+
- **Input:** Two graphs $G_1=(V_1,E_1)$ and $G_2 = (V_2,E_2)$; a budget $b$.
12+
- **Output:** Two set of nodes $V'_1 \subseteq V_1$ and $V'_2 \subseteq V_2$ whose deletion leaves at least $b$ nodes in each graph, and makes the two graphs identical.
13+
14+
## MCS in NP Notes
15+
How do we validate the solution in P-time?
16+
17+
- Count vertices, make sure they're the same.
18+
- Count edges, make sure they're the same.
19+
- Get vertex degrees, make sure they have the same distribution of vertex degrees.
20+
- If undirected
21+
- Check number/sizes of connected components.
22+
- If directed
23+
- Check SCCs
24+
- Wait, this one might not be verifiable in P-time.
25+
26+
The Graph Isomorphism problem is unknown as whether it's in P or NP-Complete. In the general case, this question if MCS in NP is indeterminate. In the context of this course/problem, we assume that the graphs $G_1$ and $G_2$ were derived from the same set of vertices, and therefore $G_1'$ and $G_2'$ have the same vertex labels.
27+
28+
## MCS in NP
29+
A solution to the MCS problem can be verified through a multi-step polynomial-time process.
30+
31+
- Construct $G'_1$ and $G'_2$ by removing $V_1'$ from $V_1$ and removing $V_2'$ from $V_2$. This step is at worst $O(n^2)$.
32+
- Count the number of vertices in both $G_1'$ and $G_2'$. Make sure the are the same number and equal to $b$. This step is $O(n)$.
33+
- For all vertices in $G_1'$, check that the vertex exists in $G_2'$. This step is at worst $O(n^2)$.
34+
- Count the number of edges in both $G'_1$ and $G'_2$. Make sure this is the same. This step is $O(n+m)$.
35+
- For each edge in $G_1'$, check to make sure that the edge exists in $G_2'$. This step is $O((n+m)^2)$
36+
37+
The overall verification runtime is $O((n+m)^2)$, which is polynomial in the size of $I$. Therefore, the MSC problem is in NP.
38+
39+
## Reduction Idea
40+
- We can easily reduce from Clique problem or the IS problem. We will use the IS problem because I always use the Clique problem.
41+
- Set $G_1=(V_1,E_1)=G=(V,E)$
42+
- Create an IS of size $|V|$ by making a $G_2=(V_2,\emptyset)$, where $|V_2|=|V|$.
43+
- Set $b=g$
44+
- Since $G_2$ contains all possible ISets from 1 to $|V|$, the solution to the MCS problem must be 2 ISs of size $b$, where one of the ISs came from $G$.
45+
- Return $S=V-V'_1$ as a solution to the IS problem.
46+
47+
**A big note**, I originally wrote to create an IS of only size $g$. This presents a problem with the note from earlier, in that the Graph Isomorphism problem is unknown as being part of P or NP-Complete. Therefore, we must create an IS with the same size as $G$, so that an IS in $G$ of size $g$ can be found which has the same vertex labels as the artificially constructed IS.
48+
49+
## Reduction from IS to MCS
50+
We will demonstrate that the IS problem can be reduced to the MCS problem, demonstrating that the MCS problem is in NP-Hard.
51+
52+
### Input Transformation
53+
Take an instance $I=(G=(V,E), g)$ of the IS problem.
54+
55+
- Create $G_1$, a perfect copy of $G$. $O(n+m)$
56+
- Create $G_2$, a copy of $G$ containing all the vertices of $G$, but no edges. $O(n)$
57+
- Set $b=g$. This is $O(1)$
58+
59+
Use $I'=(G_1,G_2,b)$ as the instance of the MCS problem. This transformation requires $O(n+m)$ time, which is polynomial in $|I|$.
60+
61+
### Output Transformation
62+
If there is no solution to the MCS problem, return "no" as the solution to the IS problem.
63+
64+
If there is a solution to the MCS problem, we are given $S=(V'_1, V'_2)$. Create the solution to the IS problem $S'$ by removing all vertices in $V_1'$ from $V$. This requires $O(n^2)$ time at worst.
65+
66+
### Justification
67+
The IS problem seeks to find a subset of vertices $S \subseteq V$ which have no edges between them in $G$, where $|S|=g$. We can find that subset using the MCS problem, by artificially constructing $G_2$ which only contains vertices, and is therefore an IS of size $|V|$. All independent sets in $G$ of any size also exist in $G_2$. Therefore, if we find a common subgraph between $G$ and $G_2$, that common subgraph is an IS. If that subgraph is of size $b=g$, then we have a solution to the IS problem.
68+
69+
If the IS problem has a solution, then there exists an IS in G of size $g$. Therefore, there exists a solution to the MCS problem, because that IS can pair up with the corresponding vertices of $G_2$ to form 2 identical subgraphs.
70+
71+
If the IS problem doesn't have a solution, there there does not exist an IS in G of size $g$. Therefore, there does not exist a solution to the MCS problem, because there is no way to extract a subgraph of G of size $b$ which matches any subgraph of $G_2$ of size $b$.
72+
73+
Therefore, the MCS problem has a solution if-and-only-if the IS problem has a solution.
74+
75+
## Conclusion
76+
We have demonstrated that the MCS problem is in NP, by demonstrating a polynomial time solution verification algorithm. We have also shown that the MCS problem is in NP-Hard, by demonstrating that there exists a reduction from the IS problem to the MCS problem. Therefore, the MCS problem is in NP-Complete.

OMSCS/Courses/GA/Practice Problems/Suggested NP Theory Problems.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ tags:
1010
- **8.10(b-f)**_Proving **NP**-Completeness by generalization._
1111
- [[8.10 - NP-Completeness by Generalization]]
1212
- **8.13(a-d, f)** – Determine which of the following problems are **NP**-Complete...
13-
- [[8.13 - NP-Complete Spanning Tree Problems (TODO)]]
13+
- [[8.13 - NP-Complete Spanning Tree Problems]]
1414
- **8.14** – Clique & Independent Set
1515
- [[8.14 - Clique + IS]]
1616
- **8.15** – Maximum Common Subgraph
17-
- [[8.15 - Maximum Common Subgraph (TODO)]]
17+
- [[8.15 - Maximum Common Subgraph]]
1818
- **8.17** – problem Π
1919
- [[8.17 - Problem Pi]]
2020
- **8.20** – Dominating Set

0 commit comments

Comments
 (0)