Graphs

advertisement
Graphs
4
2
1
3
5
6
7
8
10
9
What good is a graph….
–
–
–
–
–
–
–
–
Maps
Hypertexts
Circuits
Networks
Matching
Transactions
Schedules
Program structure
Graphs
• A graph is a set of Vertices and a set of
Edges that connect pairs of distinct vertices
(with at most 1 edge connecting any pair of
vertices).
4
2
• This is a simple graph
3
5
• What does this mean??
1
Graphs
• Simple graphs have a property about the
maximum number of edges:
A graph with V vertices has at most:
V(V-1) / 2 edges
Graphs Terms
• Vertex = Node
1
• Arc = Edge = Link
• Adjacent - Two graph edges are adjacent if they have a vertex in
common. Likewise, two vertices are adjacent if they are joined by a graph
edge.
• Incident - An edge is incident to a vertex if the vertex is at one end of
the edge. A vertex is incident to an edge if that edge is incident to the vertex.
1
2
Graphs Terms
• Degree - The number of edges incident to a given vertex. Each vertex in a directed
graph has both an indegree, the number of edges coming in to the vertex as well as an
outdegree, the number of edges going out of the vertex.
Graphs Terms
• Subgraph - A graph G1 is called a subgraph of graph G2, if every
vertex of the first graph is a vertex in the second graph, every edge of the first
graph is an edge in the second graph, and every edge of the first graph joins
the same vertices as it does in the second graph. The purple vertices with bold
edges G2 is a subgraph of the larger graph G1.
4
2
1
3
5
6
7
8
10
9
Graphs Terms
• Isomorphic – The simple graphs G1 and G2 are isomorphic if there is one-to-one
correspondence between their sets of vertices which preserves vertex adjacency. For
directed graphs the one-to-one correspondence must preserve adjacency while also
preserving relative origins and ends of edges.
• Which are isomorphic to each other??
Graphs Terms
• Path – A path in a graph is a set of vertices
in which each successive vertex (after the
first) is adjacent to its predecessor in the
4
path.
2
1
3
5
6
7
8
10
9
Graphs Terms
• Simple Path – vertices and edges are distinct
• Cycle – Simple path in which the first and last vertices are the same.
4
2
1
3
5
6
7
8
10
9
Graphs Terms
• Connected Graph – A graph is connected if there is
a path from every vertex to every other vertex in the
graph.
Graphs Terms
• Complete Graph – A graph where all edges are
present.
Graphs Terms
• Spanning Tree –
– black edges part of the spanning tree
– pink edges not
Graphs Terms
• Compliment –
Graphs Terms
• Clique – A maximum complete subgraph, or simply subgraph, which is not a part of any larger
complete subgraph. The graph shown below has three cliques induced by the sets of vertices {1, 2}, {1, 3,
5}, and {3, 4, 5, 6}.
Graphs Terms
• Bipartite – A bipartite graph is a simple graph where the set of vertices can
be separated into two subsets, called parts, so that every edge in the graph joins
vertices from separate parts. For example, below shows a simple graph which is
also a bipartite graph because it may be divided into two parts, given by the
subsets {1, 2} and {3, 4, 5}, where every edge in the graph goes from a vertex in
one part to a vertex in the other part.
Matrix Implementation
List Implementation
List vs. Matrix
• List Implementation
– Space = E + V
– Finding an edge is proportion to V
– Sparse Graphs??
• Matrix Implementation
– Space = V2
– Finding an edge is constant
– Dense Graphs??
Graph Traversals
• Breadth First Search
• Depth First Search
• Euler Path
Download