SlideShare una empresa de Scribd logo
1 de 23
Graphs and Trees




                Mathematical
                Structures for
              Computer Science
                           Chapter 5




Section 5.1 © 2006 W.H. Freeman & Co.
 Copyright                               
   Graphs and Their RepresentationsGraphs and Trees
                                                MSCS Slides
Definitions of a Graph

    ●     DEFINITION (INFORMAL): GRAPH A graph is a
          nonempty set of nodes (vertices) and a set of arcs (edges) such
          that each arc connects two nodes.
    ●     Our graphs will always have a finite number of nodes and arcs.
    ●     Example: The set of nodes in the airline map below is {Chicago,
          Nashville, Miami, Dallas, St. Louis, Albuquerque, Phoenix,
          Denver, San Francisco, Los Angeles}. There are 16 arcs;
          Phoenix–Albuquerque, Chicago−Nashville, Miami−Dallas,
          and so on.




Section 5.1                       Graphs and Their Representations          2
Formal Definition of a Graph

    ●     The informal definition of a graph works quite well if
          we have the visual representation of the graph before
          us to show which arcs connect which nodes.
    ●     But without the picture, we need a concise way to
          convey this information.
    ●     DEFINITION (FORMAL): GRAPH A graph is an ordered
          triple (N, A, g) where:
           ■
              N = a nonempty set of nodes (vertices)
           ■
              A = a set of arcs (edges)
           ■
              g = a function associating with each arc a an unordered pair
              x–y of nodes called the endpoints of a




Section 5.1                       Graphs and Their Representations           3
Formal Definition of a Graph: Example

    ●     Sketch a graph having nodes {1, 2, 3, 4, 5}, arcs {a1,
          a2, a3, a4, a5, a6}, and function g(a1) = 1–2, g(a2) = 1–
          3, g(a3) = 3–4, g(a4) = 3–4, g(a5) = 4–5, and g(a6) =
          5–5.




Section 5.1                     Graphs and Their Representations   4
Directed Graphs

    ●     Directed graph: the arcs of a graph begin at one node
          and end at another.
    ●     DEFINITION: DIRECTED GRAPH A directed graph
          (digraph) is an ordered triple (N, A, g) where:
              ■
                  N = a nonempty set of nodes
              ■
                  A = a set of arcs
              ■
                  g = a function associating with each arc a an ordered pair (x,
                  y) of nodes where x is the initial point and y is the terminal
                  point of a
    ●     A directed graph, therefore, has a direction associated
          with each arc.



Section 5.1                            Graphs and Their Representations        5
Directed Graphs: Example

    ●     In the example below there are four nodes and five
          arcs.
    ●     The function g associating arcs with endpoints
          performs the mapping g(a1) = (1, 2), meaning that arc
          a1 begins at node 1 and ends at node 2. Also, g(a3) =
          (1, 3), but g(a4) = (3, 1).




Section 5.1                   Graphs and Their Representations    6
Other Forms of Graphs

    ●     Besides imposing direction on the arcs of a graph, we may
          want to modify the basic definition of a graph in other
          ways.
    ●     Labeled graph:A graph whose nodes carry identifying
          information, such as the names of the cities in the map of
          airline routes.
    ●     Weighted graph: A graph where each arc has some
          numerical value, or weight, associated with it. For
          example, a graph that indicates the distances of the various
          routes in the airline map.
    ●     The term “graph” is used to mean an undirected graph. To
          refer to a directed graph, one always says “directed graph.”



Section 5.1                      Graphs and Their Representations    7
Applications of Graphs

    ●     Although the idea of a graph is very simple, an amazing number
          of situations have relationships between items that lend
          themselves to graphical representation.
           ■
              Graphical representations of partially ordered sets:
                   • (Hasse diagrams) were introduced in Chapter 4.
              ■
                  A PERT chart (e.g., Figure 4.7) is a directed graph. The E-R
                  diagram (e.g., Figure 4.10) is a graph.
              ■
                  The commutative diagram illustrating composition of
                  functions (see Figure 4.23) is a directed graph.
              ■
                  Chapter 7 will introduce logic networks and represent them
                  as directed graphs.
              ■
                  Directed graphs will also be used to describe finite-state
                  machines in Chapter 8.
              ■
                  As seen earlier, the airline route map was a graph.
                   • Any representation of transportation routes is a graph (road
                     maps, computer networks, water pipelines, etc.).
