Graph is a bit different data structure than other data structures. Graph data structure is like a Tree. Its a set of vertices and edges which connect vertices. Lets first understand what Tree is and how Graph is different from Tree. Tree basically represent hierarchical data. For example an Organization structure or Windows Explorer or any other File Handling GUI. Tree is composed of nodes where every node has some data and set of children. So Tree is special case of Graph where Tree has set of restriction like there will be a root node, every non leaf node will have children. In simple terms, Tree is connected graph with no cycles. So Graph is composed of nodes and edges.
How do we represent a Graph. Generally graph is represented with either adjacency list or adjacency matrix. I will use adjacency matrix here.
So graph contains vertices and edges.
View original post 285 more words