graph-algorithm

What are the differences between segment trees, interval trees, binary indexed trees and range trees?

雨燕双飞 提交于 2019-12-17 06:19:19
问题 What are differences between segment trees, interval trees, binary indexed trees and range trees in terms of: Key idea/definition Applications Performance/order in higher dimensions/space consumption Please do not just give definitions. 回答1: All these data structures are used for solving different problems: Segment tree stores intervals, and optimized for " which of these intervals contains a given point " queries. Interval tree stores intervals as well, but optimized for " which of these

Graphtheory. How to approach these kinds of problems? I want to know the logic and the way one needs to think while trying to solve this.

若如初见. 提交于 2019-12-14 03:49:57
问题 Find the number of paths on the Cartesian plane from (0, 0) to (n, n), which never raises above the y = x line. It is possible to make three types of moves along the path: move up, i.e. from (i, j) to (i, j + 1); move to the right, i.e. from (i, j) to (i + 1, j); the right-up move, i.e. from (i, j) to (i + 1, j + 1) 回答1: Path count 101 First, we solve a simpler problem: Find the number of paths on the Cartesian plane from (0, 0) to (n, n) with: move up, i.e. from (i, j) to (i, j + 1); move to

A* Pathfinding java not working properly [closed]

不羁岁月 提交于 2019-12-14 03:14:05
问题 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 5 years ago . I am creating a Maze game in java and wants to add a smarty ghost (like Pacman) that move towards user location to catch him. For smarty ghost I chose A* PathFinding Algorithm and found below links for implementing this algorithm : https://code.google.com/p/a-star/source/browse/trunk/java/PathFinder.java?r=8

TSP Where Vertices Can be Visited Multiple Times

烂漫一生 提交于 2019-12-14 02:14:49
问题 I am looking to solve a problem where I have a weighted directed graph and I must start at the origin, visit all vertices at least once and return to the origin in the shortest path possible. Essentially this would be a classic example of TSP, except I DO NOT have the constraint that each vertex can only be visited once. In my case any vertex excluding the origin can be visited any number of times along the path, if this makes the path shorter. So for example in a graph containing the

Traversing all descendants of an object

我与影子孤独终老i 提交于 2019-12-13 21:50:09
问题 I'm having problems with traversing all descendants of an object. The 'unit' in the code below is of type Unit in my program. It has a property ChildUnits which returns a List<Unit> of the children of the unit. I can successfully perform operations on the children. Then I check if those children have children, and if they do I can perform operations on them as well. However, I need to check all descendants in case there is more depth than just grandchildren. I had a go with while loops in

How to detect and save cyclic connectivity in edge vertices (hole detection)?

你。 提交于 2019-12-13 20:26:50
问题 thanks for taking the time to read my question. I am working on detecting holes in a triangular mesh and fill them with new triangles. I have done some of the parts that are, to get a list of edge vertices, etc. Following are the vertices/edges that make holes, please have a look at the image. (9, 62) => vertex # 9 and 62 makes an edge (left hole) (66, 9) => vertex # 66 and 9 makes an edge (left hole) (70, 66) => vertex # 70 and 66 makes an edge (left hole) (62, 70) => vertex # 62 and 70

Union-Find/Disjoin-Set data structure for Directed Graph

孤人 提交于 2019-12-13 15:25:50
问题 I'm looking for an efficient Union-Find (aka Disjoint Set) data structure for my directed graph, which has cycles and forests. Given such a graph G , I want to to answer following queries: Can I reach node v from u ? From which nodes, u is not reachable? For a single "source" node u , I can run DFS search and answer whether I can reach v from it. A single DFS search will have an upper-bound cost of m + n in the worst-case, where m and n are the number of vertices and edges in the graph,

Graph with adjacency matrix in C

谁说胖子不能爱 提交于 2019-12-13 08:35:06
问题 I have this struct : struct graph { int** adj; /**< Adjacency matrix. */ int n; /**< Number of nodes in graph. */ }; and I have to create a void graph into this function: struct graph *graph_create(int nodes) { //To implement } How can I create a matrix using that double pointer int** adj ? 回答1: Here is the way to define a matrix with malloc() that i catch from GeeksForGeeks with some edition. 2D integer Matrix with int ** and malloc() int r = 3, c = 4, i, j, count; //arr[r][c] int **arr =

Decide Whether All Shortest Paths From s to t Contain The Edge e

喜夏-厌秋 提交于 2019-12-13 04:20:44
问题 Let G = (V;E) be a directed graph whose edges all have non-negative weights. Let s,t be 2 vertices in V, and let e be an edge in E. Describe an algorithm that decides whether all shortest paths from s to t contain the edge e. Well, this is how you can achieve Dijsktra's time complexity: Simply run Dijkstra from s and calculate delta(s,t) (the weight of the shortest path from s to t). Remove the edge e, and run Djikstra again from s in the new graph. If delta(s,t) in the new graph has

What kind of heuristics for BFS use to solve this 'game' (find path)?

谁说胖子不能爱 提交于 2019-12-13 02:33:33
问题 I want to solve a 'game'. I have 5 circles, we can rotate circles into left or into right (90 degrees). Example: Goal: 1,2,3,....,14,15,16 Ex. of starting situations: 16,15,14,...,3,2,1 I'm using BFS to find path but I can't invent heuristic function (my every solutions are not good). I was trying manhattan distance and others... (Maybe idea is good but something wrong with my solution). Please help! 回答1: One trick you might try is to do a breadth-first search backward from the goal state.