Section 5.1                              Graphs and Their Representations           8
Graph Terminology

    ●     Two nodes in a graph are adjacent if they are the endpoints associated
          with an arc. 1 and 3 are adjacent nodes, but 1 and 4 are not.
    ●     A loop in a graph is an arc with endpoints n–n for some node n; arc a3
          is a loop with endpoints 2–2.
    ●     A graph with no loops is loop-free.
    ●     Two arcs with the same endpoints are parallel arcs; arcs a1 and a2 are
          parallel.
    ●     A simple graph is one with no loops or parallel arcs.
    ●     An isolated node is adjacent to no other node; 5 is an isolated node.
    ●     The degree of a node is the number of arc ends at that node.
              ■
                  Nodes 1 and 3 have degree 3, node 2 has degree 5, node 4 has degree 1,
                  and node 5 has degree 0.




Section 5.1                                Graphs and Their Representations                9
Graph Terminology
    ●     Because the function g that relates arcs to endpoints in the
          formal definition of a graph is indeed a function, each arc has a
          unique pair of endpoints.
              ■
                  If g is a one-to-one function, then there is at most one arc
                  associated with a pair of endpoints; such graphs have no parallel
                  arcs.
    ●     A complete graph is one in which any two distinct nodes are
          adjacent.
    ●     A subgraph of a graph consists of a set of nodes and a set of
          arcs that are subsets of the original node set and arc set,
          respectively, in which the endpoints of an arc must be the same
          nodes as in the original graph.
              ■
                  Below is a complete subgraph of the graph from the previous slide.




Section 5.1                              Graphs and Their Representations             10
Graph Terminology
    ●     A path from node n0 to node nk is a sequence
              n0, a0, n1, a1, ... , nk − 1, ak − 1, nk
          of nodes and arcs where, for each i, the endpoints of arc ai are
          ni–ni + 1. If such a path exists, then nk is reachable n0.
              ■
                  In Figure seen here, one path from node 2 to node 4 consists of the
                  sequence 2, al, 1, a2, 2, a4, 3, a6, 4.


    ●     The length of a path is the number of arcs it contains; if an arc
          is used more than once, it is counted each time it is used.
              ■
                  The length of the path described above from node 2 to node 4 is 4.
    ●     A graph is connected if there is a path from any node to any
          other node.
    ●     A cycle in a graph is a path from some node n0 back to n0, where
          no arc appears more than once in the path sequence, n0 is the
          only node appearing more than once, and n0 occurs only at the
          ends.
Section 5.1                              Graphs and Their Representations           11
Bipartite Complete Graphs

    ●     DEFINITION: BIPARTITE COMPLETE GRAPH A graph
          is a bipartite complete graph if its nodes can be partitioned
          into two disjoint nonempty sets N1 and N2 such that two nodes x
          and y are adjacent if and only if x ∈ N1 and y ∈ N2. If N1 = m
          and N2 = n, such a graph is denoted by Km,n.
    ●     The figure below is not a complete graph because it is not true
          that every node is adjacent to every other node.
    ●      However, the nodes can be divided into two disjoint sets, {1, 2}
          and {3, 4, 5}, such that any two nodes chosen from the same set
          are not adjacent but any two nodes chosen one from each set are
          adjacent.




Section 5.1                        Graphs and Their Representations        12
Isomorphic Graphs

    ●     Two graphs may appear quite different in their visual
          representation but still be the same graph according to our
          formal definition.
    ●     The graphs in the figures below are the same—they have
          the same nodes, the same arcs, and the same arc-to-
          endpoint function.
    ●     Structures that are the same except for relabeling are called
          isomorphic structures.




Section 5.1                      Graphs and Their Representations     13
Isomorphic Graphs

    ●     DEFINITION: ISOMORPHIC GRAPHS Two graphs (N1, A1,
          g1,) and (N2, A2, g2) are isomorphic if there are bijections f1: N1
          → N2 and f2: A1 → A2 such that for each arc a ε A1, g1(a) = x–y
          if and only if g2[ f2(a)] = f1(x)–f1(y).
    ●     The bijections for the isomorphic graphs below are:




