Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
320 changes: 320 additions & 0 deletions Submissions/002682716_Zhenhao_Chen-Assignment-4/Assignment-4.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,320 @@
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Zhenhao Chen 002682716"
],
"metadata": {
"collapsed": false
},
"id": "ab79e5c38863b237"
},
{
"cell_type": "markdown",
"source": [
"# Q1\n",
"#### Given a directed graph G = (V,E), where V is the set of vertices and E is the set of directed edges, the Directed Hamiltonian Cycle Cover problem is to determine whether there exists a collection of vertex-disjoint Hamiltonian cycles that cover all vertices in the graph.\n",
"\n",
"#### Decision Problem Formulation:\n",
"##### Input: A directed graph G=(V,E)\n",
"##### Output: Yes if there exists a set of vertex-disjoint Hamiltonian cycles covering all vertices, and No otherwise.\n",
"\n",
"#### Determine whether the Directed Hamiltonian Cycle Cover problem is in P, NP, or NP-complete."
],
"metadata": {
"collapsed": false
},
"id": "f401d201bf528493"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### The Directed Hamiltonian Cycle Cover problem is in NP-complete.\n",
"\n",
"#### To show this, we reduce from Hamiltonian Cycle.\n",
"#### Given an example of the Hamiltonian Cycle problem, which is to determine whether there exists a Hamiltonian cycle in an undirected graph. The undirected graph G has:\n",
"#### 4 vertices: {A, B, C, D}.\n",
"#### 4 edges: {(A, B), (B, C), (C, D), (D, A)}.\n",
"#### Now, for each edge (vi, vj) in G, we create two edges in the new directed graph G'. Then we have:\n",
"#### 4 vertices: {A', B', C', D'}.\n",
"#### 8 edges: {(A', B'), (B', A'), (B', C'), (C', B'), (C', D'), (D', C'), (D', A'), (A', D')}.\n",
"\n",
"#### we can see:\n",
"#### Undirected Hamiltonian Cycle: (A, B, C, D, A).\n",
"#### Corresponding Directed Hamiltonian Cycle Cover in G': (A', B', C', D', A'). \n",
"\n",
"#### Clearly, The reduction is polynomial time. In this way, if the original Undirected graph has a Hamiltonian cycle, the corresponding Directed Hamiltonian Cycle Cover in G' represents the same cycle through the directed edges. If there does not exist Hamiltonian cycle in the undirected original graph, there is no Directed Hamiltonian Cycle Cover in G'. Since the Hamiltonian Cycle is NP-Complete problem, the Directed Hamiltonian Cycle Cover problem is NP-complete. "
],
"metadata": {
"collapsed": false
},
"id": "5dc6adf07ad0d8d0"
},
{
"cell_type": "markdown",
"source": [
"# Q2\n",
"#### Given an undirected graph G=(V,E) and an integer k, the Maximum Clique Problem requires finding a maximum clique in G with at least k vertices.\n",
"\n",
"#### Decision Problem Formulation:\n",
"##### Input: An undirected graph G=(V,E) and an integer k.\n",
"##### Output: Yes if there exists a clique in G with at least k vertices; otherwise, No.\n",
"\n",
"#### Prove that the Maximum Clique Problem is NP-complete."
],
"metadata": {
"collapsed": false
},
"id": "12d75a3037edc856"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### The Maximum Clique Problem is NP-complete.\n",
"\n",
"#### To show this, we reduce from 3-SAT.\n",
"\n",
"#### Give a 3-SAT example with a clause set C = {C1, C2, C3,...,Cm). For r = 1,2,...,k, each clause Cr = (lr1 ∨ lr2 ∨ lr3), lri is Xi or ¬Xi.\n",
"\n",
"#### A graph can be constructed as follows. For each Cr, create a triple of vertices V1r, V2r, V3r, and create edges between Vir and Vjs if and only if: they are in different triples, i.e. r ≠ s, and they do not correspond to literals negating each other.\n",
"\n",
"#### C = (X1 ∨ ¬X2 ∨ ¬X3) ∧ (¬X1 ∨ X2 ∨ X3) ∧ (X1 ∨ X2 ∨ X3).\n",
"\n",
"![](./Q2.png)\n",
"\n",
"#### In this graph, one satisfying assignment is X1 = 1, X2 = 1/0, X3 = 1. For corresponding clique, pick one \"true\" literal from each triple.\n",
"\n",
"\n",
"#### Suppose that C has a satisfying assignment. Then there is at least one \"true\" literal in each clause. Picking such a literal from each clause, their corresponding vertices in G can be proved to be a clique. since any two of them are in different triples and cannot be complements to each other cause they are both true.\n",
"\n",
"#### Therefore, C, with k clauses, is satisfiable if and only if the graph G has a clique of size k.\n",
"\n",
"\n",
"#### Clearly, the reduction is polynomial time. Since 3-SAT is NP-complete problem, the Maximum Clique problem is NP-complete."
],
"metadata": {
"collapsed": false
},
"id": "30abe8b42f2bdefa"
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
},
"id": "b2ef3e7e17655305"
},
{
"cell_type": "markdown",
"source": [
"# Q3\n",
"#### Given a directed graph G and an integer k, the Directed Disjoint Cycles Enumeration problem is defined as follows: Determine whether there exist k disjoint cycles in the graph.\n",
"\n",
"#### Decision Problem Formulation:\n",
"##### Input: A directed graph G=(V,E) and an integer k.\n",
"##### Output: Yes if there exist k disjoint cycles in G, and No otherwise.\n",
"\n",
"#### Determine whether the Directed Disjoint Cycles Enumeration problem is in P, NP, or NP-complete.\n"
],
"metadata": {
"collapsed": false
},
"id": "182c793cfda81395"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### The Directed Disjoint Cycles Enumeration problem is in NP-complete.\n",
"\n",
"#### To show this, we reduce from Directed Disjoint Paths.\n",
"\n",
"#### Given an example of Directed Disjoint Paths, for each pair of nodes(si, ti), add a dummy node ui and connect it with directed edges(si, ui) and (ui, ti). let's set k in the Directed Disjoint Cycles Enumeration to be equal to the number of pairs in the Directed Disjoint Paths.\n",
"\n",
"#### If there exist disjoint paths P1, P2, P3,...Pk in the Directed Disjoint Paths, then the introduction of dummy nodes allows these paths to form disjoint cycles in the Directed Disjoint Cycles Enumeration instance. If there exist k disjoint cycles in the Directed Disjoint Cycles Enumeration instance, removing the dummy nodes produces k disjoint paths in the original Directed Disjoint Paths instance.\n",
"\n",
"#### Clearly, the reduction is polynomial time. Since the Directed Disjoint Path is NP-complete problem, the Directed Disjoint Cycles Enumeration is NP-complete."
],
"metadata": {
"collapsed": false
},
"id": "87604489b28d93e9"
},
{
"cell_type": "markdown",
"source": [
"# Q4\n",
"#### You are tasked with allocating facilities to cover a set of services in a city. There are n facilities, each having specific capabilities or services it can provide. You have received job applications from m potential facility operators. For each of the services, there is a subset of potential operators qualified to manage it. The question is: For a given number k ≤ m, is it possible to allocate at most k facilities that can cover all the services? We'll call this the Optimal Facility Allocation."
],
"metadata": {
"collapsed": false
},
"id": "2dab9d781c2b50c9"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### Each facility corresponds to a specific service, and potential operators are qualified to manage one or more services based on their capabilities. Our goal is to determine whether we can cover all the services efficiently, with at most k facility operators. \n",
"#### The problem is in NP, as given a set of k facility operators, it can be verified in linear time whether each service is covered.\n",
"\n",
"#### To show the problem is NP-complete, we can reduce from the Set Cover problem.\n",
"#### In an Set Cover example, given a set U of n elements and a collection of m subsets of U, we ask whether there are at most k of these sets whose union is equal to all of U.\n",
"#### Construct an instance of the Optimal Facility Allocation as follows: For each element of U, create a specific service. For each of the m subsets, create a facility operator, and let this operator be qualified to manage the services that are elements of this subset.\n",
"#### There are k facility operators that can cover all the services if and only if there are k subsets whose union is U.\n",
"#### Clearly, the reduction takes polynomial time. Since the Set Cover is in NP-complete, the Optimal Facility Allocation is an NP-complete problem."
],
"metadata": {
"collapsed": false
},
"id": "c38a0ea1b3f1d696"
},
{
"cell_type": "markdown",
"source": [
"# Q5\n",
"#### You are managing a set of resources that need to be allocated to various projects within a company. There are n resources, each with specific capabilities or skills. You have received applications from m potential project managers. For each skill, there is a subset of potential project managers qualified to handle it. The question is: For a given number k ≤ m, is it possible to allocate at most k project managers who can cover all the required skills for all projects? We'll call this the Efficient Resource Allocation Puzzle.\n"
],
"metadata": {
"collapsed": false
},
"id": "6d4e1005e0adc998"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### Each resource corresponds to a specific skill, and potential project managers are qualified to handle one or more skills based on their capabilities. Our goal is to determine if we can efficiently cover all the required skills for the projects with at most k project managers.\n",
"#### The problem is in NP, as given a set of k project managers, it can be verified in linear time whether each required skill is covered.\n",
"\n",
"#### To show the problem is NP-complete, we can reduce from the Vertex Cover problem.\n",
"#### In Vertex Cover, given an undirected graph G and an integer k, we ask whether there exists a vertex cover of size at most k.\n",
"#### Construct an instance of the Efficient Resource Allocation Puzzle as follows: For each vertex in G, create a specific skill. For each edge in G, create a project manager, and let this manager be qualified to handle the skills corresponding to the vertices connected by the edge.\n",
"#### There are k project managers that can cover all the required skills if and only if there exists a vertex cover of size at most k in G.\n",
"#### Clearly, the reduction takes polynomial time. Since the Vertex Cover is in NP-complete, the Efficient Resource Allocation Puzzle is NP-complete."
],
"metadata": {
"collapsed": false
},
"id": "f7131d54cc81929d"
},
{
"cell_type": "markdown",
"source": [
"# Q6\n",
"#### For each of the two questions below, decide whether the answer is (i) “Yes,” (ii) “No,” or (iii) “Unknown, because it would resolve the question of whether P = NP.” Give a brief explanation of your answer.\n",
"#### (a) Is it the case that Minimum Dominating Set ≤P Minimum Vertex Cover?\n",
"#### (b) Is it the case that Independent Set ≤P Interval Scheduling?"
],
"metadata": {
"collapsed": false
},
"id": "830b0ed85184cab4"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### (a)\n",
"#### In the Minimum Dominating Set problem, the task is to find the smallest set of vertices in a graph such that every vertex in the graph is either in the dominating set or adjacent to a vertex in the dominating set. This problem can be polynomial-time reduced to the Minimum Vertex Cover problem.\n",
"#### Given an instance of the Minimum Dominating Set problem (graph G), construct a new graph G' by adding a new vertex for each edge in G. Connect these new vertices to their corresponding endpoints in G. Now, finding the Minimum Vertex Cover in G' is equivalent to finding the Minimum Dominating Set in G.\n",
"#### Therefore, Minimum Dominating Set ≤P Minimum Vertex Cover, implying that if we can efficiently solve Minimum Vertex Cover, we can also efficiently solve Minimum Dominating Set.\n",
"\n",
"#### (b)\n",
"#### To show Independent Set ≤P Interval Scheduling, we can perform a polynomial-time reduction from Independent Set to Interval Scheduling. Given an instance of the Independent Set problem (a graph G and an integer k), we construct an equivalent instance of Interval Scheduling. Assign each vertex in G a corresponding unit-length interval on the timeline. Connect intervals (vertices) with edges if there is an edge between the corresponding vertices in G. Set k equal to the size of the maximum independent set in G. Solving the resulting Interval Scheduling instance will yield a solution to the Independent Set problem.\n",
"#### Therefore, Independent Set ≤P Interval Scheduling.\n",
"\n"
],
"metadata": {
"collapsed": false
},
"id": "cfc6deb7ff31ff3e"
},
{
"cell_type": "markdown",
"source": [
"# Q7\n",
"#### In the RANDOMIZED-EDGE-COLORING problem, you are given an undirected graph G=(V,E) with positive weights assigned to each edge. The objective is to assign colors to the edges of the graph in such a way that every vertex is incident to at least one differently colored edge, and the expected number of colors used is minimized.\n",
"\n",
"#### (a) Propose a randomized algorithm for solving the RANDOMIZED-EDGE-COLORING problem. Outline the key steps of your algorithm.\n",
"#### (b) Analyze the algorithm's performance. Can you provide a bound on the expected number of colors used with respect to the minimum number of colors required for a valid edge coloring? If so, prove the bound.\n",
"#### (c) Consider practical applications where the RANDOMIZED-EDGE-COLORING problem might be relevant. How could minimizing the expected number of colors used in edge coloring be beneficial in real-world scenarios?\n"
],
"metadata": {
"collapsed": false
},
"id": "52747ae68f46cd7e"
},
{
"cell_type": "markdown",
"source": [
"### Ans:\n",
"#### (a)\n",
"```\n",
"Initialize an empty set of colors C.\n",
"Create a list of edges with weights [(u, v, w_uv)](w_uv means the weight of edge (u, v)) for each edge (u, v) in E.\n",
"Sort the list of edges in non-decreasing order of weights\n",
"\n",
"for each edge (u, v, w_uv) in the sorted list:\n",
" Randomly choose a color for the edge that is not in C.\n",
" Add the chosen color to C.\n",
"\n",
"Return the set of colors C.\n",
"\n",
"```\n",
"\n",
"#### (b)\n",
"#### To analyze the performance, we can consider proving a bound on the expected number of colors used (E[∣C∣]) with respect to the minimum number of colors required for a valid edge coloring (∣C*∣).\n",
"#### Claim: E[∣C∣] ≤ 2 * max(Wu / Wu + Wv, Wv / Wu + Wv) * ∣C*∣.\n",
"#### proof: Similar to the previous analysis, we consider the probability of increasing the number of colors by 1 in each iteration of the algorithm. For each edge (u,v,Wuv), the probability of choosing vertex u is Wu / (Wu + Wv), and the probability of choosing vertex v is Wv / (Wu + Wv).\n",
"\n",
"#### In communication networks, minimizing the number of 'colors' used for communication edges can enhance bandwidth efficiency and reduce interference."
],
"metadata": {
"collapsed": false
},
"id": "809e1d698d9d083b"
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
},
"id": "8ee38e9301ae5757"
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
},
"id": "58bf5902e62bcc2e"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
First Name: Zhenhao
Last Name : Chen
NU_ID : 002682716

Assignment-4 : Reflection of assignment 4

How ChatGPT or the tool you used assisted in this task:
I used ChatGPT to assist me in this task. It's really a cool tool for us to create something and learn something. When I have confusion about the sample questions, ChatGPT could provide me with explanations. Especially when it comes to NP-complete problems, ChatGPT could always some creative problems. All the problems it generated for me can greatly enhance my understanding to these concepts.

Challenges you faced while ensuring the problem maintained the spirit of the example:
It's a little difficult when I tried to figured out problems in the example pdf, cause they are just too abstract and contained a lot arithmetic. The basic concept is easy to understand and the basic reduction is easy to practice. However, there are too many complex problems. Sometimes in the creation of my own problems, I needed to check ChatGPT with the answers.

What you learned about problem design in the realm of algorithms:
- The most important thing that I've learned is that a well-designed algorithmic problem is clear and precisely defined. Ambiguity can lead to confusion and difficulties in understanding the problem's requirements. Therefore, it's of great essential to provide a clear and unambiguous problem statement.
- Moreover, it's also helpful to provide clear sample input and output since they clarify the problem's requirements.
- Those problems related to NP, NP-complete can really lead to practical applications.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.