graph-theory

Expected number of Edges required to make a graph connected if the vertices are joined randomly?

ぐ巨炮叔叔 提交于 2019-12-05 23:21:29
问题 We select two vertices randomly and connect them. So what is the expected number of edges in the graph when it becomes connected ? I tried solving it using induction but couldn't reach to an answer. What will be the right approach to this problem ? 回答1: For given number of vertices n and chosen count of edges, you get the probability of the graphs connectedness as the proportion of connected graphs to all graphs. Number of all graphs is the combination number of m over n * ( n - 1).

How to find the distance between the two most widely separated nodes

为君一笑 提交于 2019-12-05 20:20:13
I'm working through previous years ACM Programming Competition problems trying to get better at solving Graph problems. The one I'm working on now is I'm given an arbitrary number of undirected graph nodes, their neighbors and the distances for the edges connecting the nodes. What I NEED is the distance between the two farthest nodes from eachother (the weight distance, not by # of nodes away). Now, I do have Dijkstra's algorithm in the form of: // Dijkstra's Single-Source Algorithm private int cheapest(double[] distances, boolean[] visited) { int best = -1; for (int i = 0; i < size(); i++) {

identifying connected graphs given edges

杀马特。学长 韩版系。学妹 提交于 2019-12-05 20:01:55
How do I group people who are related, even indirectly? Concretely, using the first two columns of the data set like below, how do I in SAS (maybe using a DATA step or PROC SQL) programmatically derive the third column? Is there a non-iterative algorithm? Background: Each person has multiple addresses. Through each address, each person is connected to zero or more persons. If two people are connected, they get the same group ID. If person A is directly connected to B and B is connected to C, then persons A, B, and C share a group. data people; input person_id address_id $ household_id;

Finding all possible paths in graph

大兔子大兔子 提交于 2019-12-05 18:08:57
I'm looking for some algorithm which will help me find all possible paths in a graph. Everything I found so far is not fully satisfying. Let's imagine we have a graph (tree) like this one: And let's use some algorithm like Breadth-First Search or Depth-First Search . In return we'll get something like 1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9 Which is how we go through this tree and this is not what I'm looking for. I'd love to get all paths, like: 1 1, 2 1, 2, 4 1, 2, 5 1, 2, 6 1, 3 1, 3, 7 1, 3, 7, 8 1, 3, 7, 9 The thing is that I want just to specify root node and algorithm should

Shortest sequence of nodes though an unweighted graph

会有一股神秘感。 提交于 2019-12-05 16:41:54
I would like to know if there is an algorithm for finding the shortest sequence of nodes though a graph from its a head node to the tail node. The graph branches out from the head node and is arbitrarily complex and converges at the tail node. All connections between nodes are unweighted. I'm considering tackling this problem taking exploratory steps from the head and tail nodes and until the nodes from either end of the graph touch etc, but I'd like to know if a "better wheel" exists before I (re)invent one. Use breadth first search , which runs in O(E+V). It's the fastest you'll get on an

Cliques in python

不问归期 提交于 2019-12-05 15:54:47
I have this problem and I need help with it, this is my code: cliques=[clique for clique in nx.find_cliques(GC) if len(clique)>2] for clique in cliques: if len (clique)==3: GC.remove_edge() print "Clique to appear: ",clique #draw the graph nx.draw(GC) plt.show() first I searched in my graph to find cliques, after that I test if the clique of length 3, if its true I want to delete one edge So I can eliminate complete-graph(3). How can I do that? Thanks I think the trickiest problem here is dealing with shared edges. You don't want to search for cliques each time you remove an edge, and yet you

Using the apriori algorithm for recommendations

让人想犯罪 __ 提交于 2019-12-05 15:16:52
So a recent question made me aware of the rather cool apriori algorithm . I can see why it works, but what I'm not sure about is practical uses. Presumably the main reason to compute related sets of items is to be able to provide recommendations for someone based on their own purchases (or owned items, etcetera). But how do you go from a set of related sets of items to individual recommendations? The Wikipedia article finishes: The second problem is to generate association rules from those large itemsets with the constraints of minimal confidence. Suppose one of the large itemsets is Lk, Lk =

Fastest Path with Acceleration at Points

感情迁移 提交于 2019-12-05 14:24:12
问题 This is just something I came up with on my own, but it seems like a fun problem and it has me stumped. You have a set of points in two-dimensional space, with one point designated "Start" and one "End". Each point has coordinates (in meters from the origin), but also an "acceleration number" (in meters/second of delta-V). Upon reaching a point (including the start), you may accelerate by up to that point's acceleration number in any direction. Edge cost is dependent on your current speed,

how to import matplotlib in python

假装没事ソ 提交于 2019-12-05 13:51:32
问题 I am new to python and I am working on a graph problem and I want to draw this graph to have a better understanding of it. I learnt that matplotlib module is supposed to be imported for this but I dont know how to add it to the project.(I am a java developer and It is pretty much like adding jar to your classpath) When I try doing import matplotlib I get the following error: File "/Library/Python/2.7/site-packages/networkx-1.7rc1-py2.7.egg/networkx/drawing/nx‌​_pylab.py", line 114, in draw

Updating Shortest path distances matrix if one edge weight is decreased

会有一股神秘感。 提交于 2019-12-05 13:17:49
We are given a weighed graph G and its Shortest path distance's matrix delta. So that delta(i,j) denotes the weight of shortest path from i to j (i and j are two vertexes of the graph). delta is initially given containing the value of the shortest paths. Suddenly weight of edge E is decreased from W to W'. How to update delta(i,j) in O(n^2)? (n=number of vertexes of graph) The problem is NOT computing all-pair shortest paths again which has the best O(n^3) complexity. the problem is UPDATING delta, so that we won't need to re-compute all-pair shortest paths. More clarified : All we have is a