Posts

Showing posts with the label Graph

How to use GraphViz for visualizing graphs

Image
GraphViz is a very useful tool for defining and visualizing graph structures - once you know how. I find it's documentation on how to use the thing a little lacking, so I've posted some instructions on how to get started. For Windows operating systems, download and install the GraphViz programmer from here: https://www.graphviz.org/download/

Graph Traversals in C++ and C#

Image
Breadth First Search From WikiPedia : "Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbors" I have borrowed heavily the C++ code listing used at the 'Geeks for geeks' website and made a few modifications of my own, such as using smart pointers. I have also produced C# equivalents of the code. For reference the website is here: http://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/ Full C++/C# code listings: [tabs] [tab title="C++"] [code language="cpp"] #include <iostream> #include <list> #include <memory> class Graph { int _V; bool _directed; std::unique_ptr< std::list<int> > adj; public: Graph(int V, bool directed); ...