graph-theory

Efficient way to practice graph theory algorithms

I just read about the breadth-first search algorithm in the Introduction to Algorithms book and I hand simulated the algorithm on paper. What I would like to do now is to implement it in code for extra practice. I was thinking about implementing all the data structures from scratch (the adjacency list, the "color", "distance", and "par...

What algorithm can I use to find the shortest path between specified node types in a graph?

This is the problem: I have n points (p1, p2, p3, .. pn), each of them can connect to any other with a determined cost x. Each point belongs to one of a set of point-types (for example "A" "B" "C" "D"...). The input of the method is the path I want to follow, for example "A-B-C-A-D-B". The output is the shortest path connecting the p...

Graphs (Nodes and Edges)

I am using HASKELL for graph games. I am willing to get a suitable method for reach ability from a node to a particular node in the graph apart from using bfs or trees etc. As I asked for code in haskell for reach ability from one node to a particular node, it is necessary to tell you that I am totally new to haskell. I have been re...

Core Data Fetched Properties to rank connectivity between Objects

I want to rank how strongly connected instances of Entity A are to other instances or Entity A are in my graph.I only need to do this for the n most recently viewed entities. I describe relations between two instances of Entity A by means of another Entity B. This is because I need to describe each relationship. I was considering using ...

Finding edge in weighted graph

I have a graph with four nodes, each node represents a position and they are laid out like a two dimensional grid. Every node has a connection (an edge) to all (according to the position) adjacent nodes. Every edge also has a weight. Here are the nodes represented by A,B,C,D and the weight of the edges is indicated by the numbers: A ...

Good algorithm for finding the diameter of a (sparse) graph?

I have a large, connected, sparse graph in adjacency-list form. I would like to find two vertices that are as far apart as possible, that is, the diameter of the graph and two vertices achieving it. I am interested in this problem in both the undirected and directed cases, for different applications. In the directed case, I of course ...

Kruskal vs Prim

I was wondering when one should use Prim's algorithm and when Kruskal's to find the minimum spanning tree? They both have easy logics, same worst cases, and only difference is implementation which might involve a bit different data structures. So what is the deciding factor? ...

Hungarian Algorithm and multiple factors

I have a situation where I need to allocate people to several events. If we just had a price as a factor, it would be fine, but there is a number of factors that come in. First, some background. This is for a non-profit organization that promotes story hours for children that are hospitalized for any reason, so they depend on voluntary ...

Using the apriori algorithm for recommendations

So a recent question made me aware of the rather cool apriori algorithm. I can see why it works, but what I'm not sure about is practical uses. Presumably the main reason to compute related sets of items is to be able to provide recommendations for someone based on their own purchases (or owned items, etcetera). But how do you go from a ...

Add a edge to direct acyclic graph with other restrictions

I have a DAG. I have this operation to add a edge between two nodes. If A is reachable from B, then B is A's parent. If A is reachable from B without going though another node, then B is A's direct parent. Requirements for this graph are: No cycles. For any node, there is a list of direct parents P[1],P[2],P[3]... P[i] is not a paren...

Paths in complete graph

I have a friend that needs to compute the following: In the complete graph Kn (k<=13), there are k*(k-1)/2 edges. Each edge can be directed in 2 ways, hence 2^[(k*(k-1))/2] different cases. She needs to compute P[A !-> B && C !-> D] - P[A !-> B]*P[C !-> D] X !-> Y means "there is no path from X to Y", and P[ ] is the probability. So ...

Automatic graph layout spring theory

I'm trying to position entities visualy to show their relationships to each other. It looks like for automatic graph layout, the spring algorithm would suit my needs. I'd like to implement this in silverlight using c#, so I'm looking for code samples, or links to good explanations of the theory. Any help appreciated ...

Partitioning perfect matchings in a bipartite graph

In the 'marriage problem', we have N boys and N girls and an NxN binary matrix telling us which pairings are suitable, and want to pair each girl to a boy. (i.e. we want to find a perfect matching in a bipartite graph). Hall's theorem says that you can find a perfect matching if every collection of boy-nodes is collectively adjacent to ...

Analyzing Path Data

I have data representing the paths people take across a fixed set of points (discrete, e.g., nodes and edges). So far I have been using igraph. I haven't found a good way yet (in igraph or another package) to create "canonical" paths summarizing what significant sub-groups of respondents are doing. A canonical path can be operationali...

Algorithm to Find Overlapping Line Segments

n4------------------n3--------------------n2--n1 | | | | | | | P1 | | | | | | | n6--n5 | | | | n11--n10 | n17 ...

Graph Theory Question

This is a two part question. In a reunion of 20 people, there are 48 pairs of people that know each other. a) Justify why there is, at least, one person who knows, at most, other 4 persons. b) Suppose there is a single person who knows at most other 4 persons. How many people does that person knows exactly? I'm unsure about my answe...

What's the name for directed trees with edges pointing towards the root?

What do you call a graph that's almost an arborescence, but where the edges go in the opposite direction? That is, a directed graph with a center node, where every node has exactly one path to the center? It might help to have a reason for naming this thing. I'm looking to describe the control structure used in a continuation passing ar...

How can I learn higher-level programming-related math without much formal training?

I haven't taken any math classes above basic college calculus. However, in the course of my programming work, I've picked up a lot of math and comp sci from blogs and reading, and I genuinely believe I have a decent mathematical mind. I enjoy and have success doing Project Euler, for example. I want to dive in and really start learning ...

Are there any online algorithms for planarity testing?

I know that planarity testing can be done in O(v) (equivalently O(e), since planar graphs have O(v) edges) time. I wonder if it can be done online in O(1) amortized time as each edge is added (still O(e) time overall). In other words, in a database table representing edges of a graph and subject to a constraint that the represented gra...

Algorithms to Identify All the Cycle Bases in a UnDirected Graph

I have an undirected graph with Vertex V and Edge E. I am looking for an algorithm to identify all the cycle bases in that graph. I think Tarjans algorithm is a good start. But the reference I have is about finding all of the cycles, not cycle base ( which, by definition is the cycle that cannot be constructed by union of other cycles)...