graph-theory

How to compute a minimum bottleneck spanning tree in linear time?

こ雲淡風輕ζ 提交于 2019-12-03 08:51:30
问题 We can find a minimum bottleneck spanning tree in O(E log*V) in the worst case by using Kruskal's algorithm. This is because every minimum spanning tree is a minimum bottleneck spanning tree. But I got stuck on this job-interview question from this course. How can we find a minimum bottleneck spanning tree in linear time even in the worst case. Note that we can assume that we can compute the median of n keys in linear time in the worst case. 回答1: Get V , the median of the weights of the |E|

How to serialize a graph structure?

泄露秘密 提交于 2019-12-03 08:21:48
问题 Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data. But many problems are best represented by graphs. A thermal simulation program will, for instance, work with temperature nodes connected to each others through resistive edges. So what is the best way to serialize a graph structure? I know XML can, to some extent, do it---in the same way that a relational database can serialize a complex web of

How to delete all related nodes in a directed graph using networkx?

谁说胖子不能爱 提交于 2019-12-03 07:53:45
I'm not sure exactly sure what the correct terminology is for my question so I'll just explain what I want to do. I have a directed graph and after I delete a node I want all independently related nodes to be removed as well. Here's an example: Say, I delete node '11', I want node '2' to be deleted as well(and in my own example, they'll be nodes under 2 that will now have to be deleted as well) because its not connected to the main graph anymore. Note, that node '9' or '10' should not be deleted because node '8' and '3' connect to them still. I'm using the python library networkx. I searched

count of distinct acyclic paths from A[a,b] to A[c,d]?

梦想与她 提交于 2019-12-03 07:24:56
问题 I'm writing a sokoban solver for fun and practice, it uses a simple algorithm (something like BFS with a bit of difference). now i want to estimate its running time ( O and omega). but need to know how to calculate count of acyclic paths from a vertex to another in a network. actually I want an expression that calculates count of valid paths, between two vertices of a m*n matrix of vertices. a valid path: visits each vertex 0 or one times. have no circuits for example this is a valid path:

How do you solve the 15-puzzle with A-Star or Dijkstra's Algorithm?

人盡茶涼 提交于 2019-12-03 07:11:52
问题 I've read in one of my AI books that popular algorithms (A-Star, Dijkstra) for path-finding in simulation or games is also used to solve the well-known "15-puzzle". Can anyone give me some pointers on how I would reduce the 15-puzzle to a graph of nodes and edges so that I could apply one of these algorithms? If I were to treat each node in the graph as a game state then wouldn't that tree become quite large? Or is that just the way to do it? 回答1: A good heuristic for A-Star with the 15

Undirected graph conversion to tree

拜拜、爱过 提交于 2019-12-03 07:10:27
Given an undirected graph in which each node has a Cartesian coordinate in space that has the general shape of a tree, is there an algorithm to convert the graph into a tree, and find the appropriate root node? Note that our definition of a "tree" requires that branches do not diverge from parent nodes at acute angles. See the example graphs below. How do we find the red node? collapsar here is a suggestion on how to solve your problem. prerequisites notation: g graph, g.v graph vertices v,w,z : individual vertices e : individual edge n : number of vertices any combination of an undirected

Algorithm for solving this distributing beads puzzle?

你说的曾经没有我的故事 提交于 2019-12-03 06:56:38
Lets say you have a circle (like below) with N spots, and you have N beads distributed in the slots. Here's an example: Each bead can be moved clockwise for X slots, which costs X^2 dollars. Your goal is to end up with one bead in each slot. What is the minimum amount of money you have to spend to achieve this task? More interesting variation of this problem: Algorithm for distributing beads puzzle (2)? In this answer I assume beads can only be moved once. Otherwise it would be evident that beads should only move one square at a time, which makes this problem much less interesting: the sum of

Algorithm for determining if 2 graphs are isomorphic

空扰寡人 提交于 2019-12-03 06:56:14
Disclaimer: I'm a total newbie at graph theory and I'm not sure if this belongs on SO, Math SE, etc. Given 2 adjacency matrices A and B, how can I determine if A and B are isomorphic. For example, A and B which are not isomorphic and C and D which are isomorphic. A = [ 0 1 0 0 1 1 B = [ 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 1 0 ] 0 0 0 1 1 0 ] C = [ 0 1 0 1 0 1 D = [ 0 1 0 1 1 0 1 0 1 0 0 1 1 0 1 0 1 0 0 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 1 1 0 0 1 0 ] 0 0 1 1 1 0 ] (sorry for this

Looking for algorithm finding euler path

吃可爱长大的小学妹 提交于 2019-12-03 06:52:20
I'm looking for an algorithm to find an Euler path in a graph. I've seen a good one a couple of weeks ago but I can't find it now, I remember there was tagging edges, something with even/odd connections... Do you know a similar, simple and straightforward algorithm? MJW From Graph-Magics.com , for an undirected graph, this will give you the tour in reverse order, i.e. from the end vertex to the start vertex: Start with an empty stack and an empty circuit (eulerian path). If all vertices have even degree: choose any of them. This will be the current vertex. If there are exactly 2 vertices

Seeking algorithm to invert (reverse? mirror? turn inside-out) a DAG

女生的网名这么多〃 提交于 2019-12-03 06:17:16
问题 I'm looking for an algorithm to "invert" (reverse? turn inside-out?) a DAG: A* # I can't ascii-art the arrows, so just / \ # pretend the slashes are all pointing B C # "down" (south-east or south-west) / / \ # e.g. G E D # A -> (B -> G, C -> (E -> F, D -> F)) \ / F The representation I'm using is immutable truly a DAG (there are no "parent" pointers). I'd like to traverse the graph in some fashion while building a "mirror image" graph with equivalent nodes, but with the direction of relations