Graphs CS240341 Graphs Used for representing manytomany relationships
- Slides: 10
Graphs CS-240/341
Graphs • Used for representing many-to-many relationships – can take two forms • directed (digraph) - a finite set of elements called vertices (nodes) connected by a set of directed edges (arcs) – G = {V} {E} where • V= {V 1, V 2, V 3…Vn} E= { (Vm 1, Vn 1), (Vm 2, Vn 2)…(Vmx, Vny) } 1 4 2 5 3
Edges • Represent a relationship between two verticies – to ; in a digraph represents that A is adjacent to B – from ; B is adjacent from A A 25 B • Edges may also have an associated weight or value – if the vertices represent cities then the edge may represent a connection (road) between them and the weight may represent the distance and the direction may represent a one way street – if the graph represents a network of active components (p-n junctions, diodes/transistors) then the direction represents the direction of the pn junctions and the edges represent the way the components are connected and the weights represent the forward resistance of the junction (backward resistance is infinity)
Digraph Abstract Data Type • Data Elements: – collection of vertices and a collection of edges and weights • Basic Operations: – – – – Create an empty digraph Check if the digraph is empty Destroy a digraph Insert a new vertex Insert a new edge between two existing vertices Delete a vertex and all directed edges to or from it Delete a directed edge between to vertices search for an edge value
Digraph representation • Adjacency Matrix Representation to from 4 0 5 3 3 2 1 5 2 6 4 0 1 2 3 4 0 0 5 2 4 0 1 0 0 5 0 0 2 0 1 0 0 6 3 0 0 0 4 0 0 0
Digraph Representation • Adjacency List – use an array of pointers to be the heads of a list of adjacencies for each vertex 4 0 5 3 3 1 5 1 2 5 2 4 6 3 2 1 0 4 5 2 6 4 2 3 1 2 3 4
Graph Traversal • Depth First 0 1 5 1 2 5 2 4 6 2 3 3 4 1 2 3 1. Visit the start vertx V 4 2. For each vertex adjacent to V do the following: if w has not been visited, apply the depth-first search algorithm starting with w connecting the vertices along the way will produce a spanning tree 4 0 visited Spanning tree 5 3 V 3 2 1 4 0 5 3 5 2 6 4 3 2 1 5 2 6 4
Graph Traversal • Breadth First 1. Visit the start vertex V 2 Initialize a queue to contain only the start vertex 3. While the queue is not empty do the following Rempve vertex V from the queue For all vertices w adjacent to v do the following: If w has not been visited then Visit W Add W to the queue
Spanning Trees • The set of vertices and edges produced by a DFS traversal produces what is known as a spanning tree – if the DFS doesn’t include all of the vertices, then do another DFS starting at a vertex not yet in the tree. This may have to be done a number of times but will eventually produce a set disjoint (not connected) spanning trees called a spanning forest.
Degree of a vertex • In degree is the number of edges coming into a vertex • Out degree is the number of edges going out of a vertex 3 In degree = 3 Out degree = 2
- Representing proportional relationships lesson 3-1
- Representing graphs and graph isomorphism
- Representing graphs and graph isomorphism
- Lesson 10 interpreting graphs of proportional relationships
- Proportional graph
- Good and bad state graphs in software testing
- Comparing distance/time graphs to speed/time graphs
- Graphs that enlighten and graphs that deceive
- Polynomial function form
- The circular chart used to remember color relationships is?
- Karttecken färger