graph-theory

Minimal addition to strongly connected graph

二次信任 提交于 2019-12-22 03:23:40
问题 I have a set of nodes and set of directed edges between them. The edges have no weight. How can I found minimal number of edges which has to be added to make the graph strongly connected (ie. there should be a path from every node to all others)? Does this problem have a name? 回答1: It's a really classical graph problem. Run algorithm like Tarjan-SCC algorithm to find all SCCs. Consider each SCC as a new vertice, link a edge between these new vertices according to the origin graph, we can get

Will a source-removal sort always return a maximal cycle?

霸气de小男生 提交于 2019-12-21 21:18:37
问题 I wrote a source-removal algorithm to sort some dependencies between tables in our database, and it turns out we have a cycle. For simplicity, let's say we have tables A, B, C, and D. The edges are like this: (A, B) (B, A) (B, C) (C, D) (D, A) As you can see, there are two cycles here. One is between A and B and another is between all four of them. Will this type of sort always choke on the largest cycle? Or is that not necessarily the case? 回答1: By source-removal I presume you mean at each

Finding shortest path in two dimensional array (Javascript)

久未见 提交于 2019-12-21 18:37:27
问题 I am trying to implement an algorithm, that finds the shortest path in the following two dimensional array (from the top left corner, to the right bottom corner): [ [ 'A', 'A', 'A', 'B', 'A' ], [ 'B', 'B', 'B', 'B', 'B' ], [ 'A', 'B', 'A', 'A', 'A' ], [ 'A', 'B', 'B', 'B', 'B' ], [ 'A', 'A', 'A', 'A', 'A' ] ] The rules are, that the path must alternate between A's and B's. The output must be a number specifying the smallest number of steps it will take to go through the array. (In the example

Finding shortest path in two dimensional array (Javascript)

风流意气都作罢 提交于 2019-12-21 18:36:02
问题 I am trying to implement an algorithm, that finds the shortest path in the following two dimensional array (from the top left corner, to the right bottom corner): [ [ 'A', 'A', 'A', 'B', 'A' ], [ 'B', 'B', 'B', 'B', 'B' ], [ 'A', 'B', 'A', 'A', 'A' ], [ 'A', 'B', 'B', 'B', 'B' ], [ 'A', 'A', 'A', 'A', 'A' ] ] The rules are, that the path must alternate between A's and B's. The output must be a number specifying the smallest number of steps it will take to go through the array. (In the example

Algorithm for Grouping

孤人 提交于 2019-12-21 17:28:52
问题 I am trying to help someone write a program that I thought would be easy, but of course it never is :) I am trying to take a class roster (usually between 10-20 students) and effectivly uniquely pair off each classmate to another to make unique groups. Therefore in a class of 10 people, you can have 9 groups. It needs to be able to handle odd number of students too, adding to my confusion. I was looking at doing this in Java, but that is flexible. Any ideas on an algorithmic way to guarantee

Drawing a Web Graph [closed]

这一生的挚爱 提交于 2019-12-21 09:14:08
问题 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 last year . I'm trying to draw a graph on an ASP webpage. I'm hoping an API can be helpful, but so far I have not been able to find one. The graph contains labeled nodes and unlabeled directional edges. The ideal output would be something like this. Anybody know of anything pre-built than can help? 回答1: Definitely graphviz.

Elegant examples of xslt?

为君一笑 提交于 2019-12-21 05:30:15
问题 After a long learning loop via XAML, I've returned to HTML and javascript, and realised that the concept of declarative code - in terms of rules for transformation - is an incredibly powerful concept. Despite its surfeit of syntax, XSLT processing of XML is the keystone of declarative transformation programming. I have, however, always found it hard to understand how XSLT would be used for everyday tasks (with XML). What are some good examples of XSLT elegantly solving a programming problem,

Get visited edges in OrientDB's shortestPath()

不打扰是莪最后的温柔 提交于 2019-12-21 04:55:30
问题 I am new to OrientDB and I want to use the new shortestPath() method to get the edges that are between two vertices. What I do is: OSQLSynchQuery<T> sql = new OSQLSynchQuery<T>("select shortestpath(" + firstVertex + ", " + secondVertex + ").asString()"); List<ODocument> execute = db.query(sql); and what I can only get is [#-2:1{shortestpath:[#8:1, #8:3]} v0] . So, I wanted to know how could I extract the edges (well, only one edge in this case, because these two vertices are directly

Does it Make Sense to Map a Graph Data-structure into a Relational Database?

巧了我就是萌 提交于 2019-12-21 04:50:26
问题 Specifically a Multigraph. Some colleague suggested this and I'm completely baffled. Any insights on this? 回答1: It's pretty straightforward to store a graph in a database: you have a table for nodes, and a table for edges, which acts as a many-to-many relationship table between the nodes table and itself. Like this: create table node ( id integer primary key ); create table edge ( start_id integer references node, end_id integer references node, primary key (start_id, end_id) ); However,

Divide-And-Conquer Algorithm for Trees

大兔子大兔子 提交于 2019-12-21 04:30:45
问题 I am trying to write a divide & conquer algorithm for trees. For the divide step I need an algorithm that partitions a given undirected Graph G=(V,E) with n nodes and m edges into sub-trees by removing a node . All subgraphs should have the property that they don't contain more than n/2 nodes (the tree should be split as equal as possible). First I tried to recursively remove all leaves from the tree to find the last remaining node, then I tried to find the longest path in G and remove the