graph-theory

What is breadth-first search useful for?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 06:44:04
问题 Usually when I've had to walk a graph, I've always used depth-first search because of the lower space complexity. I've honestly never seen a situation that calls for a breadth-first search, although my experience is pretty limited. When does it make sense to use a breadth-first search? UPDATE : I suppose my answer here shows a situation where I've used a BFS (because I thought was a DFS). I'm still curious to know though, why it was useful in this case. 回答1: When you want to reach a node by

Proof of correctness: Algorithm for diameter of a tree in graph theory

泄露秘密 提交于 2019-11-30 06:18:44
问题 In order to find the diameter of a tree I can take any node from the tree, perform BFS to find a node which is farthest away from it and then perform BFS on that node. The greatest distance from the second BFS will yield the diameter. I am not sure how to prove this, though? I have tried using induction on the number of nodes, but there are too many cases. Any ideas would be much appreciated... 回答1: Let's call the endpoint found by the first BFS x. The crucial step is proving that the x found

What is the meaning of “from distinct vertex chains” in this nearest neighbor algorithm?

女生的网名这么多〃 提交于 2019-11-30 06:14:06
The following pseudo-code is from the first chapter of an online preview version of The Algorithm Design Manual (page 7 from this PDF ). The example is of a flawed algorithm, but I still really want to understand it: [...] A different idea might be to repeatedly connect the closest pair of endpoints whose connection will not create a problem, such as premature termination of the cycle. Each vertex begins as its own single vertex chain. After merging everything together, we will end up with a single chain containing all the points in it. Connecting the final two endpoints gives us a cycle. At any

How do I run graphx with Python / pyspark?

删除回忆录丶 提交于 2019-11-30 04:50:00
I am attempting to run Spark graphx with Python using pyspark. My installation appears correct, as I am able to run the pyspark tutorials and the (Java) GraphX tutorials just fine. Presumably since GraphX is part of Spark, pyspark should be able to interface it, correct? Here are the tutorials for pyspark: http://spark.apache.org/docs/0.9.0/quick-start.html http://spark.apache.org/docs/0.9.0/python-programming-guide.html Here are the ones for GraphX: http://spark.apache.org/docs/0.9.0/graphx-programming-guide.html http://ampcamp.berkeley.edu/big-data-mini-course/graph-analytics-with-graphx

How to graph adjacency matrix using MATLAB

拥有回忆 提交于 2019-11-30 04:20:47
问题 I want to create a plot showing connections between nodes from an adjacency matrix like the one below. gplot seems like the best tool for this. However, in order to use it, I need to pass the coordinate of each node. The problem is that I don't know where the coordinates should be, I was hoping the function would be capable of figuring out a good layout for me. For example here's my output using the following arbitrary coordinates: A = [1 1 0 0 1 0; 1 0 1 0 1 0; 0 1 0 1 0 0; 0 0 1 0 1 1; 1 1

Edge classification in a DFS

為{幸葍}努か 提交于 2019-11-30 03:25:44
According to the book (Intro to Algorithm), in dfs, edges are classified as 4 kinds: Tree Edge, if in edge (u,v), v is first discovered, then (u, v) is a tree edge. Back Edge, if ......, v is discovered already and v is an ancestor, then it's a back edge. Forward Edge, if ......, v is discovered already and v is a descendant of u, forward edge it is. Cross Edge, all edges except for the above three. My question is how can I identify whether v is u's ancestor or descendant when I'm trying to figure out if (u, v) is a back or forward edge? If you really need it, you can check it by maintaining

What is the most efficient way of finding a path through a small world graph?

谁说我不能喝 提交于 2019-11-30 00:33:22
I have a sea of weighted nodes with edges linking clusters of nodes together. This graph follows the typical small world layout. I wish to find a path finding algorithm, which isn't costly on processor power, to find a path along the best possible path where the nodes are the most favorably weighted, the fastest route is not the most important factor. This algorithm, also takes into consideration load bearing, and traffic rerouting. (sidenote: could neural networks be used here?) Thanks I'm looking at ACO . Is there anything better than ACO for this kind of problem? Right the A* algorithm

Prefuse Toolkit: dynamically adding nodes and edges

百般思念 提交于 2019-11-29 23:24:05
Does anyone have experience with the prefuse graph toolkit? Is it possible to change an already displayed graph, ie. add/remove nodes and/or edges, and have the display correctly adapt? For instance, prefuse comes with an example that visualizes a network of friends: http://prefuse.org/doc/manual/introduction/example/Example.java What I would like to do is something along the lines of this: // -- 7. add new nodes on the fly ------------------------------------- new Timer(2000, new ActionListener() { private Node oldNode = graph.nodes().next(); // init with random node public void

Designing a Yahoo Pipes inspired interface [closed]

烂漫一生 提交于 2019-11-29 23:18:01
I really like the interface for Yahoo Pipes ( http://pipes.yahoo.com/pipes/ ) and would like to create a similar interface for a different problem. Are there any libraries that would allow me to create an interface with the same basic look and feel? I especially like how the pipes behave and how they are not just straight lines. Edit: The application would be web-based. I'm open to using Flash or Javascript. WireIt is an open-source javascript library to create web wirable interfaces like Yahoo! Pipes for dataflow applications, visual programming languages or graphical modeling. Wireit uses

How to prevent edges in graphviz to overlap each other

瘦欲@ 提交于 2019-11-29 22:48:35
I have a graph I've created in graphviz, but the problem is that edges overlap each other (I have 5-7 nodes in each row), so it is hard to tell for each node which are the nodes it connects. How can I make the edges not to overlap each other? Have them cross each other is OK. I'm assuming you have a directed graph which you layout with dot. I don't think there's a magic switch to prevent overlapping edges. Graphviz tries to do that out of the box. Some suggestions that may help, depending on the graph: edge concentrators (concentrate=true): Merge multiple edges with a common endpoint into