Section 5.1                        Graphs and Their Representations         14
Isomorphism in Simple Graphs

    ●     Graph isomorphism is easier to establish if we restrict our
          attention to simple graphs.
    ●     If one can find an appropriate function f1 mapping nodes to
          nodes, then a function f2 mapping arcs to arcs is trivial
          because there is at most one arc between any pair of
          endpoints.
    ●     THEOREM ON SIMPLE GRAPH ISOMORPHISM
          Two simple graphs (N1, A1, g1) and (N2, A2, g2) are
          isomorphic if there is a bijection f: N1 → N2 such that for
          any nodes ni and nj of N1, ni and nj are adjacent if and only
          if f (ni) and f (nj) are adjacent. (The function f is called an
          isomorphism from graph 1 to graph 2.)

Section 5.1                        Graphs and Their Representations         15
Proving That Graphs Are Not Isomorphic

    ●         To prove that two graphs are not isomorphic, we must
              prove that the necessary bijection(s) do(es) not exist.
    ●         Certain conditions under which it is clear that two graphs
              are not isomorphic are:
              1.    One graph has more nodes than the other.
              2.    One graph has more arcs than the other.
              3.    One graph has parallel arcs and the other does not.
              4.    One graph has a loop and the other does not.
              5.    One graph has a node of degree k and the other does not.
              6.    One graph is connected and the other is not.
              7.    One graph has a cycle and the other does not.




Section 5.1                            Graphs and Their Representations        16
Planar Graphs

    ●     A planar graph is one that can be represented (on a sheet
          of paper, that is, in the plane) so that its arcs intersect only
          at nodes.
    ●     Designers of integrated circuits want all components in one
          layer of a chip to form a planar graph so that no
          connections cross.
    ●     A simple, connected, planar graph (when drawn in its
          planar representation, with no arcs crossing) divides the
          plane into a number of regions, including totally enclosed
          regions and one infinite exterior region.
    ●     Leonhard Euler observed a relationship between the
          number n of nodes, the number a of arcs, and the number r
          of regions in such a graph. This relationship is known as
          Euler’s formula: n − a + r = 2.
Section 5.1                       Graphs and Their Representations       17
Planar Graphs

    ●         THEOREM ON THE NUMBER OF NODES
              AND ARCS For a simple, connected, planar graph
              with n nodes and a arcs:
              1.   If the planar representation divides the plane into r
                   regions, then n − a + r = 2.
              2.   If n ≥ 3, then a ≤ 3n − 6.
              3.   If n ≥ 3 and there are no cycles of length 3, then a ≤
                   2n – 4.
    ●         We can use this theorem to prove that certain graphs
              are not planar.




Section 5.1                          Graphs and Their Representations       18
Homeomorphic Graphs

    ●     DEFINITION: HOMEOMORPHIC GRAPHS Two graphs
          are homeomorphic if both can be obtained from the same graph
          by a sequence of elementary subdivisions in which a single arc
          x–y is replaced by two new arcs xv–vy connecting to a new node
          v.
    ●     The graphs in parts (b) and (c) of the figure below are
          homeomorphic because each can be obtained from part (a) by a
          sequence of elementary subdivisions. (However, neither can be
          obtained from the other by a sequence of elementary
          subdivisions.)




Section 5.1                       Graphs and Their Representations        19
Nonplanar Graphs

    ●     A graph that is planar cannot be turned into a
          nonplanar graph by elementary subdivisions.
    ●     A graph that is nonplanar cannot be turned into a
          planar graph by elementary subdivisions.
    ●     Homeomorphic graphs are either both planar or both
          nonplanar.
    ●     KURATOWSKI THEOREM A graph is nonplanar
          if and only if it contains a subgraph that is
          homeomorphic to K5 or K3,3.
    ●     If a graph has a subgraph homeomorphic to the
          nonplanar graphs K5 or K3,3, then the subgraph—and
          hence the entire graph—is nonplanar.

