Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU
Why graphs are important Graphs are used a lot in computer science – Social network (face book, linked in)
Why graphs are important Graphs are used a lot in computer science – Computer networks
Why graphs are important Graphs are used a lot in computer science – Transportation network
Why graphs are important Graphs are used a lot in computer science – Wireless sensors
What are graphs? A set of vertices V and a set of edges E Each edge is a ordered pair of two vertices G = (V, E) E.g. – V = {1, 2, 3, 4, 5, 6} – E = {,,,,,,, }
What are graphs? V = {1, 2, 3, 4, 5, 6} E = {,,,,,,, }
What are graphs? Use a undirected line to indicate a pair of edges or a self edge
How to represent a graph?
E.g What is the space complexity?
How to represent a graph? Can we improve the space complexity?
How to represent a graph?
next Adjacency-list NIL
How to represent a graph? How to represent an attribute for an edge or a node? Put satellite in vertices or edges and store them NILEdgeNILEdgeNIL 2 EdgeNIL 3 EdgeSat. 4NILEdgeNIL 5 Sat.NIL 6 Edge Vertex 1 2next4 NIL Vertex Edge
How to represent a graph? Let’s try to implement graphs in Java – A Graph interface define all the operations – A subclass to implement adjacency matrix
How to represent a graph? Why not just maintain two array? – E – and V Part of HW5 – What are advantages and disadvantages to just use an array of edges and an array of vertices to represent a graph?