SLIDE 6 Adjacency List
- List elements might also contain objects of
an Edge class.
2 1 3 4
6.1 4.2 1.0 1.5
1 2 3 4
2 1.0 4 3.7 3 6.1 1.0 4 4.2 2 6.1 4 1.5 3 1.5 2 4.2 3.7
3.7
Graph Implementations
– Very often, other data may be associated with a vertex – It is often useful to create a Vertex class that holds all data. – Each graph may, in addition to edge representation, contain a set of Vertex class
Graph Implementations
– Graph of 50 Vertices – 4bytes / entry
1,200 10,000 100 2,500 2,000 1,500 1,200 1,000 500 250 49 Edges 20,400 10,000 16,400 10,000 12,400 10,000 10,000 10,000 8,400 10,000 4,400 10,000 2,400 10,000 792 10,000 Adj List
Graph Implementations
O (E / N) O (1) Delete Edge O (E / N) O (1) Insert Edge Find Neighbors Delete Node Insert Node Operation O (E / N) O(N) O (E) O (N) O (E / N) O (1) Adj List
N = number of nodes E = number of edges E / N = avg number of edges per vertex
Graph Implementations
- When implementing CS3DiGraph
– Choose implementation best suited for TSP – Feel free to use nested classes for aux classes (if required) – Feel free to use Java Collections Framework
Summary
- Graphs
- Terminology
- Building a Graph
- Implementing a Graph
- Tomorrow: Graph Traversals
- Questions?