Section 5.1                   Graphs and Their Representations   20
Adjacency Matrices

    ●     The usual computer representations of a graph involve one of two data
          structures, either an adjacency matrix or an adjacency list.
    ●     Suppose a graph has n nodes numbered n1, n2, ... , nn. This numbering
          imposes an arbitrary ordering on the set of nodes; recall that a set is an
          unordered collection. Having ordered the nodes, we can form an n x n
          matrix where entry i,j is the number of arcs between nodes ni and nj.
          This matrix is called the adjacency matrix A of the graph with respect
          to this ordering. Thus, aij = p where there are p arcs between ni and nj.
    ●     For example, the following graph has a corresponding adjacency
          matrix.




Section 5.1                           Graphs and Their Representations             21
Adjacency Lists

    ●     Many graphs, far from being complete graphs, have relatively few
          arcs. Such graphs have sparse adjacency matrices; that is, the
          adjacency matrices contain many zeros.
    ●     Yet if the graph has n nodes, it still requires n2 data items to represent
          the adjacency matrix, even if many of these items are zero. Any
          algorithm or procedure in which every arc in the graph must be
          examined requires looking at all n2 items in the matrix.
    ●     A graph with relatively few arcs can be represented more
          efficiently by storing only the nonzero entries of the adjacency
          matrix.
    ●     An adjacency list consists of a list for each node of all the
          nodes adjacent to it.
              ■
                  Pointers are used to get us from one item in the list to the next.
                  Such an arrangement is called a linked list.
              ■
                  There is an array of n pointers, one for each node, to get each list
                  started.
Section 5.1                               Graphs and Their Representations               22
Adjacency Lists: Example

    ●     The adjacency list for the graph of the figure on the left contains
          a four-element array of pointers, one for each node.
    ●     The pointer for each node points to an adjacent node, which
          points to another adjacent node, and so forth.
    ●     In the figure, the dot indicates a null pointer, meaning that there
          is nothing more to be pointed to or that the end of the list has
          been reached.




Section 5.1                        Graphs and Their Representations        23

Más contenido relacionado

La actualidad más candente

Graph theory in network system
Graph theory in network systemGraph theory in network system
Graph theory in network systemManikanta satyala
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data StructureKeno benti
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structurehafsa komal
 
Network Topology
Network TopologyNetwork Topology
Network TopologyHarsh Soni
 
Data Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneData Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneDoug Needham
 
Graph: Euler path and Euler circuit
Graph: Euler path and Euler circuitGraph: Euler path and Euler circuit
Graph: Euler path and Euler circuitLiwayway Memije-Cruz
 
Graph in Data Structure
Graph in Data StructureGraph in Data Structure
Graph in Data StructureProf Ansari
 
Adjacency list
Adjacency listAdjacency list
Adjacency listStefi Yu
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory IntroductionMANISH T I
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabatinabati
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1Tech_MX
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - GraphMadhu Bala
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 

La actualidad más candente (20)

Graph theory in network system
Graph theory in network systemGraph theory in network system
Graph theory in network system
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Graph theory
Graph theory Graph theory
Graph theory
 
Network Topology
Network TopologyNetwork Topology
Network Topology
 
Data Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZoneData Structure Graph DMZ #DMZone
Data Structure Graph DMZ #DMZone
 
graph theory
graph theory graph theory
graph theory
 
Presentation on graphs
Presentation on graphsPresentation on graphs
Presentation on graphs
 
Graph: Euler path and Euler circuit
Graph: Euler path and Euler circuitGraph: Euler path and Euler circuit
Graph: Euler path and Euler circuit
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
 
Graph in Data Structure
Graph in Data StructureGraph in Data Structure
Graph in Data Structure
 
Adjacency list
Adjacency listAdjacency list
Adjacency list
 
Graph Theory Introduction
Graph Theory IntroductionGraph Theory Introduction
Graph Theory Introduction
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph theory 1
Graph theory 1Graph theory 1
Graph theory 1
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 

Similar a Graphs and Trees (20)

Unit 2: All
Unit 2: AllUnit 2: All
Unit 2: All
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Cpsc125 ch6sec1
Cpsc125 ch6sec1Cpsc125 ch6sec1
Cpsc125 ch6sec1
 
