graph-algorithm

Reverse Breadth First traversal in C#

浪尽此生 提交于 2019-12-02 22:43:20
Anyone has a ready implementation of the Reverse Breadth First traversal algorithm in C#? By Reverse Breadth First traversal , I mean instead of searching a tree starting from a common node, I want to search the tree from the bottom and gradually converged to a common node. Let's see the below figure, this is the output of a Breadth First traversal : In my reverse breadth first traversal , 9 , 10 , 11 and 12 will be the first few nodes found ( the order of them are not important as they are all first order). 5 , 6 , 7 and 8 are the second few nodes found, and so on. 1 would be the last node

Understanding and building a social network algorithm

◇◆丶佛笑我妖孽 提交于 2019-12-02 21:22:13
I am not sure whether this is the right platform to ask this question. But my problem statement is : I have a book shop & x no of clients (x is huge). A client can tell me whether a book is a good or bad (not recommended). I have a internal logic to club books together , so if a client says a book is bad, he is saying that similar books are bad too and don't show him that. I oblige and hide those books. Clients can also interact among themselves, and have a mutual confidence level between them. A case arises when client A says Book X1 is bad. Hence i blacklist X1,X2,X3,X4 etc. But his friend

Is there any JavaScript libraries for graph operations and algorithms?

馋奶兔 提交于 2019-12-02 20:32:42
What I need is a JavaScript implementation of pure mathematical graphs . To be clear I DON'T mean graph visualization libraries like sigma.js or d3.js . The library I'm looking for would implement following features: creation of directed and undirected graph objects creation of weighted and unweighted graps objects adding/removing vertices and edges to/from the graph adding labels to vertices and edges (i.e. additional meta data) implementation of basic graph search and traversal algorithms like depth-first-search , breadth-first search , Dijkstra's algorithm , A* and others . Does anyone know

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

戏子无情 提交于 2019-12-02 18:25:01
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? 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 the number of nodes plus the number of edges, which is O(m + n). With am adjacency matrix, the time required

A* Algorithm for very large graphs, any thoughts on caching shortcuts?

天涯浪子 提交于 2019-12-02 17:14:11
I'm writing a courier/logistics simulation on OpenStreetMap maps and have realised that the basic A* algorithm as pictured below is not going to be fast enough for large maps (like Greater London). The green nodes correspond to ones that were put in the open set/priority queue and due to the huge number (the whole map is something like 1-2 million), it takes 5 seconds or so to find the route pictured. Unfortunately 100ms per route is about my absolute limit. Currently, the nodes are stored in both an adjacency list and also a spatial 100x100 2D array. I'm looking for methods where I can trade

Comparing object graph representation to adjacency list and matrix representations

白昼怎懂夜的黑 提交于 2019-12-02 14:02:39
I'm currently following Steve Yegge's advice on preparing for a technical programming interview: http://steve-yegge.blogspot.com/2008/03/get-that-job-at-google.html In his section on Graphs, he states: There are three basic ways to represent a graph in memory (objects and pointers, matrix, and adjacency list), and you should familiarize yourself with each representation and its pros and cons. The pros and cons of matrix and adjacency list representations are described in CLRS, but I haven't been able to find a resource that compares these to an object representation. Just by thinking about it,

Show that, given a query point q, it can be tested in time O(log n) whether q lies inside P

喜欢而已 提交于 2019-12-02 05:17:28
问题 I am trying to solve some exercises of the book "Computational Geometry Algorithm and Applications, 3rd - de berg et al" of chapter 6 - Point Location. Unfortunately, I have no idea how to solve the following exercise: Given a convex polygon P as an array of its n vertices in sorted order along the boundary. Show that, given a query point q, it can be tested in time O(log n) whether q lies inside P. My Idea so far: The only way I know to determine if a point lies inside p in O(log n) is to

Show that, given a query point q, it can be tested in time O(log n) whether q lies inside P

爱⌒轻易说出口 提交于 2019-12-02 00:22:40
I am trying to solve some exercises of the book "Computational Geometry Algorithm and Applications, 3rd - de berg et al" of chapter 6 - Point Location. Unfortunately, I have no idea how to solve the following exercise: Given a convex polygon P as an array of its n vertices in sorted order along the boundary. Show that, given a query point q, it can be tested in time O(log n) whether q lies inside P. My Idea so far: The only way I know to determine if a point lies inside p in O(log n) is to use a directed acyclic graph. In order to use a directed acyclic graph I need to build it, which is

Algorithm for minimum diameter spanning tree

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 00:04:21
问题 Given a undirected and connected graph G, find a spanning tree whose diameter is the minimum. 回答1: singhsumit linked the relevant paper by Hassin and Tamir, entitled "On the minimum diameter spanning tree problem", but his answer is currently deleted. The main idea from the paper is that finding a minimum diameter spanning tree in an undirected graph can be accomplished by finding the "absolute 1-center" of the graph and returning a shortest path tree rooted there. The absolute 1-center is

Design an algorithm for the single source shortest path problem that runs in time O(k(|V|+|E|))

五迷三道 提交于 2019-12-01 21:16:56
Suppose we are given a directed graph G = (V, E) with potentially positive and negative edge lengths, but no negative cycles. Let s ∈ V be a given source vertex. How to design an algorithm for the single-source shortest path problem that runs in time O(k(|V | + |E|)) if the shortest paths from s to any other vertex takes at most k edges ? Here`s O(k(|V | + |E|)) approach: We can use Bellman-Ford algorithm with some modifications Create array D[] to store shortest path from node s to some node u initially D[s]=0, and all other D[i]=+oo (infinity) Now after we iterate throught all edges k times