graph-algorithm

Non-recursive Depth-First Search (DFS) Using a Stack

浪子不回头ぞ 提交于 2019-12-03 07:28:25
问题 Ok this is my first post on Stack Overflow I have been reading for a little while and really admire the site. I am hoping this is something that will be acceptable to ask. So I have been reading through Intro to Algorithms (Cormen. MIT Press) all the way through and I am up to the graph algorithms. I have been studying the formal algorithms laid out for breadth and depth first search in very fine detail. Here is the psuedo-code given for depth-first search: DFS(G) ----------------------------

How to find multidimensional path of exact 0 cost with 1, 0, -1 weights

淺唱寂寞╮ 提交于 2019-12-03 07:18:48
问题 I was given directed graph with n nodes and edges with weigths of vectors (every vector has length m) of numbers 1, 0, -1. I would like to find any path (or say that such path doesn't exist) from one node to other (we can visit nodes many times) such sum of its weights equals to vector of only zeros. I was thinking of bruteforce backtracking algorithm but it is not guaranteed that it would end. Can we somehow limit length of such path in terms of n and m? Example of graph for n=8, m=2 Example

Visualizing set hierarchies as color coded graphs

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 06:57:33
问题 I have been reading quite a bit on graphing libraries for Java and Javascript lately but I haven't found a good way to do what I want to do. Essentially I have a hierarchy of sets with regards to a bunch of elements (up to several thousands). These sets can be fully or partly overlapping, fully covering or completely disjoint from one another. What I would like to do is to display the following information: The size of a set (in relation to the other sets) A "heat" value (in color code) of a

Is there any JavaScript libraries for graph operations and algorithms?

限于喜欢 提交于 2019-12-03 06:54:04
问题 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

Efficiently build a graph of words with given Hamming distance

家住魔仙堡 提交于 2019-12-03 04:55:55
I want to build a graph from a list of words with Hamming distance of (say) 1, or to put it differently, two words are connected if they only differ from one letter ( lo l -> lo t ). so that given words = [ lol, lot, bot ] the graph would be { 'lol' : [ 'lot' ], 'lot' : [ 'lol', 'bot' ], 'bot' : [ 'lot' ] } The easy way is to compare every word in the list with every other and count the different chars; sadly, this is a O(N^2) algorithm. Which algo/ds/strategy can I use to to achieve better performance? Also, let's assume only latin chars, and all the words have the same length. Assuming you

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

邮差的信 提交于 2019-12-03 04:23:37
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? Vamsi Sangam 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 AdjacencyMatrix[U] , which is off course of length |V| . Imagine the BFS progressing as frontiers. You take

Finding Connected Components using Hadoop/MapReduce

若如初见. 提交于 2019-12-03 03:53:21
I need to find connected components for a huge dataset. (Graph being Undirected) One obvious choice is MapReduce. But i'm a newbie to MapReduce and am quiet short of time to pick it up and to code it myself. I was just wondering if there is any existing API for the same since it is a very common problem in Social Network Analysis? Or atleast if anyone is aware of any reliable(tried and tested) source using which atleast i can get started with the implementation myself? Thanks I blogged about it for myself: http://codingwiththomas.blogspot.de/2011/04/graph-exploration-with-hadoop-mapreduce.html

Functional implementation of Tarjan's Strongly Connected Components algorithm

天涯浪子 提交于 2019-12-03 02:49:35
问题 I went ahead and implemented the textbook version of Tarjan's SCC algorithm in Scala. However, I dislike the code - it is very imperative/procedural with lots of mutating states and book-keeping indices. Is there a more "functional" version of the algorithm? I believe imperative versions of algorithms hide the core ideas behind the algorithm unlike the functional versions. I found someone else encountering the same problem with this particular algorithm but I have not been able to translate

Comparing object graph representation to adjacency list and matrix representations

匆匆过客 提交于 2019-12-03 01:49:01
问题 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

Finding a shortest path that passes through some arbitrary sequence of nodes?

最后都变了- 提交于 2019-12-03 00:25:08
In this earlier question the OP asked how to find a shortest path in a graph that goes from u to v and also passes through some node w. The accepted answer, which is quite good, was to run Dijkstra's algorithm twice - once to get from u to w and once to get from w to v. This has time complexity equal to two calls to Dijkstra's algorithm, which is O(m + n log n). Now consider a related question - you are given a sequence of nodes u 1 , u 2 , ..., u k and want to find the shortest path from u 1 to u k such that the path passes through u 1 , u 2 , ..., u k in order. Clearly this could be done by