Cpsc125 ch6sec1
Cpsc125 ch6sec1Cpsc125 ch6sec1
Cpsc125 ch6sec1
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
graph theory
graph theorygraph theory
graph theory
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
Elements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptxElements of Graph Theory for IS.pptx
Elements of Graph Theory for IS.pptx
 
Graphs
GraphsGraphs
Graphs
 
8.-Graphs information technologies graph
8.-Graphs information technologies graph8.-Graphs information technologies graph
8.-Graphs information technologies graph
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Basics of graph
Basics of graphBasics of graph
Basics of graph
 

Más de David Wood

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainDavid Wood
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?David Wood
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...David Wood
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 KeynoteDavid Wood
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221David Wood
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart CityDavid Wood
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software DevelopmentDavid Wood
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsDavid Wood
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelDavid Wood
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301David Wood
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601David Wood
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors KillDavid Wood
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in AustraliaDavid Wood
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsDavid Wood
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social mediaDavid Wood
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's JourneyDavid Wood
 
Open by Default
Open by DefaultOpen by Default
Open by DefaultDavid Wood
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926David Wood
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426David Wood
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesDavid Wood
 

Más de David Wood (20)

Internet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchainInternet of Things (IoT) two-factor authentication using blockchain
Internet of Things (IoT) two-factor authentication using blockchain
 
Returning to Online Privacy?
Returning to Online Privacy?Returning to Online Privacy?
Returning to Online Privacy?
 
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
Methods for Securing Spacecraft Tasking and Control via an Enterprise Ethereu...
 
BlockSW 2019 Keynote
BlockSW 2019 KeynoteBlockSW 2019 Keynote
BlockSW 2019 Keynote
 
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
Returning to Online Privacy - W3C/ANU Future of the Web Roadshow 20190221
 
Privacy in the Smart City
Privacy in the Smart CityPrivacy in the Smart City
Privacy in the Smart City
 
Controlling Complexities in Software Development
Controlling Complexities in Software DevelopmentControlling Complexities in Software Development
Controlling Complexities in Software Development
 
Privacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable ClaimsPrivacy Concerns related to Verifiable Claims
Privacy Concerns related to Verifiable Claims
 
Implementing the Verifiable Claims data model
Implementing the Verifiable Claims data modelImplementing the Verifiable Claims data model
Implementing the Verifiable Claims data model
 
So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301So You Wanna be a Startup CTO 20170301
So You Wanna be a Startup CTO 20170301
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
 
When Metaphors Kill
When Metaphors KillWhen Metaphors Kill
When Metaphors Kill
 
Secularism in Australia
Secularism in AustraliaSecularism in Australia
Secularism in Australia
 
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and PleonasmsMeditations on Writing in Paradoxes, Oxymorons, and Pleonasms
Meditations on Writing in Paradoxes, Oxymorons, and Pleonasms
 
Building a writer's platform with social media
Building a writer's platform with social mediaBuilding a writer's platform with social media
Building a writer's platform with social media
 
Summary of the Hero's Journey
Summary of the Hero's JourneySummary of the Hero's Journey
Summary of the Hero's Journey
 
Open by Default
Open by DefaultOpen by Default
Open by Default
 
Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926Lod Then, Now and Next 20110926
Lod Then, Now and Next 20110926
 
Linked Data ROI 20110426
Linked Data ROI 20110426Linked Data ROI 20110426
Linked Data ROI 20110426
 
Introduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF VocabulariesIntroduction to Linked Data: RDF Vocabularies
Introduction to Linked Data: RDF Vocabularies
 

