Presentation is loading. Please wait.

Presentation is loading. Please wait.

Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU.

Similar presentations


Presentation on theme: "Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU."— Presentation transcript:

1 Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU

2 Why graphs are important Graphs are used a lot in computer science – Social network (face book, linked in)

3 Why graphs are important Graphs are used a lot in computer science – Computer networks

4 Why graphs are important Graphs are used a lot in computer science – Transportation network

5 Why graphs are important Graphs are used a lot in computer science – Wireless sensors

6 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 = {,,,,,,, }

7 What are graphs? V = {1, 2, 3, 4, 5, 6} E = {,,,,,,, } 123 456

8 What are graphs? 123 456 Use a undirected line to indicate a pair of edges or a self edge

9 How to represent a graph?

10 E.g. 123 456 123456 1 2 3 4 5 6 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 What is the space complexity?

11 How to represent a graph? 123456 1 2 3 4 5 6 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Can we improve the space complexity?

12 How to represent a graph?

13 123 456 1 2 3 4 5 6 2next2 4 4 5 5 5 5 6 6 2 2 4 4 6 6 Adjacency-list NIL

14 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 123456 1NILEdgeNILEdgeNIL 2 EdgeNIL 3 EdgeSat. 4NILEdgeNIL 5 Sat.NIL 6 Edge 1 2 3 4 5 6 Vertex 1 2next4 NIL Vertex Edge

15 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

16 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?


Download ppt "Design and Analysis of Algorithms Introduction to graphs, representations of a graph Haidong Xue Summer 2012, at GSU."

Similar presentations


Ads by Google