1 / 38

Discrete Structures CISC 2315 FALL 2010

This article provides an overview of graphs and trees, including their components, terminology, and applications. Topics covered include vertices, edges, degrees, adjacency matrices, and connectedness.

wmelissa
Download Presentation

Discrete Structures CISC 2315 FALL 2010

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Discrete StructuresCISC 2315FALL 2010 Graphs & Trees

  2. Graphs • A graph is a discrete structure, with discrete components…

  3. Components of a Graph edge vertex (node)

  4. Vertices • A graph G = (V, E), where V is the set of all the vertices in the graph, and E is the set of all edges in the graph. • The elements of V are typically named u or v.

  5. Types of Edges Note unordered • Undirected edges: • In this case, there is a function ffrom E to • An edge is a loop if f(e) = {u, u} = {u} for some u in V. loop Undirected graph

  6. Types of Edges Note ordered • Directed edges: • In this case, there is a function ffrom E to • An edge is a loop if f(e) = (u, u) for some u in V. loop Directed graph

  7. Graph Terminology • Two vertices u and v in an undirected graph G are adjacent (neighbors) in G if {u,v} is an edge of G. If e={u,v}, then the edge e is called incident with the vertices u and v. Edge e is said to connect u and v. Also, vertices u and v are called endpoints of the edge {u,v}.

  8. Graph Terminology e u v Vertices u and v are adjacent. Edge e is incident with u and v; e connects u and v. Vertices u and v are endpoints of e.

  9. Degree • The degree of a vertex in an undirected graph is the number of edges incident with it. A loop contributes twice to the degree. • A vertex of degree zero is called isolated. A vertex of degree 1 is called pendant.

  10. Graph Terminology e u v What is the deg(u)? What is the deg(v)?

  11. Graph Terminology • In a directed graph G with edge (u,v), u is said to be adjacent to v and v is said to be adjacent from u. Vertex u is the initial vertex and v is the terminal (end) vertex of (u,v). The initial and terminal vertices of a loop are the same.

  12. Graph Terminology e u v Vertex u is adjacent to v and v is adjacent from u. Vertex u is the initial vertex and v is the terminal vertex of edge (u,v).

  13. Degree • The in-degree of a vertex v, deg-(v) in a directed graph is the number of edges with v as their terminal vertex. The out-degree of v, deg+(v), is the number of edges with v as their initial vertex. A loop contributes 1 to both the in-degree and out-degree.

  14. Graph Terminology e u v What is the in-degree of u? the out-degree of u? What is the in-degree of v? the out-degree of v?

  15. Simple Graphs • A graph is simple if it has only one edge connecting each pair of vertices.

  16. Simple Graphs simple not simple

  17. Bipartite Graph • A simple graph G=(V,E) is bipartite if V can be partitioned into disjoint sets V1 and V2 such that every edge in the graph connects a vertex in V1 and a vertex in V2. No edge in G connects either two vertices in V1 or two vertices in V2.

  18. Bipartite Graph

  19. Union of Graphs • The union of two simple graphs G1=(V1,E1) and G2=(V2,E2) is the simple graph

  20. Union of a Graphs

  21. Matrices Used to represent graphs in a computer program. A matrix is a rectangular array of numbers. a11 a12 … a1n a21 a22 … a2n . . . a1m a2m … amn A = This is an m x n matrix.

  22. Adjacent Vertices in a Graph adjacent vertices vertex a g c e b d f

  23. Adjacency Matrix to Represent a Graph a g c e d b f

  24. Incidence to Represent a Graph a g e1 c e7 e6 e e10 e5 e3 e2 e9 e4 b e11 d e8 f

  25. Path • A path is a sequence of edges that begins with a vertex of the graph and travels along edges of the graph, always connecting pairs of adjacent vertices. • A path of length n from u to v in an undirected graph is a sequence of edges e1,…,en that begins with u and ends with v. The path is a circuit if u=v. The path passes through the vertices that are visited, and it traverses the edges on the path. A path or circuit is simple if it doesn’t contain the same edge more than once.

  26. Path in Matrix an Undirected Graph u v

  27. Connectedness • An undirected graph is connected if there is a path between every pair of distinct vertices in the graph.

  28. Is this graph connected?

  29. Trees • Note that a tree is a connected undirected graph that has no simple circuits.

  30. Path • A path of length n from u to v in a directed graph is a sequence of directed edges e1,…,en that begins with u and ends with v. The path is a circuit if u=v. The path passes through the vertices that are visited, and it traverses the edges on the path. A path or circuit is simple if it doesn’t contain the same edge more than once.

  31. Circuit in a Directed Graph u=v

  32. Connectedness • A directed graph is strongly connected if there is a path from a to b and from b to a whenever a and b are vertices in the graph. • A directed graph is weakly connected if there is a path between every two vertices in the underlying undirected graph.

  33. Is this graph strongly/weakly connected?

  34. Example Applications of Graphs • Designing airplane routes • Modeling the interconnections and information flow in local and wide area computer networks • Models of ecologies • Finding the shortest path between two locations (uses distances along the edges) • Solving search problems in artificial intelligence

  35. Lists - revisited • A list is a finite ordered sequence of zero or more elements that can be repeated. • The difference betweenlists andtuples is in what parts can be randomly accessed. • Head (L) and Tail (L) is • Memory representation of a list in the computer head (L) = b tail (L) L d b c e cons (a,L) a

  36. Computer representation of a tree a a b c d b c d e e

  37. Binary Tree a a b c b c e d d e Binary trees can be used to represent sets whose elements have some ordering. Such a tree is called a binary search tree and has the property that for each node Of the tree, each element in its left subtree precedes the node element and each Element in its right subtree succeeds the node element.

  38. a 2 1 f 3 1 3 1 2 2 2 g c e 1 1 2 d Spanning Trees – Kruskal’s Algorithm L= {{a,b},{c,d},{d,g},{e,f},{f,g},{a,f},{b,c},{c,g},{d,e},{e,g},{a,g},{b,g}} 1 1 1 1 1 2 2 2 2 2 3 3 b • Kruskal’s Algorithm: • Sort the edges of the graph by weight, and let L be the sorted list • Let T be the minimal spanning tree and initialize T : = 0. • For each vertex v of the graph, create the equivalence class [v] = {v}. • while there are 2 or more equivalence classes do • Let {a,b} be the edge at the head of L: • L := tail (L); • if [a} not = [b] then • T:= T U {{a,b}}; • Replace the equivalence classes [a] and [b] by [a] U [b] • fi • od

More Related