Graphs and Trees

  • 1. Graphs and Trees Mathematical Structures for Computer Science Chapter 5 Section 5.1 © 2006 W.H. Freeman & Co. Copyright Graphs and Their RepresentationsGraphs and Trees MSCS Slides
  • 2. Definitions of a Graph ● DEFINITION (INFORMAL): GRAPH A graph is a nonempty set of nodes (vertices) and a set of arcs (edges) such that each arc connects two nodes. ● Our graphs will always have a finite number of nodes and arcs. ● Example: The set of nodes in the airline map below is {Chicago, Nashville, Miami, Dallas, St. Louis, Albuquerque, Phoenix, Denver, San Francisco, Los Angeles}. There are 16 arcs; Phoenix–Albuquerque, Chicago−Nashville, Miami−Dallas, and so on. Section 5.1 Graphs and Their Representations 2
  • 3. Formal Definition of a Graph ● The informal definition of a graph works quite well if we have the visual representation of the graph before us to show which arcs connect which nodes. ● But without the picture, we need a concise way to convey this information. ● DEFINITION (FORMAL): GRAPH A graph is an ordered triple (N, A, g) where: ■ N = a nonempty set of nodes (vertices) ■ A = a set of arcs (edges) ■ g = a function associating with each arc a an unordered pair x–y of nodes called the endpoints of a Section 5.1 Graphs and Their Representations 3
  • 4. Formal Definition of a Graph: Example ● Sketch a graph having nodes {1, 2, 3, 4, 5}, arcs {a1, a2, a3, a4, a5, a6}, and function g(a1) = 1–2, g(a2) = 1– 3, g(a3) = 3–4, g(a4) = 3–4, g(a5) = 4–5, and g(a6) = 5–5. Section 5.1 Graphs and Their Representations 4
  • 5. Directed Graphs ● Directed graph: the arcs of a graph begin at one node and end at another. ● DEFINITION: DIRECTED GRAPH A directed graph (digraph) is an ordered triple (N, A, g) where: ■ N = a nonempty set of nodes ■ A = a set of arcs ■ g = a function associating with each arc a an ordered pair (x, y) of nodes where x is the initial point and y is the terminal point of a ● A directed graph, therefore, has a direction associated with each arc. Section 5.1 Graphs and Their Representations 5
  • 6. Directed Graphs: Example ● In the example below there are four nodes and five arcs. ● The function g associating arcs with endpoints performs the mapping g(a1) = (1, 2), meaning that arc a1 begins at node 1 and ends at node 2. Also, g(a3) = (1, 3), but g(a4) = (3, 1). Section 5.1 Graphs and Their Representations 6
  • 7. Other Forms of Graphs ● Besides imposing direction on the arcs of a graph, we may want to modify the basic definition of a graph in other ways. ● Labeled graph:A graph whose nodes carry identifying information, such as the names of the cities in the map of airline routes. ● Weighted graph: A graph where each arc has some numerical value, or weight, associated with it. For example, a graph that indicates the distances of the various routes in the airline map. ● The term “graph” is used to mean an undirected graph. To refer to a directed graph, one always says “directed graph.” Section 5.1 Graphs and Their Representations 7
  • 8. Applications of Graphs ● Although the idea of a graph is very simple, an amazing number of situations have relationships between items that lend themselves to graphical representation. ■ Graphical representations of partially ordered sets: • (Hasse diagrams) were introduced in Chapter 4. ■ A PERT chart (e.g., Figure 4.7) is a directed graph. The E-R diagram (e.g., Figure 4.10) is a graph. ■ The commutative diagram illustrating composition of functions (see Figure 4.23) is a directed graph. ■ Chapter 7 will introduce logic networks and represent them as directed graphs. ■ Directed graphs will also be used to describe finite-state machines in Chapter 8. ■ As seen earlier, the airline route map was a graph. • Any representation of transportation routes is a graph (road maps, computer networks, water pipelines, etc.). Section 5.1 Graphs and Their Representations 8
  • 9. Graph Terminology ● Two nodes in a graph are adjacent if they are the endpoints associated with an arc. 1 and 3 are adjacent nodes, but 1 and 4 are not. ● A loop in a graph is an arc with endpoints n–n for some node n; arc a3 is a loop with endpoints 2–2. ● A graph with no loops is loop-free. ● Two arcs with the same endpoints are parallel arcs; arcs a1 and a2 are parallel. ● A simple graph is one with no loops or parallel arcs. ● An isolated node is adjacent to no other node; 5 is an isolated node. ● The degree of a node is the number of arc ends at that node. ■ Nodes 1 and 3 have degree 3, node 2 has degree 5, node 4 has degree 1, and node 5 has degree 0. Section 5.1 Graphs and Their Representations 9
  • 10. Graph Terminology ● Because the function g that relates arcs to endpoints in the formal definition of a graph is indeed a function, each arc has a unique pair of endpoints. ■ If g is a one-to-one function, then there is at most one arc associated with a pair of endpoints; such graphs have no parallel arcs. ● A complete graph is one in which any two distinct nodes are adjacent. ● A subgraph of a graph consists of a set of nodes and a set of arcs that are subsets of the original node set and arc set, respectively, in which the endpoints of an arc must be the same nodes as in the original graph. ■ Below is a complete subgraph of the graph from the previous slide. Section 5.1 Graphs and Their Representations 10
  • 11. Graph Terminology ● A path from node n0 to node nk is a sequence n0, a0, n1, a1, ... , nk − 1, ak − 1, nk of nodes and arcs where, for each i, the endpoints of arc ai are ni–ni + 1. If such a path exists, then nk is reachable n0. ■ In Figure seen here, one path from node 2 to node 4 consists of the sequence 2, al, 1, a2, 2, a4, 3, a6, 4. ● The length of a path is the number of arcs it contains; if an arc is used more than once, it is counted each time it is used. ■ The length of the path described above from node 2 to node 4 is 4. ● A graph is connected if there is a path from any node to any other node. ● A cycle in a graph is a path from some node n0 back to n0, where no arc appears more than once in the path sequence, n0 is the only node appearing more than once, and n0 occurs only at the ends. Section 5.1 Graphs and Their Representations 11
  • 12. Bipartite Complete Graphs ● DEFINITION: BIPARTITE COMPLETE GRAPH A graph is a bipartite complete graph if its nodes can be partitioned into two disjoint nonempty sets N1 and N2 such that two nodes x and y are adjacent if and only if x ∈ N1 and y ∈ N2. If N1 = m and N2 = n, such a graph is denoted by Km,n. ● The figure below is not a complete graph because it is not true that every node is adjacent to every other node. ● However, the nodes can be divided into two disjoint sets, {1, 2} and {3, 4, 5}, such that any two nodes chosen from the same set are not adjacent but any two nodes chosen one from each set are adjacent. Section 5.1 Graphs and Their Representations 12
  • 13. Isomorphic Graphs ● Two graphs may appear quite different in their visual representation but still be the same graph according to our formal definition. ● The graphs in the figures below are the same—they have the same nodes, the same arcs, and the same arc-to- endpoint function. ● Structures that are the same except for relabeling are called isomorphic structures. Section 5.1 Graphs and Their Representations 13
  • 14. Isomorphic Graphs ● DEFINITION: ISOMORPHIC GRAPHS Two graphs (N1, A1, g1,) and (N2, A2, g2) are isomorphic if there are bijections f1: N1 → N2 and f2: A1 → A2 such that for each arc a ε A1, g1(a) = x–y if and only if g2[ f2(a)] = f1(x)–f1(y). ● The bijections for the isomorphic graphs below are: Section 5.1 Graphs and Their Representations 14
  • 15. Isomorphism in Simple Graphs ● Graph isomorphism is easier to establish if we restrict our attention to simple graphs. ● If one can find an appropriate function f1 mapping nodes to nodes, then a function f2 mapping arcs to arcs is trivial because there is at most one arc between any pair of endpoints. ● THEOREM ON SIMPLE GRAPH ISOMORPHISM Two simple graphs (N1, A1, g1) and (N2, A2, g2) are isomorphic if there is a bijection f: N1 → N2 such that for any nodes ni and nj of N1, ni and nj are adjacent if and only if f (ni) and f (nj) are adjacent. (The function f is called an isomorphism from graph 1 to graph 2.) Section 5.1 Graphs and Their Representations 15
  • 16. Proving That Graphs Are Not Isomorphic ● To prove that two graphs are not isomorphic, we must prove that the necessary bijection(s) do(es) not exist. ● Certain conditions under which it is clear that two graphs are not isomorphic are: 1. One graph has more nodes than the other. 2. One graph has more arcs than the other. 3. One graph has parallel arcs and the other does not. 4. One graph has a loop and the other does not. 5. One graph has a node of degree k and the other does not. 6. One graph is connected and the other is not. 7. One graph has a cycle and the other does not. Section 5.1 Graphs and Their Representations 16
  • 17. Planar Graphs ● A planar graph is one that can be represented (on a sheet of paper, that is, in the plane) so that its arcs intersect only at nodes. ● Designers of integrated circuits want all components in one layer of a chip to form a planar graph so that no connections cross. ● A simple, connected, planar graph (when drawn in its planar representation, with no arcs crossing) divides the plane into a number of regions, including totally enclosed regions and one infinite exterior region. ● Leonhard Euler observed a relationship between the number n of nodes, the number a of arcs, and the number r of regions in such a graph. This relationship is known as Euler’s formula: n − a + r = 2. Section 5.1 Graphs and Their Representations 17
  • 18. Planar Graphs ● THEOREM ON THE NUMBER OF NODES AND ARCS For a simple, connected, planar graph with n nodes and a arcs: 1. If the planar representation divides the plane into r regions, then n − a + r = 2. 2. If n ≥ 3, then a ≤ 3n − 6. 3. If n ≥ 3 and there are no cycles of length 3, then a ≤ 2n – 4. ● We can use this theorem to prove that certain graphs are not planar. Section 5.1 Graphs and Their Representations 18
  • 19. Homeomorphic Graphs ● DEFINITION: HOMEOMORPHIC GRAPHS Two graphs are homeomorphic if both can be obtained from the same graph by a sequence of elementary subdivisions in which a single arc x–y is replaced by two new arcs xv–vy connecting to a new node v. ● The graphs in parts (b) and (c) of the figure below are homeomorphic because each can be obtained from part (a) by a sequence of elementary subdivisions. (However, neither can be obtained from the other by a sequence of elementary subdivisions.) Section 5.1 Graphs and Their Representations 19
  • 20. Nonplanar Graphs ● A graph that is planar cannot be turned into a nonplanar graph by elementary subdivisions. ● A graph that is nonplanar cannot be turned into a planar graph by elementary subdivisions. ● Homeomorphic graphs are either both planar or both nonplanar. ● KURATOWSKI THEOREM A graph is nonplanar if and only if it contains a subgraph that is homeomorphic to K5 or K3,3. ● If a graph has a subgraph homeomorphic to the nonplanar graphs K5 or K3,3, then the subgraph—and hence the entire graph—is nonplanar. Section 5.1 Graphs and Their Representations 20
  • 21. Adjacency Matrices ● The usual computer representations of a graph involve one of two data structures, either an adjacency matrix or an adjacency list. ● Suppose a graph has n nodes numbered n1, n2, ... , nn. This numbering imposes an arbitrary ordering on the set of nodes; recall that a set is an unordered collection. Having ordered the nodes, we can form an n x n matrix where entry i,j is the number of arcs between nodes ni and nj. This matrix is called the adjacency matrix A of the graph with respect to this ordering. Thus, aij = p where there are p arcs between ni and nj. ● For example, the following graph has a corresponding adjacency matrix. Section 5.1 Graphs and Their Representations 21
  • 22. Adjacency Lists ● Many graphs, far from being complete graphs, have relatively few arcs. Such graphs have sparse adjacency matrices; that is, the adjacency matrices contain many zeros. ● Yet if the graph has n nodes, it still requires n2 data items to represent the adjacency matrix, even if many of these items are zero. Any algorithm or procedure in which every arc in the graph must be examined requires looking at all n2 items in the matrix. ● A graph with relatively few arcs can be represented more efficiently by storing only the nonzero entries of the adjacency matrix. ● An adjacency list consists of a list for each node of all the nodes adjacent to it. ■ Pointers are used to get us from one item in the list to the next. Such an arrangement is called a linked list. ■ There is an array of n pointers, one for each node, to get each list started. Section 5.1 Graphs and Their Representations 22
  • 23. Adjacency Lists: Example ● The adjacency list for the graph of the figure on the left contains a four-element array of pointers, one for each node. ● The pointer for each node points to an adjacent node, which points to another adjacent node, and so forth. ● In the figure, the dot indicates a null pointer, meaning that there is nothing more to be pointed to or that the end of the list has been reached. Section 5.1 Graphs and Their Representations 23

Notas del editor