Announcements PA3 available, due 03/30, 11:59p. Graphs!! G = (V,E) Tree: Simple (sub)Graph: Spanning subgraph: Connected (sub)Graph: Spanning tree: Connected component:
G = (V,E) Graph Vocabulary: Use the graph G to answer these questions. |V| = n 1. List the edges incident on vertex b: |E| = m 2. What is the degree of vertex h? 3. List all the vertices adjacent to vertex i: 4. Describe a path from p to o: 5. Describe a path from 6 to g: 6. List the vertices in the largest complete subgraph in G: 7. Describe the smallest connected subgraph in G: 8. Describe the connected components in G: 9. How many edges in a spanning forest of G? 10. How many paths from 0 to 9? 11. Can you draw G with no crossing edges?
What’s left? How do we get from here to there? Need: 1. Common Vocabulary 2. Graph implementation 3. Traversal 4. Algorithms.
Graphs: theory that will help us in analysis Running times often reported in terms of n, the number of vertices, but they often depend on m, the number of V edges. a b How many edges? d U X Z h At least: c e G = (V,E) W g connected – |V| = n f Y |E| = m not connected - At most: simple - not simple - Relationship to degree sum:
Thm: Every minimal connected graph G=(V,E) has |V|-1 edges. Proof: Consider an arbitrary minimal connected graph G=(V,E). V a Lemma: Every connected subgraph of G is minimally connected. U X Z (easy proof by contradiction) h c e IH: For any j < |V|, any minimal connected graph of j vertices has W j-1 edges. f Y Suppose |V| = 1: A minimal connected graph of 1 vertex has no edges, and 0 = 1-1. Suppose |V| > 1: Choose any vertex and let d denote its degree. Set aside its incident edges, partitioning the graph into _______ components, C 0 =(____,____), ... C d =(____, ____), each of which is a minimal connected subgraph of G. This means that |E k | = ________ by _____. Now we’ll just add up edges in the original graph:
Graphs: Toward implementation…(ADT) Functions: (merely a smattering…) V b insertVertex(pair keyData) d X Z insertEdge(vertex v1, vertex v2, pair keyData) h e W g removeEdge(edge e); f removeVertex(vertex v); Y Data: incidentEdges(vertex v); Vertices areAdjacent(vertex v1, vertex v2); Edges origin(edge e); + some structure that reflects destination(edge e); the connectivity of the graph
Graphs: Adjacency Matrix Some functions we’ll compare: u a c insertVertex(vertex v) b d removeVertex(vertex v) v w z areAdjacent(vertex v, vertex u) incidentEdges(vertex v) u v w z u a u v b v w c w z d z
Graphs: Adjacency List Some functions we’ll compare: insertVertex(vertex v) u a c removeVertex(vertex v) b d areAdjacent(vertex v, vertex u) v w z incidentEdges(vertex v) u a v b w c z d
Recommend
More recommend