Download Graph representation

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Mathematics of radio engineering wikipedia , lookup

Four color theorem wikipedia , lookup

Transcript
Graphs
Representations
© Gunnar Gotshalks
GraphRepresentation–1
Adjacency Matrix
• Row and column indices are vertex number
• Matrix entries
»
< p , q > ∈ G → Matrix [ p , q ] = True
< p , q > ∉ G → Matrix [ p , q ] = False
f
r
o
m
© Gunnar Gotshalks
1
2
3
4
5
1
F
T
T
F
F
to
2 3
T T
F T
T F
F F
F T
4
F
F
F
F
T
5
F
F
T
T
F
Space
Big O?
f
r
o
m
1
2
3
4
5
1
F
F
F
F
F
to
2 3
T T
F F
T F
F F
F F
4
F
F
F
F
T
5
F
F
T
F
F
GraphRepresentation–2
Adjacency Matrix – 2
• In general the matrix entries can be any data representing
the edge
»
»
»
»
»
»
True / False are the minimum – an edge exists / ~exists
Integer – 0 / 1 for False / True
Number of parallel edges
Airline flight number
Time to do task (vertices represent checkpoints)
Maximum rate of oil flow in a pipeline
© Gunnar Gotshalks
GraphRepresentation–3
Adjacency List
• The adjacency matrix is very useful but is wasteful of
space due to many ‘zero’ entries
• Instead of a matrix use sequence representations based
on lists – not arrays
• Each vertex is represented as a sequence of adjacent
vertices
»
Each vertex in an adjacency list points to its entry in the
list of all vertices
»
Each vertex in an adjacency list can also point to edge
data
© Gunnar Gotshalks
GraphRepresentation–4
Adjacency List – Abstract Diagram
© Gunnar Gotshalks
GraphRepresentation–5
Adjacency List – Example
Space
Big O?
Adjacency list is itself a graph
with vertices of mixed types.
© Gunnar Gotshalks
GraphRepresentation–6
Graph Descriptors Vertex Adjacency List
© Gunnar Gotshalks
GraphRepresentation–7
Incidence Matrix – Undirected Graph
• Row indices are edge numbers
Column indices are vertex numbers
• Matrix entries
e = < p , q > ↔ Matrix [ e , p ] = Matrix [ e , q ] = True
e
d
g
e
© Gunnar Gotshalks
1
2
3
4
5
1
T
T
F
F
F
vertex
2 3 4
T F F
F T F
T T F
F F T
F T T
5
F
F
F
T
F
Space
Big O?
GraphRepresentation–8
Graph Descriptors Edge Incident Lists
© Gunnar Gotshalks
GraphRepresentation–9
Edge List
Space
Big O?
© Gunnar Gotshalks
GraphRepresentation–10
Graph Representation Summary
• Need to maintain three types of sequences
»
»
»
All vertices sequence
All edge sequence
Adjacency list (slide 11) or incidence list (slide 12)
> One for each vertex
© Gunnar Gotshalks
GraphRepresentation–11
Graph Representation Summary – 2
• Each of the sequence types can be in arrays or linked lists
depending upon
»
How dynamic the structures are
> Many insertions and deletions during use, linked
lists are better
»
The variance in sequence sizes for adjacency or
incidence lists
> Low variance – all lists are roughly the same length
– can use array, as there would be few unused
positions
> High variance – many short and long lists
– use linked lists
– Linked lists have overhead space for pointers and
extra time to dereference a link.
© Gunnar Gotshalks
GraphRepresentation–12