graph-algorithm

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

What is time complexity of BFS depending on the representation of the graph?

被刻印的时光 ゝ 提交于 2019-12-20 15:42:07
问题 I was wondering what is the time complexity of BFS, if I use: an adjacency matrix adjacency list edge list Is it same as their space complexity? 回答1: The complexity of BFS implemented using an Adjacency Matrix will be O(|V| 2 ). And that when implemented by an Adjacency List is O(|V| + |E|) . Why is it more in the case of Adjacency Matrix? This is mainly because every time we want to find what are the edges adjacent to a given vertex 'U', we would have to traverse the whole array

VF2 algorithm steps with example

流过昼夜 提交于 2019-12-20 10:38:01
问题 Can someone explain the steps of the VF2 algorithm for graph isomorphism in simple words? I am learning this algorithm, but it is harsh without a working example. Can someone lead me the right direction? Thank you. 回答1: I will try to give you a quick explaination of my previous answer to this question : Any working example of VF2 algorithm? I will use the same example as the one in my previous answer : The 2 graphs above are V and V' .(V' is not in the drawing but it's the one on the right)

Why does the time complexity of DFS and BFS depend on the way the graph is represented?

怎甘沉沦 提交于 2019-12-20 09:18:59
问题 The site http://web.eecs.utk.edu/~huangj/CS302S04/notes/graph-searching.html describes that when an adjacency list is used then, DFS and BFS have complexity O(V+E), and if an adjacency matrix is used, the complexity is O(V 2 ). Why is this? 回答1: In both cases, the runtime depends on how long it takes to iterate across the outgoing edges of a given node. With an adjacency list, the runtime is directly proportional to the number of outgoing edges. Since each node is visited once, the cost is

How to find path of exact length in graph

ⅰ亾dé卋堺 提交于 2019-12-20 03:41:08
问题 I would like to find path of fixed length (given while running the program) in undirected graph. I'm using adjacency matrix of my graph. I tried to use some algorithms like DFS or A*, but they only return the shortest path. Nodes can't be visited again. So let's say that my graph have 9 nodes and the shortest path is built from 4 nodes. I want to have additional variable that will "tell" the algorithm that I want to find path which have 7 nodes (for example) and it will return nodes which are

How to find path of exact length in graph

╄→尐↘猪︶ㄣ 提交于 2019-12-20 03:41:07
问题 I would like to find path of fixed length (given while running the program) in undirected graph. I'm using adjacency matrix of my graph. I tried to use some algorithms like DFS or A*, but they only return the shortest path. Nodes can't be visited again. So let's say that my graph have 9 nodes and the shortest path is built from 4 nodes. I want to have additional variable that will "tell" the algorithm that I want to find path which have 7 nodes (for example) and it will return nodes which are

All the paths between 2 nodes in graph

南笙酒味 提交于 2019-12-19 19:29:41
问题 I have to make an uninformed search (Breadth-first-Search) program which takes two nodes and return all the paths between them. public void BFS(Nod start, Nod end) { Queue<Nod> queue = new Queue<Nod>(); queue.Enqueue(start); while (queue.Count != 0) { Nod u = queue.Dequeue(); if (u == end) break; else { u.data = "Visited"; foreach (Edge edge in u.getChildren()) { if (edge.getEnd().data == "") { edge.getEnd().data = "Visited"; if (edge.getEnd() != end) { edge.getEnd().setParent(u); } else {

Find all simple path from node A to node B in direct weighted graph with the sum of weighs less a certain value?

戏子无情 提交于 2019-12-19 11:52:38
问题 I have a directed weighted graph G=(V,E), which may have loops . I am trying to determine the best time efficient algorithm to accomplish task: t o find all simple path in G between source and target node with total weight of edges in this path less than certain value (for convenience we denote this value as PATH_WEIGHT_LIMIT) All weights is positive and can be float. So, a prototype of my function will be: def find_paths(G, source, target, path_weight_limit) Result paths may overlap, its

2D waypoint pathfinding: combinations of WPs to go from curLocation to targetLocation

北慕城南 提交于 2019-12-19 10:29:34
问题 Please take a moment to understand my situation. If it is not comprehendable, please tell me in a comment. I have an ArrayList of Waypoints. These waypoints are not in any order. A waypoint has the following properties: {int type, float z, float y, float x, float rotation} This applies to a 3 dimensional world, but since my pathfinding should not care about height (and thus treat the world as a 2 dimensional one), the y value is ignored. Rotation is not of importance for this question. In

Connect nodes to maximize total edge weight

倖福魔咒の 提交于 2019-12-18 14:08:09
问题 I am working on a problem which could be reduced to a graph optimization problem as below. A set of colored nodes is given. They are all unconnected i.e. there is no edge in the graph. The edges are to be inserted between the nodes. A node can have only 4 edges at max. A table provides rules for profit contribution from the edges. Eg., An edge connecting red to red: profit is 10 An edge connecting red to blue: profit is 20 The total number of nodes is around 100. The total number of colors is