Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 days ago.
Improve this question
We know that the K-median problem is proved to be NP-Hard. In fault-tolerant K-median problem on an undirected graph G=(V, E):
We are given a set of facilities F⊆ V and a set of demands (or clients) D ⊆ V in a metric space. We can open at most k facilities and then assign each client j to the r_j≥1 facility. Assigning demand j to facility i incurs an assignment cost of d(i, j), where d(i, j) is the shortest path between i and j. Our goal is to minimize the sum of the assignment costs for all clients.
If r_j is uniform, e.g. r_j=3 for all clients, each client should be connected to three facilities. Why the below algorithm does not solve the problem in polynomial time; let's assume r_j =3.
Go through all the vertices in F
For each v ∈ F Calculate the sum of the distance to all clients D
Store this sum value in a variable
Select the first vertext v with minimum sum variable as the first facility to be opened
Select the second vertex v' with minimum sum variable as the second facility to be opened
Select the third vertex v'' with minimum sum variable as the third facility to be opened
Connect all clients to facilities calculated in steps 2,3,4.
Note: This problem was considered in this article , and the authors provided an approximation algorithm for it. Hence, it should be a hard problem. They did not specifically mention the problem to be solved on the graph but mentioned that it should be on metric space. Moreover, they mention the existence of an approximation algorithm even in the uniform case of r_j.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to solve the problem of node/vertices disjoint paths in a directed graph and came to know about the idea of splitting nodes into in and out nodes respectively. I got the idea and how it works and all the related theorem's like menger theorem but still, I'm not sure how to code it in an efficient manner.
Which data structure should I use so that I can split the vertices and still manage to balance the time complexity? Is there any algorithm existing which tells how to approach the code.
Please help or suggest some appropriate link which may help me out.
Thanks
It's quite simple actually. Let's say you have graph as an edge list of pairs u v meaning theres an edge from u to v
If nodes are not integers already use a dictionary/hash/map to reduce them to integers in range 1..n where n is number of nodes.
Now we "split" all nodes, for each node i it will become 2 nodes i and i+n. where i is considered in-node and i+n out-node.
Now graph edges are modified, for every edge u --> v we instead store edge u+n --> v
Also we add edges from each nodes in-node to out-node, i.e. from node i to i+n
We can assign infinity capacities to all edges and capacities of 1 to edges that connect in-node to out-node
Now Node-disjoint paths from some node s to t can be found using any max-flow algorithm (Ford-Fulkerson, Edmonds-Karp, Dinic, etc)
pesudo-code for building residual network:
n = #nodes
for each node i in 1..n:
residual_graph.addEdge(i, i+n, capacity=1);
residual_graph.addEdge(i+n, i, capacity=0);
for each edge (u,v) in graph
residual_graph.addEdge(u+n, v, capacity=+Infinity);
residual_graph.addEdge(v, u+n, capacity=0);
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
suppose we have a weighted grid graph and our problem is to find maximum independent set. There is a greedy algorithm that each time choose the heaviest node and remove it and its neighbors until all nodes of G have been chosen or removed. we want to prove that W(s) >= 1/4 W(T) where S is our greedy result and T is the OPT solution.
let S be the result of our greedy algorithm and T be an arbitrary independent set which can be the OPT. We know that for any T for any node v which belongs to T-S there exist a node v' in S which is neighbor of v and w(v) <= w(v').
Is there any idea to how prove that?
Just use your last statement, and consider T as the maximum independent set and you have this two results :
for every node in T-S like v there exist a node like u in S were W(v) <= W(u).
each node like u in S is at most neighbor of 4 nodes in T.
now use them :)
The desired result can be obtained with the following proof.
Let S be the set generated by the greedy algorithm, let T be an independent set of maximal weight. We will stepwise transform T into S and bound the loss for each transformation step.
Choose v in T\S with maximal weight. By the statement included in the question above, there exists v' in S such that w(v') >= w(v); choose such a v'. Let N be the neighbourhood of v' in T; N contains v and at most 4 vertices (as we have a grid graph). As v was chosen with maximal weight and w(v')>=w(v), we obtain w(v')>=w(N)/4. We set T':=(T\N) and add v' to it. By construction, T' remains an independent set and we have w(T') >= w(T) - (3/4)w(N).
In total, for each exchange step, vertices from T\S get eliminated, but a node from S is added such that the added total weight is at least one quarter of the lost total weight.
Furthermore, the constructed sets N in each step are disjoint, which means that in each step, at least one quarter of w(N) is preserved. In total, as we have constructed S, andS has weight at least (1/4)w(T).
Note that the input graph is not required to be a grid graph but maximum degree 4 is sufficient; furthermore, the proof can be generalized by permitting an abitrary graph, replacing 4 by the maximum degree Δ yielding an approximation ratio of 1/Δ.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am practicing Algorithms problems from my book and came across this one:
You are given a directed network G with n nodes and m edges, a source s, a sink t and a maximum flow f from s to t. Assuming that the capacity of every edge is a positive integer, describe an O(m + n) time algorithm for updating the flow f in each of the following two cases.
(i) The capacity of edge e increases by 1.
(ii) The capacity of edge e decreases by 1.
It seems like it would be as simple as walking through the network flow edges and adjusting flows, but I do not think it is really that simple. Wikipedia only give algorithms that are O(n^2 m) or O(n m^2). Any help or thoughts would be appreciated.
There is a solution here.
Suppose e is an edge between u and v.
Increased capacity
The idea for increasing the capacity is to simply do a DFS in the residual flow graph for a path from s to t.
Decreased capacity
If the edge is unsed in the maximum flow then you are done.
Otherwise, the idea is to see if there is an alternative path from u to v in the residual flow graph. This takes O(n+m). If found, then you can increase the maximum flow by 1.
Otherwise, you need to decrease the flow. You do this by finding a path from u to s along which the flow can increase by 1, and a path from t to v along which the flow can increase by 1.
(The increases are in a reverse direction so this reduces the flow from s to t).
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I have a simple question on DFS and I'm trying to understand how to use it and not how to solve the whole problem. I'm really looking for an explanation and not a solution to my homework.
I'll write down the question first.
"Suppose you have an undirected graph G=(V,E) and let three of its
vertices to be called v1, v2 and v3. Find an algorithm which
determines if these three vertices are part of a clique
(complete graph) (k>=3)"
Now I suppose to use DFS in order to solve it. As far as I understand DFS will let me know if v1, v2 and v3 are in the same strongly connected component. If I'm correct I should also determine if G is also a clique(complete graph).
I read in the internet and I found out that asserting if a graph is clique or not is NP and cannot be solved easily. Am I correct? Am I missing anything? Is there any propery I can use to determine immediately if a graph is comeplete ?
To clarify the confusion about the NP-completeness: checking whether a graph is a clique is not NP-complete; just count the edges and see whether there are n(n-1)/2. What is NP-complete is to find a maximum clique (meaning the subgraph that has the biggest number of vertices and is a clique) or a clique of k vertices in a graph of n vertices (if k is part of the input instead of a fixed number); the latter case is called the clique decision problem.
EDIT: I just realized you asked something regarding strongly connected components as well; that term only applies to directed graphs (i.e. the edges have a direction, which means for two vertices v and w, the edge v->w is not the same as the edge w->v). Cliques are commonly defined on undirected graphs, for which there are only connected components.
If I understood it properly, all you have to check whether these three vertices are connected, i.e., the edges v1-v2, v2-v3 and v3-v1 exists. If they exist, they form a clique of K=3. If at least one of them does not, these three vertices together can not be in a clique of size k>=3.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am working on solving this problem:
Professor Gaedel has written a program that he claims implements Dijkstra’s algorithm.
The program produces v.d and v.π for each vertex v in V. Give an
O.(V + E)-time algorithm to check the output of the professor’s program. It should
determine whether the d and π attributes match those of some shortest-paths tree.
You may assume that all edge weights are nonnegative.
v.d is the shortest distance from starting node to v.
v.π is v's predecessor in the shortest path from starting node to v
My idea is:
For every vertex (i), compare i.d with (i.π).d. If i's predecessor has a larger d value then we cannot have a shortest-path tree.
I believe this can check if the professor's output is not a shortest-path tree, but I don't think it can confirm that the output is a shortest-path tree. I cannot think of a way to do this without more information.
Am I on the right track?
I think this would work
Do a DFS, but instead of following the regular graph edges, follow only the π value for each vertex. You're doing this to produce a topological ordering, so that the first vertex to finish will be the first vertex in the topological ordering. Note that the first vertex in the topo sort you produce will be the "source" vertex that was given to Gaedel's algorithm.
Now that you have a topo ordering, you can relax edges in the most efficient order, just like how you would do it on a DAG.
for each v in topoSortedVerts
if v.d_verify != v.d_Gaedel
//fail
for each u in v.adjacencies
relax(v, u)
if v.d_verify != v.d_Gaedel
//fail
I think you may also need to make sure all V verts are considered, and that the source vertex matches. Maybe. Also, I guess Gaedel's predecessor subgraph induced by the π values could be real jacked up and have all kinds of crazy things wrong with it, but I assume it doesn't.
It is O(V + E) because the outer loop runs V times, and the inner loop runs E times using aggregate analysis.