1 / 54

Introduction to Computer Science 2 Introduction to Graphs

Introduction to Computer Science 2 Introduction to Graphs. Prof. Neeraj Suri. Utility  + Definitions  Computer Representation Graph Applications (Spanning trees, path problems, flow problems, etc). SW Programs…. Start. A.

major
Télécharger la présentation

Introduction to Computer Science 2 Introduction to Graphs

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. Introduction to Computer Science 2Introduction to Graphs Prof. Neeraj Suri Utility  + Definitions  Computer Representation Graph Applications (Spanning trees, path problems, flow problems, etc)

  2. SW Programs… Start A • Determine the program sequence that exercises all the branches such that repeating any branches happens the least # of times • (or: cover all branches without repeating any branch) • classical basis for SW & Security testing • basis for linkers/compilers B C D E End

  3. Graph Theory • Representation of objects & their mutual relations • Computer Networks/Cellular (Mobile) Coverage • Flow control (networks routing, airline/resource scheduling…) • VLSI Chip Layouts, Chip testing • SW program flow/testing, security access control … • Graphs offer fundamental data & problem representation structures (+ solution basis) for CS problems.

  4. The Königsberg Bridge Problem In 1736 Leonhard Euler, a mathematician, asked regarding his hometown Königsberg: Solutio problematis ad geometriam situs pertinentis? “Is there a path, such that each of the seven bridges are crossed and exactly once (and returns to the starting point)?”

  5. C A D Graphical Abstraction C • “ with a pencil can you trace all the bridges (edges) only once without lifting your pencil?” A D B B C A B The Graph D

  6. 1. General Definitions Graph types Vertices, edges, paths, cycles Isomorphic graphs Connected graphs etc

  7. Definition: Graph • A Graph G = ( V, E ) consists of: • A set V = { v1, ..., vn } of vertices (nodes), and • A set E V  V of edges • In a directed graph, edges are ordered pairs of vertices (vi, vj)  E, that represent an edge from vitovj C A B D

  8. Is this a graph? A Graph G = ( V, E ) consists of • A set V = { v1, ..., vn } verticesand • A set E  V  V of edges Strictly, according to the definition, the parallel edges are actually not “allowed” (unless each of the parallel edges represents a different “directed” edge) • Generally we will not use any parallel edges in our graphs

  9. Example: Undirected Graph v2 • G = ( V, E ) with • V = { v1, v2, v3, v4, v5 } • E = { (v1,v3), (v1,v2), (v2,v5), (v2,v4), (v3,v4), (v4,v5) } • E = { (v3,v1),(v2,v1), … v1 v5 v3 v4

  10. Example: Directed Graph v2 • G = ( V, E ) with • V = { v1, v2, v3, v4, v5 } • E = { (v1,v3), (v1,v2), (v2,v5), (v2,v4), (v3,v4), (v4,v5) } v1 v5 v3 v4

  11. Definitions (1) • A graph G = ( V, E ) is called • Vertex finite, if | V | <  and • Edge finite, if | E | <  . • Every vertex finite graphs is edge finite (when multiple edges are excluded) • Not every edge finite graph is vertex finite! • Generally we will consider only vertex finite graphs (also easier to draw …) • Two vertices are adjacent when they are connected by an edge (neighbor vertices)

  12. Definitions (2) v2 • (self) loop = edge with the same start and end vertex • Every undirected graph can also be represented as a directed graph • Multiple (unidirectional) edges between two vertices are called parallel. • Graphs without parallel edges and self-loops are called simplegraphs (our primary usage for the lectures!!) v1 v5 v3 v4

  13. Definitions (3) • For a graph vertex v in a graph G = ( V, E ) one can define the predecessorand successor: • P(v) = { w | (w,v)  E } • S(v) = { w | (v,w)  E } • The set N(v) of neighborsof v is • N(v) = P(v)  S(v) • For undirected graphs: • N(v) = { w | (v,w)  E or (w,v)  E } • For a vertex v, edges either starting or ending in v are called incidentedges

  14. Example v2 • P(v2) = { v1, v4 } • S(v4) = { v2, v3, v5 } • P(v1) = { } • N(v5) = { v2, v4 } • A directed graph is completely defined through the sets of predecessors and successors of each vertex • An undirected graph is defined by the set of neighbors of each vertex v1 v5 v3 v4

  15. Graphs Graph Degree Degree: # of edges incident at a vertex

  16. Example: Undirected Graph v2 • Sum of degrees equals twice the # of edges ∑ d(v) = 2|E| • # of vertices of odd degree is even v1 v5 Degree: # of edges incident at a vertex v3 v4

  17. Definitions (4) • The degreed of a vertex v V is the number of edges incident on it • For directed graphs: • Out-degree: d+(v) = number of edges starting in v • In-degree: d-(v) = number of edges ending in v • Vertices with degree 0 are isolated vertices • For every directed graph:  d+(vi) =  d-(vi) • Sum of degrees equals twice the # of edges ∑ d(v) = 2E • # of vertices of odd degree is even n n i=1 i=1

  18.  d+(vi) =  d-(vi) ∑ d(v) = 2E Example v2 • d+(v5) = 0 d-(v5) = 2 • d+(v4) = 3 d-(v3) = 2 i d+(vi) = 2 + 1 + 0 + 3 + 0 = 6 i d-(vi) = 0 + 2 + 2 + 0 + 2 = 6 v1 v5 v3 v4

  19. Definitions (5) • A graph whose vertices all have the same degree is called regular • In a connected graph every vertex is connected with each other • A graph G' = ( V', E' ) is a subgraphof G if: V  V' & E  E' • i.e., G  G'. • A clique is a maximal connected subgraph.

  20. Clique of G Example Graph G Subgraph G'

  21. Definitions (6) • A partial graph G' = ( V', E' ) consists of a subset of vertices and their respective incident edges: E' = { (v,w) | v,w  V' and (v,w)  E } (unlike a classical sub-graph, this is edge-complete for the covered vertices)

  22. Example Graph G Subgraph G' Partial Graph G'

  23. Definitions (7) • For any graph: • Every graph is its own subgraph • A subgraph of a subgraph of G is a subgraph of G • A single vertex from V is a subgraph of G • An edge e  E with its connecting vertices is a subgraph of G • Two or more subgraphs, that share no edges, are called edge disjoint • Two or more subgraphs that share no vertices, are called vertex disjoint

  24. Isomorphism • Two graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic, if a bijection exists  : V1  V2, s.t.: (v,w)  E1 iff. ((v), (w))  E2 • Isomorphic graphs have the same (graph theoretical) properties: • Same number of vertices • Same number of edges • Same number of vertices with a certain degree • equivalency: one-to-one correspondence across vertices and edges

  25. Example: Isomorphic Graphs v5 G1 = (V1, E1) G2 = (V2, E2)  e a  v4  v3       b d  c  v1 v2  •  represents the bijective function • Check if the condition (v,w)  E1  ((v), (w))  E2 holds!

  26. Example: Isomorphic Graphs (2) w3 w1 w2 v1 v2 v6 v3 v5 v4 w4 w5 w6

  27. Example: Isomorphic Graphs (3) • Yes – “see” structural similarities (cuboid) • Isomorphisms are not always easy to see • Are these isomorphic ?

  28. Example: Isomorphic Graphs (4) • Isomorphic? • No – Same number of vertices but “other” edges

  29. Operations on Graphs • Inverse/Converse graph: • G = (V,E) is a directed graph. The converse G-1 = (V,E-1) of G is a graph for which: E-1 = { (u,v) | (v,u)  E } • E.g., the direction of the edges is reverse • G1 = (V1, E1) and G2 = (V2,E2) are graphs • Union of G1 and G2: G1 G2 = (V1  V2, E1  E2) • Intersection of G1 and G2: G1  G2 = (V1  V2, E1  E2 ) • Ring sum of G1 and G2: G1 G2 = ( V1  V2, (E1  E2) - (E1  E2) ) • E.g., the ring sum contains the union of the vertices and all the edges that are either in G1 or G2, but not in both

  30. Operations on Graphs (2) • For a directed graph G = ( V, E ) one can define: G = G  G-1 • G transforms every edge to a double edge, which is the same as an undirected edge • Often G is called assigned undirected graph • ...sometimes called

  31. Graphs

  32. Paths in Graphs • How does one reach vertex vk from v1 in a graph G = ( V, E )? • A path is a sequence of vertices p = v1, v2, ...,vk, with (vi,vi+1)  E for 1  i < k. • When G is a directed graph, then p is a directed path • For a path p = v1, ..., vk, v1 is the starting vertex and vk the ending vertex

  33. Paths in Graphs (2) • A path p is (vertex) simple, if every vertex only occurs once in the path • A path is edge simpleif every edge occurs only once • An edge simple path is known as a walk

  34. Cycles • A cycle is a path, where the starting and ending vertex is the same • An edge simple cycle is one where all edges appear only once • A vertex simple cycle is one where all vertices (except starting/ending) appear only once

  35. Example • Path p1 = v2, v5, v4p2 = v1, v3, v4, v2, v5 • No path: v2,v3,v5 • Vertex simple path: p3 = v1, v2, v3, v4, v5 • Walk (Edge Simple): p4 = v1, v2, v3, v4, v2, v5 • path p4 is edge but not vertex simple, but every vertex simple graph is also edge simple • Full walk (covering _all_ edges): v3, v1, v2, v3, v4, v2, v5, v2 • Cycle p5 = v1, v3, v4, v2, v1 • Edge simple cycle p6 = v1, v3, v4, v2, v1 v4 v3 v1 v5 v2

  36. Definitions (8) • Composition of paths: • p1 = u1, u2, ..., ui and p2 = v1, v2, ..., vk are two paths, with ui = v1. The concatenation p1 p2of p1 und p2 is defined as: p1 p2 = u1, u2, ..., ui, v2, ..., vk. • Length of a path: • The length ||p|| of a path line p = v1, v2, ..., vk is the number of edges in p • The vertices between which there is a path are called connected vertices • When every pair of vertices in an undirected graph are connected, the graph is connected

  37. Un- (or Dis-) Connected Graphs • An un-connected graph consists of one or more components, that are themselves connected graphs v6 v4 v3 v8 v1 v7 v5 v2

  38. Definitions (9) • Cut-vertex/Articulation-vertex/Cut sets: • A cut-vertex is a vertex for a connected graph, which if removed cuts the graph into two or more connected graphs • The cut-vertices of G is sometimes called vertex cut or separating set (…also vertex cut set…) v6 v8 v4 Cut-vertex: eg. v3 v3 v1 v2 v5 v7 Not cut-vertex: eg. v2

  39. Definitions (10) • In a connected graph G, an edge is called cut-edge if removal of it the graph is split in one or more components. • A cut set (or edge cut) of G is a set of edges, where by removal from G, G is split in one or more components. Note: Not a set of cut-edges! • Graphs without cut-edges are called multiple connected graphs. They are important for communication networks (fault-tolerance) • A scaffolding (also: skeleton, spanning tree, more later) is a subgraph G‘ = (V, E‘) of a graph G = (V, E) with the same set of vertices and a minimal number of edges E‘  E such that G‘ is connected (cycle free?)

  40. Example v6 v8 v4 • Only cut-edge (v5, v7) • Apart from v7: several cut sets, e.g.: { (v3, v5), (v3, v6) } or { (v1, v3) , (v2, v3), (v4, v3) } • Excluding v7: Graph is multiple connected v3 v1 v2 v5 v7

  41. Cut-Set/Separability Applications • Finding connectivity for fault tolerance • Cutting the graph into parts s.t the min. number of edges get cut: • Finding VLSI layouts layers with minimal interconnect wiring • Cutting graph into (almost) equal components • Power distribution; Cellular network base-station layouts • Route distributions

  42. Euler Graphs • Def.: The Euler line of a graph is a cyclic edge simple path (closed walk/circuit) which includes all edges • [Euler Ckt: contains each edge once only] • Def.: A graph, where an Euler line exists, is an Euler graph Euler Graph Euler Graph?

  43. Theorem of Euler Graphs • Theorem: • A connected graph is an Euler graph iff all vertices have an even degree • Answers the Königsberg bridge problem: C C A B A D Pregel Representation as Graph D B

  44. Proof (1) • Connected Graph G • All vertices in G have even degree : • As G is an Euler graph, a edge simple cyclic path exists p = v1,v2,...,vk, v1 which includes all edges • In an edge simple cyclic path every vertex in p is “reached” over one edge and “left” over another, thus the degree of every visited vertex is even • As the graph is connected, the cycle covers all vertices. Hence Prop. 2 holds for all vertices in p   G is an Euler graph

  45. Proof (2) • Connected Graph G • All vertices in G have even degree : (Idea): 1. Start with any vertex (with incident edges) and follow any edge of a path leaving the vertex. As the degree of every visited node is even there must be an “exit” edge to take for every visited vertex, until we reach the originating node which only has one non-visited edge.  G is an Euler graph

  46. Proof (3) • Connected Graph G • All vertices in G have even degree : (Idea): 2. Now remove the found cycle. For every vertex the removed number of edges will be even. Therefore only vertices with degree 0 or an even degree are left. Continue from 1. until all edges are visited.  G is an Euler graph

  47. Proof (4) • Connected Graph G • All vertices in G have even degree : (Idea): 3. All cycles can be composed, whereby at the intersections, first the first the new cycle is visited and then the rest of the original cycle.  G is an Euler graph

  48. Well known Euler Graphs “Star of David” “Mohammed‘s Scimitars”

  49. Theorem of Euler Graphs • Euler Path (not circuit or closed walk) • each edge is covered once and only once • Condition: Iff it is connected & has at most 2 vertices of odd degree

More Related