Python Graplib Module Prerequisites














































Python Graplib Module Prerequisites



GRAPHS


In the previous article, we have discussed brief Introduction of Graphlib

 Module.




 

Before going to discuss further details about Graphlib module, let us discuss about graphs briefly.


GRAPHS

DefinitionGraph is a non-linear datastructure consists of a finite set of 

vertices(or nodes) and a set of edges which connect a pair of nodes.

      G=(V,E) V=vertices, E=edges.








why we need Graphs?

Graphs are used to solve many real-life problems.some of the few

 examples are given below.


1)To calculate the shortest path between source and destination

  example : Google maps uses graphs for building transportation 

  systems, where intersection of two(or more) roads are considered to      be a vertex and the road connecting two vertices is                                  considered to be an edge, thus their navigation system is based on        the algorithm to calculate the shortest path between two vertices.

2)Graphs are used to define the flow of computation.


3)Graphs are used to represent networks of communication.


4)Graphs are used torepresent data organisation.



GRAPH REPRESNTATION

Using Adjacency matrixAn adjacency matrix is a square matrix of size

 N*N, where N is number of vertices in the graph.Elements of the

 matrix indicate whether  pairs of adjacent or not in the graph








PYTHON DICTIONARY IMPLEMENTATION:

graph = { "A" : ["C","D","B"],
          "B" : ["E", "A"],
          "C" : ["A", "D"],
          "D" : ["A","C","E"],
          "E" : ["B", "D"],
          
        } 
print (graph)


Output:

{'A': ['C', 'D', 'B'], 'B': ['E', 'A'], 'C': ['A', 'D'], 'D': ['A', 'C', 'E'], 'E': ['B', 'D']}


In the next module, we will see about types of graphs


Comments