A graph can refer to a graphic (such as a chart or diagram) showing or displaying the relationship between two or more variables used, for instance, in visualizing scientific data.
11
votes
1answer
902 views
Topological sort in Java
I am learning algorithms in graphs. I have implemented topological sort using Java. Kindly review my code and provide me with feedback.
...
11
votes
1answer
324 views
Variadic function with restricted types
I am designing a class which (among other things) acts as a vertex in an undirected graph.
...
10
votes
3answers
1k views
Find all paths from source to destination
Given a directed connected graphs, find all paths from source to destination.
Looking for code review, optimizations and best practices. Also need help figuring out complexity, which in my best ...
9
votes
1answer
76 views
Generic Graph Library
I've been working on a generic graph library for a while now, in a bit of an off and on fashion. I realise that boost::graph exists, but it is a complex library ...
7
votes
3answers
362 views
Depth First Traversal of a Graph
I am learning how to implement a basic undirected graph and perform a depth first traversal.
Please critique my code for correctness, best practices, security, and any other comments that may be ...
7
votes
1answer
1k views
Distribute random number of nodes in a range [closed]
The purpose of the following code is to get a random number of 100 nodes and to distribute these nodes randomly in range 500*500...(X,Y). This was the first step:
...
7
votes
2answers
201 views
Missing level of technical depth (Common Ancestor)
I recently have given a coding test in a reputable IT company. There were three coding questions.
They refused me by saying that
as we felt they didn't demonstrate the level of technical depth ...
7
votes
2answers
3k views
A* search algorithm
A* search algorithm. Looking for reviews on optimization, accuracy and best practices.
...
7
votes
2answers
945 views
Check if directed graph contains a cycle
I have solved the question, and in turn felt the need to get it reviewed. Any suggestions for clean up and optimization would help. Also please verify my complexity: Complexity: O (V + E). ...
7
votes
1answer
419 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 ...
6
votes
3answers
977 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 ...
6
votes
2answers
119 views
Clone of an undirected graph
Perform a graph clone. Verifying complexity to be O(E). Looking for code review, optimizations and best practices.
...
6
votes
1answer
129 views
Escaping the prison - finding the shortest way
I have given an assignment where I have to escape a labyrinth. The goal is to find the shortest way. I have done some research and there seem to be two strategies to solve the problem: the Depth-first ...
6
votes
1answer
48 views
Extracting nodes from a road network
My code takes 143.023 seconds for extracting nodes from a road network of city like Göteborg in Sweden. Please check it out if I can optimize it.
...
6
votes
2answers
520 views
Ford-Fulkerson algorithm
Solved the ford-fulkerson algorithm, which is too vast to explain it comprehensively here. Check Wikipedia for Ford-Fulkerson and Princeton lecture on Ford-Fulkerson.
Looking for code review, ...
6
votes
1answer
134 views
Dijkstra-like routing algorithm
I've got the following code to find the shortest path between two nodes using almost-Dijkstra's-algorithm which was written for an exercise, and I'm looking for things to improve my general Scala ...
6
votes
1answer
244 views
Shortest Path in a Unit Cost DAG BFS in Hadoop
Just got done implementing a shortest path algo of a unit cost DAG BFS in Hadoop and wanting to get anyone's opinion on how I could have done it better. The main issue I see is that I lose the ...
5
votes
4answers
422 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 ...
5
votes
2answers
5k views
Learning to code a graph
This is my first attempt at putting the conceptual knowledge I've gained about graphs into code. When searching for examples they all seem overly complicated, and searching for a tutorial or ...
5
votes
2answers
188 views
Map color problem: Optimize using a heap?
I've written some python code to solve the map coloring problem. In my code, I represent the problem using Territory and ...
5
votes
1answer
2k views
Prims algorithm implementation
Review this code regarding optimization, cleanup, and best practices.
...
5
votes
2answers
2k views
Implementation of Dijkstra's algorithm
Please pick my code apart and give me some feedback on how I could make it better or more simple.
...
5
votes
1answer
44 views
Generic Graph Library Part 2 : Algorithms
(This is a follow on to this question).
Having given an implementation for some of the graph structures, here is a portion of the algorithms that are defined to work over them:
graph_degree.hpp
...
5
votes
1answer
175 views
Code to construct a complete graph
I have tried to design a class for a complete graph.
Needless to say, disadvantages of my current solution are very visible:
dependent inputs have led to verification headaches.
In this code we ...
5
votes
2answers
142 views
How to improve this algorithm for building a graphs closures
We have a large directed acyclic graph and a requirement to filter it by allowing a user to select certain nodes and then we remove all nodes that are not selected nodes, ancestors of those nodes, or ...
5
votes
1answer
65 views
Strongly connected components algorithm
In my Python application, I am using Tarjan's algorithm to compute strongly connected components. Unfortunately, it shows up under profiling as one of the top functions in my application (at least ...
5
votes
0answers
68 views
Finding all paths from a given graph
I need to find all paths from a given graph. I can do that for now, however my recursive code is not efficient and my graphs are very complicated, hence I need a better algorithm.
...
4
votes
1answer
670 views
Do I need to delete a vector?
I want to make a graph from input from a text file in the format:
vertex1 vertex2 cost time
where vertex1 and vertex2 are strings that form an edge and cost and ...
4
votes
1answer
48 views
JFreeChart Dynamic Scatter Chart
I have a model that consists of a 100 'agents' that change their x and y coordinates randomly. I use JFreeChart scatter chart to represent agents' locations.
...
4
votes
1answer
52 views
Maximize the number of nodes that could be reachable in a graph
Description of my code:
I am trying to maximize the number of nodes that could be reachable in a graph. Please do not consider my main algorithm, I want it to be like that. The only parts that I need ...
4
votes
1answer
559 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.
...
4
votes
1answer
110 views
Modified BFS code optimizations
I need some help reviewing this code in terms of making as fast as possible. This is a modified version of BFS that does quite a bit of processing on the side.
Use case:
I have a large graph ...
4
votes
1answer
314 views
Dijkstra's and Prim's algorithms: correctness/efficiency
This is in preparation for a competition that only allows C++03.
...
4
votes
1answer
906 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 ...
4
votes
1answer
1k 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 ...
4
votes
1answer
127 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 ...
3
votes
2answers
1k 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
...
3
votes
2answers
721 views
3
votes
1answer
595 views
My first python graph traversal review
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 ...
3
votes
1answer
148 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, ...
3
votes
1answer
295 views
DFS/BFS implementation Cormen's pseudo code
I like this site and thought if putting this dfs/bfs C++ code for Cormen pseudo code.....please give your comments
...
3
votes
1answer
133 views
Tarjan's algorithm for Strongly Connected Components without keeping SCC in stack
I've been looking for an implementation of Tarjan's algorithm in C#/C++ for a strongly-connected components in graphs, and couldn't find any implementation without use of additional Stack - most of ...
3
votes
1answer
258 views
Please review my Digraph Code in Java
can people please review my digraph code? 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 ...
3
votes
1answer
100 views
Review/rate my new graph class
I have written a PHP class called "graph". It is a class that performs RESTful-like commands to a MySQL database. I have posted the GitHub repo.
Here is the code as well:
config.php
...
3
votes
1answer
341 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.
...
3
votes
2answers
82 views
Simplify an if else construct with assignment before if and else
I want to simplify an if: .. else: .. construct:
...
3
votes
1answer
64 views
Clone an undirected graph
I'm looking for code-review, optimization and best practices. Also verifying complexity to be O(E) time and O(V+E) space complexity.
...
3
votes
0answers
40 views
Thinking in 'Haskell' - when to use (state) Monads
I really enjoy Haskell but feel I still have a total beginner's style, and would like to move beyond that. The code below - for Dijkstra's shortest path algorithm - is a case in point. I feel as ...
2
votes
4answers
1k views
Depth First Search & Breadth First Search implementation
I've implemented DFS and BFS implementations. I want to check if the code is readable, contains any issues, and can be improved.
GraphImplementation
...
2
votes
2answers
5k views
STL graph implementation
I'm looking for a code review on the following C++/STL graph implementation:
...