# Questions tagged [graph]

A graph is an abstract representation of objects (vertices) connected by links (edges). For questions about plotting data graphically, use the [data-visualization] tag instead.

639 questions
Filter by
Sorted by
Tagged with
1k views

### Digraph Code in Java

This is used to create a directed graph of type T. The directed graph has edges and vertices with values but is directional such that nodes can loop unto ...
13k views

### BFS and DFS in Scala

I would love it if someone could give me some suggestions for these 2 graph search functions. I am new to scala and would love to get some insight into making these more idiomatic. ...
2k views

### Finding strongly connected components of directed graph, kosaraju

Given a graph in [[sourcevertex,targetvertex],...] format with all the directed edges of the graph I am trying to optimize the code here because it still hasn't ...
5k views

...
1k views

### Complete graph traversal algorithm in Prolog

Given a table, I want to explore all possible transition between the elements in the table. ex: for a table with size 3 [0,1,2], the output of the algorithm should be 0->1, 1->0, 0->2, 2->1, 1->2, 2->...
3k views

### Strongly-connected component for a graph

I implemented a strongly connected graph code in C++. matrix_graph.h ...
12k views

### DFS/BFS implementation of Cormen's pseudo code

This is DFS/BFS C++ code for Cormen pseudo code. Please comment on this. ...
19k views

I've created this adjacency list, but I don't like the design of the graph. The issue is that there is one pointer in the node to its adjacency list and there is a pointer in an ...
1k views

### Find almost-shortest path more efficiently

I'm trying to solve a SPOJ problem, which is code SAMER08A at this link. The problem is that when I ran my code in my IDE with all the examples given in the problem, the code works perfectly. But ...
130 views

### Small graph API to track vertices and edges added to graph

I'm working on my Scala chops and implemented a small graph API to track vertices and edges added to graph. I have basic GraphLike Trait, and have an Undirected Graph class ( ...
855 views

...
521 views

### Is this implementation of Kruskal's algorithm maintainable and efficient?

I'm implementing Kruskal's algorithm in C++11 and would like feedback on style and performance on my graph data structure and algorithm for educational purposes (for production code, I'd use a pre-...
4k views

### Finding the closest node

I have a function that I need to optimize: ...
314 views

...
479 views

### Improving readability of non-recursive depth first search function in Lisp

As a free-time activity in order to learn some Lisp I had to implement depth first directed graph search. Due to large graph size (800K nodes, 5M arcs) recursion-based approach I could devise didn't ...
1k views

### My first graph traversal code

I'm trying to solve a graph traversal problem I found, and was wondering how I could improve my implementation. Currently it seems a little convoluted and long. The problem is as follows: I have a ...
769 views

### BFS implementation to find connected components taking too long

This is in continuation to a question I asked here. Given the total number of nodes (employees) and the adjacency list (friendship amongst employees), I need to find all the connected components. <...
3k views

### Evaluating longest path

Here is a program which keeps track of the longest path in a graph. I think it can be written much better. ...
3k views

### Generating adjacency matrix on random cout of graphs with output the matrix

I've developed program, which may work with graphs and its edges (connections between vertices): http://ideone.com/FDCtT0 ...
10k views

### Undirected, connected and weighted graph implementation

I was thinking in a way of implementing a graph in such that would let find a minimum spanning tree. Graph.h ...
363 views

### Finding and returning a loopy path in a directed graph

I wrote a function in Scala to find out and return a loopy path in a directed graph. One of the arguments is a graph presented in an adjacent list, and the other is a start node. It returns a pair ...
273 views

### unw_graph class (unweighted graph)

Here is my new STL-like implementation of an unweighted graph. Could you please tell me what member functions I should include in my library? unweighted_graph.hpp ...
6k views

### D3 visualization of a Facebook friend graph

I've been learning Python for about a year and now I'm trying to improve my JavaScript. I wrote this simple d3 visualization that shows your Facebook friends as a force-directed graph. Here's a live ...
4k views

### STL-like graph implementation

I have implemented an STL-like graph class. Could someone review it and tell me things that I could add to it? File graph.hpp ...
12k views

### Implementation of Kosaraju's algorithm for strongly connected components

To learn and practice coding in C++, I wrote an implementation of Kosaraju's two-pass algorithm for computing the strongly connected components in a directed graph, using depth-first search. This was ...
1k views

### Reorder a list of courses, given their prerequisites

I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the ...
22k views

### STL graph implementation

I'm looking for a code review on the following C++/STL graph implementation: ...
125 views

### “Causes” Puzzle solution (network of words with Levenshtein distance 1)

The "Causes" puzzle is to recursively find, starting with the word "causes", the number of words that can be formed by substituting one letter. ...
4k views

### Variadic function with restricted types

I am designing a class which (among other things) acts as a vertex in an undirected graph. ...
334 views

### “Ringing in the New Year (2011→ 2012)” puzzle

I am trying to solve the puzzle RINGING IN THE NEW YEAR. Start at 2011. By moving through the maze and doing any arithmetic operations you encounter, exit the maze with a result of 2012. You may ...
477 views

### Graph generator for undirected graphs

I am still pretty new to Haskell and am working on a graph generator for undirected unlabeled graphs containing loops and I have a bottleneck in the following functions. So far, I have not given any ...
1k views

### Javascript graph skeleton implementation

I started implementing a graph drawing application in javascript and < canvas > element, and i just wanted to hear your thought on the progress so far. I'm very open to suggestions and i'm very ...
1k views

### BFT/DFT/Topological graph implementation

I am trying to learn graphs and implement in code. Can you please review my code and give me feedback? Source code ...
1k views

### Print pair representing objects from sequence of nonnegative integer pairs

There are some things I am not sure of from a professional standpoint about the "correct" way to write C++ code. I have been looking through source code produced by various opensource projects, as ...
593 views

### Compute random triplets of float pairs and average area of generated triangles

I am trying to get in a lot of practice for interviews so I am trying to write as much code as possible, and getting feed back from excellent programmers like "you". Can I get some general feed back ...
300 views

### Social network evolution

I am writing a piece of code which models the evolution of a social network. The idea is that each person is assigned to a node and relationships between people (edges on the network) are given a ...
1k views

### Fastest way to find all neighbours of a vertex in a graph

I'm looking for the fastest way to find all neighbours of a vertex in an undirected Graph. Please improve on the code if possible. ...
2k views

### Coding adjacency list representing graph

I want to write some basic code on graph like DFS, BFS but before that I am coding graph representation in adjacency list, and some basic functions like ...