graph-algorithm

Minimum number of days required to solve a list of questions

↘锁芯ラ 提交于 2019-11-27 21:41:33
There are N problems numbered 1..N which you need to complete. You've arranged the problems in increasing difficulty order, and the ith problem has estimated difficulty level i. You have also assigned a rating vi to each problem. Problems with similar vi values are similar in nature. On each day, you will choose a subset of the problems and solve them. You've decided that each subsequent problem solved on the day should be tougher than the previous problem you solved on that day. Also, to not make it boring, consecutive problems you solve should differ in their vi rating by at least K. What is

Why can't Prim's or Kruskal's algorithms be used on a directed graph?

和自甴很熟 提交于 2019-11-27 20:13:19
问题 Prim's and Kruskal's algorithms are used to find the minimum spanning tree of a graph that is connected and undirected. Why can't they be used on a graph that is directed? 回答1: It's a minor miracle that these algorithms work in the first place -- most greedy algorithms just crash and burn on some instances. Assuming that you want to use them to find a minimum spanning arborescence (directed paths from one vertex to all others), then one problematic graph for Kruskal looks like this. 5 --> a /

How to generate a maze with more than one successful path?

守給你的承諾、 提交于 2019-11-27 19:21:54
问题 Which algorithm can be used to generate a maze with more than one successful path and if algorithm is modified version of some well known algorithm then explain or add a link . I am using 2D array A to store configuration of maze . Assume if the size of maze is n * n then more than one path should be there from A[0][0] to A[n-1][n-1] . 回答1: This algorithms should be able to generate mazes with distinct loop-free paths from start to goal: Starting with an empty maze (or a solid block of rock),

What is the problem name for Traveling salesman problem(TSP) without considering going back to starting point?

拜拜、爱过 提交于 2019-11-27 19:20:09
I would like to know what is the problem name for TSP w/o considering the way of going back to starting point and what is the algorithm to solve this. I looked into Shortest path problem but that is not what I am looking for, the problem only find the shortest path from 2 assigned points. But what I am looking for is the problem which we give n points and inputting only 1 starting point. Then, find the shortest path traveling all points exactly once. (end point can be any point.) I also looked into Hamiltonian path problem but it seems not to solve my defined problem but rather find whether

How to choose an integer linear programming solver?

倖福魔咒の 提交于 2019-11-27 15:39:16
问题 I am newbie for integer linear programming. I plan to use a integer linear programming solver to solve my combinatorial optimization problem. I am more familiar with C++/object oriented programming on an IDE. Now I am using NetBeans with Cygwin to write my applications most of time. May I ask if there is an easy use ILP solver for me? Or it depends on the problem I want to solve ? I am trying to do some resources mapping optimization. Please let me know if any further information is required.

Algorithm for diameter of graph?

孤人 提交于 2019-11-27 15:16:50
问题 If you have a graph, and need to find the diameter of it (which is the maximum distance between two nodes), how can you do it in O(log v * (v + e)) complexity. Wikipedia says you can do this using Dijkstra's algorithm with a binary heap . But I don't understand how this works. Can someone explain please? Or show a pseudocode? 回答1: For a general Graph G=(V,E) there is no O(log V * (V + E)) time complexity algorithm known for computing the diameter. The current best solution is O(V*V*V) , e.g.,

Algorithm to simplify a weighted directed graph of debts

时光毁灭记忆、已成空白 提交于 2019-11-27 12:53:21
I've been using a little python script I wrote to manage debt amongst my roommates. It works, but there are some missing features, one of which is simplifying unnecessarily complicated debt structures. For example, if the following weighted directed graph represents some people and the arrows represent debts between them (Alice owes Bob $20 and Charlie $5, Bob owes Charlie $10, etc.): It is clear that this graph should be simplified to the following graph: There's no sense in $10 making its way from Alice to Bob and then from Bob to Charlie if Alice could just give it to Charlie directly. The

Computing target number from numbers in a set

陌路散爱 提交于 2019-11-27 11:28:12
问题 I'm working on a homework problem that asks me this: Tiven a finite set of numbers, and a target number, find if the set can be used to calculate the target number using basic math operations (add, sub, mult, div) and using each number in the set exactly once (so I need to exhaust the set). This has to be done with recursion. So, for example, if I have the set {1, 2, 3, 4} and target 10, then I could get to it by using ((3 * 4) - 2)/1 = 10. I'm trying to phrase the algorithm in pseudo-code,

Graph serialization

北城以北 提交于 2019-11-27 10:27:44
问题 I'm looking for a simple algorithm to 'serialize' a directed graph. In particular I've got a set of files with interdependencies on their execution order, and I want to find the correct order at compile time. I know it must be a fairly common thing to do - compilers do it all the time - but my google-fu has been weak today. What's the 'go-to' algorithm for this? 回答1: Topological Sort (From Wikipedia): In graph theory, a topological sort or topological ordering of a directed acyclic graph (DAG

Construct a minimum spanning tree covering a specific subset of the vertices

百般思念 提交于 2019-11-27 10:16:00
问题 I have an undirected, positive-edge-weight graph (V,E) for which I want a minimum spanning tree covering a subset k of vertices V (the Steiner tree problem). I'm not limiting the size of the spanning tree to k vertices; rather I know exactly which k vertices must be included in the MST. Starting from the entire MST I could pare down edges/nodes until I get the smallest MST that contains all k . I can use Prim's algorithm to get the entire MST, and start deleting edges/nodes while the MST of