SlideShare una empresa de Scribd logo
1 de 15
Descargar para leer sin conexión
Lecture 8




                                  Graph
                             Data Structure (CS221)




                       Abdisalam Issa-Salwe

                        Taibah University
           College of Computer Science & Engineering
                 Computer Science Department




Outline

 Graph Data Type
 Graph Concepts
 Graph Data Structure
 Directed/undirected Graph
 Graph Relationship
 Graph implementation



                                                       2




                                                           1
Learning Outcomes

 Describe a Graph ADT
 Understand how to implement a Graph
 ADT
 Describe algorithms to traverse a graph




                                                             3




The Graph ADT
 A graph is a collection of nodes connected by edges
 If an edge e connects vertex u and v, we denote it as (u;
 v).if u = v, e is called a loop




                                                             4




                                                                 2
Graph Concepts

 A tree is an example of a graph
 In a graph a node may be it’s own
 ancestor
 In general a graph has no root node
 Formally, a graph is an ordered pair of
 sets (N,E)
 Both nodes and edges may have data
 values associated

                                                   5




Graph Data Structure (cont…)
 Graph is a data structure that consists of a set of
 nodes and a set of edges that relate the nodes
 to one another
 It is made up of a set of nodes called vertices
 and a set of lines called edges (or arcs) that
 connect the nodes.
 If the edges in the graph have no direction it is
 called an undirected graph.
 A graph whose edges are directed from one
 vertex to another is called a directed graph, or
 digraph

                                                   6




                                                       3
Graphs Data Structure (cont…)
More definition:
• Like a tree, is a NON-Linear structure
 consisting of nodes and links between
  the nodes
 Types:    Undirected graph

              Directed graph

Graphs are often used to solve problems

                                                   7




Undirected Graph


 • An undirected graph is a set of nodes
   and a set of links between the nodes.
 • Each NODE is called a VERTEX
                                      V0      V1
 • Each LINK is called an EDGE             E0
 • The order of the two connected vertices
   is unimportant
 ex: whether        “V0 connects V1” or
                    “V1 connects V0”
        means the same thing
                                                   8




                                                       4
Undirected Graph examples
                        5 vertices
                         6 edges


                   V0
           E0            E1             V2        E5

      V1                        E4
           E2                      V4
                 V3      E3


                                                            9




Undirected Graph examples
                5 vertices    6 edges
 V3                           E4
                   V2

       E2               E1                   E0   V0
                        V1



            E3                               V4        E5


  In drawing, the placement of the vertices
 is UNIMPORTANT same as previous graph
                                                            10




                                                                 5
Directed Graph

A directed graph is a finite set of vertices
together with a finite set of edges. If both
are empty then we have an empty graph


V1 SOURCE                      V0
                                                V2
                   V1
                                           V4
V3   TARGET                V3

                                                     11




  Directed Graph

• Loops: a loop connects a vertex to itself
                               LOOP
                Vertex

• Path: is a sequence of vertices
    P0, P1, P2,… Pn , each adjacent pairs of
    vertices Pi and Pi+1 are connected by an edge

                        path
              V1                      V3
          SOURCE                    TARGET
                                                     12




                                                          6
Directed Graph

• Multiple edges:
    a graph may have two or more edges
    connecting the same two vertices in the same
    direction
                                       Directed
           Undirected
                                       V0
     V0
                                              V2
                 V2         V1
V1
                                             V4
                                  V3
      V3        V4                                 13




 Directed Graph
• Simple graph:

  • No loops
  • No multiple edges
  • Directed
  • Undirected
• Directed graph representation:

     • Using a 2-Dim array
     • Using a Linked List for each vertex
     • Using the set class from the C++
       Standard Library ( edge sets )
                                                   14




                                                        7
Graph Relationship

 Adjacent vertices: Two vertices in a
 graph that are connected by an edge
 Path: A sequence of vertices that
 connects two nodes in a graph
 Complete graph: A graph in which every
 vertex is directly connected to every other
 vertex
 Weighted graph: A graph in which each
 edge carries a value
                                                 15




Graph Relationship (cont…)

 In a complete graph, every vertex is
 adjacent to every other vertex.
 If there are N vertices, there will be N * (N
 - 1) edges in a complete directed graph
 and N * (N - 1) / 2 edges in a complete
 undirected graph.




                                                 16




                                                      8
Weighted graphs can be used to represent
Weighted graph   applications in which the value of the
                 connection between the vertices is important,
                 not just the existence of a connection.




                                                                 17




Complete graph




                                                                 18




                                                                      9
Degree
 In an undirected graph, the degree of a
 vertex u is the number of edges connected
 to u.
 In a directed graph, the out-degree of a
 vertex u is the number edges leaving u,
 and its in-degree is the number of edges
 ending at u
 Each vertex is associated with a linked list
 that enumerates all the vertices that are
 connected to u
                                            19




Graph Traversals (cont…)


In general:
•Both traversal algorithms
     1. Start at one vertex of a graph
     2. Process the information contained
         at that vertex
     3. Move along an edge to process a
         neighbor


                                            20




                                                 10
Graph Traversals (cont…)

• The traversal algorithm should be
   careful that it doesn’t enter a “Repetitive
   Cycle”. Therefore we will mark each vertex as
   it is processed..
• When the traversal finishes, all of the vertices
  that can be reached from the start vertex have
  been processed.
• Some of the vertices may not be processed
  because there is NO PATH from the START
  VERTEX                                             21




 Solving a simple problem using a graph


A network of computers can be represented
By a graph, with
• each vertex representing One of the
      machines in the network, and
• an Edge representing a communication wire
      Between the two machines.
The question of whether one machine can send
a message to another machine boils down to
whether the corresponding vertices are
Connected by a path
                                                     22




                                                          11
Solving a simple problem using a graph

                  V0      6
             1                     V0 to V3 = 1
                      3       V1
    V3
                                   V3 to V1 = 3

                          2        V1 to V2 = 2
         7
                 V2                     Total 6
                  6
• Each edge has a NON-Negative Integer value
attached to it called the weight or cost of the edge
The path with the lowest cost is called the
Shortest path
                                                       23




 Node ADT

   Essential Operations
      create: Element → Node
      changeElement: Node´Element → Node
      getElement: Node → Element




                                                       24




                                                            12
Edge ADT

 Essential Operations
  •   create: Node´Node´Attribute → Edge
  •   changeAttribute: Edge´Attribute → Edge
  •   getAttribute: Edge → Attribute
  •   getNodes: Edge → Node´Node
  •   getEdge: Node´Node → Edge




                                               25




Digraph ADT

create: → Graph
addNode: Node´Graph → Graph
addEdge: Edge´Graph → Graph
containsNode: Node´Graph → Boolean
containsEdge: Node´Node´Graph → Boolean
removeNode: Node´Graph → Graph
removeEdge: Node´Node´Graph → Graph
numNodes: Graph → Integer
numEdges: Graph → Integer


                                               26




                                                    13
Digraph ADT

 Other helpful operations
   an iterator over all nodes in the graph;
   an iterator over all edges in the graph;
   for each node, an iterator over all nodes to
   which it has an edge.




                                              27




Digraph Implementations

 Edge Set implementation
   Set of Nodes
   Set of Edges - (node, node, attribute)
 Standard method of representing sets
   e.g. hash table, BSTree




                                              28




                                                   14
Digraph Implementations (cont…)

 Adjacency Set (or Adjacency List)
 implementation
   Set of Nodes
   Data at each node includes list of adjacent
   nodes and edge attributes
 Standard method of representing sets
   e.g. hash table, BSTree



                                                 29




                                                      15

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Stack project
Stack projectStack project
Stack project
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Unit I-Data structures stack & Queue
Unit I-Data structures stack & QueueUnit I-Data structures stack & Queue
Unit I-Data structures stack & Queue
 
stack & queue
stack & queuestack & queue
stack & queue
 
Red black tree
Red black treeRed black tree
Red black tree
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Linked List
Linked ListLinked List
Linked List
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005Skip list vinay khimsuriya_200430723005
Skip list vinay khimsuriya_200430723005
 
deque and it applications
deque and it applicationsdeque and it applications
deque and it applications
 
Hash table
Hash tableHash table
Hash table
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Linked list
Linked listLinked list
Linked list
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
Prim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
 
Linked list
Linked listLinked list
Linked list
 
Asymptotic Notation
Asymptotic NotationAsymptotic Notation
Asymptotic Notation
 

Destacado

Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Graph data structure
Graph data structureGraph data structure
Graph data structureTech_MX
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and GraphsIntro C# Book
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of GraphAbhishek Pachisia
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
Trees data structure
Trees data structureTrees data structure
Trees data structureSumit Gupta
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theoryChuckie Balbuena
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of treeSiddhi Viradiya
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data StructuresAdarsh Patel
 
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 ColouringSaurabh Kaushik
 

Destacado (20)

Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
17. Trees and Graphs
17. Trees and Graphs17. Trees and Graphs
17. Trees and Graphs
 
Graph representation
Graph representationGraph representation
Graph representation
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
introduction to graph theory
introduction to graph theoryintroduction to graph theory
introduction to graph theory
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
 
Minimum spanning Tree
Minimum spanning TreeMinimum spanning Tree
Minimum spanning Tree
 
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
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
 
Recursion
RecursionRecursion
Recursion
 

Similar a Lecture8 data structure(graph)

Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfChristianKapsales1
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structurehamza javed
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structuresSavit Chandra
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1David Wood
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructuresLikhithaGunturi
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashingVictor Palmar
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structurePooja Bhojwani
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c languageSARITHA REDDY
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structureMahmoud Alfarra
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsAakash deep Singhal
 
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
 

Similar a Lecture8 data structure(graph) (20)

Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdfClass01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
Class01_Computer_Contest_Level_3_Notes_Sep_07 - Copy.pdf
 
Unit 2: All
Unit 2: AllUnit 2: All
Unit 2: All
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
Graphs in data structures
Graphs in data structuresGraphs in data structures
Graphs in data structures
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1
 
Graphs
GraphsGraphs
Graphs
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graph
GraphGraph
Graph
 
Graph
GraphGraph
Graph
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
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
 

Más de Taibah University, College of Computer Science & Engineering

Más de Taibah University, College of Computer Science & Engineering (20)

Lecture 1- Computer Organization and Architecture.pdf
Lecture 1- Computer Organization and Architecture.pdfLecture 1- Computer Organization and Architecture.pdf
Lecture 1- Computer Organization and Architecture.pdf
 
The paper the welfare state of the somali nation - a possible solution to t...
The paper   the welfare state of the somali nation - a possible solution to t...The paper   the welfare state of the somali nation - a possible solution to t...
The paper the welfare state of the somali nation - a possible solution to t...
 
Colonial intrusion and_the_somali_resistance
Colonial intrusion and_the_somali_resistanceColonial intrusion and_the_somali_resistance
Colonial intrusion and_the_somali_resistance
 
Lecture 3 (Contemporary approaches to Information Systems)
Lecture 3 (Contemporary approaches to Information Systems)Lecture 3 (Contemporary approaches to Information Systems)
Lecture 3 (Contemporary approaches to Information Systems)
 
Lecture 7 (business-level strategy and the value chain model)
Lecture 7  (business-level strategy and the value chain model)Lecture 7  (business-level strategy and the value chain model)
Lecture 7 (business-level strategy and the value chain model)
 
Lecture 4 (using information technology for competitive advantage)
Lecture 4 (using information technology for competitive advantage)Lecture 4 (using information technology for competitive advantage)
Lecture 4 (using information technology for competitive advantage)
 
Lecture 2 (major types of information systems in organizations)
Lecture 2 (major types of information systems in organizations)Lecture 2 (major types of information systems in organizations)
Lecture 2 (major types of information systems in organizations)
 
Practical session 1 (critical path analaysis)
Practical session 1 (critical path analaysis)Practical session 1 (critical path analaysis)
Practical session 1 (critical path analaysis)
 
Chapter 2 modeling the process and life-cycle
Chapter 2  modeling the process and life-cycleChapter 2  modeling the process and life-cycle
Chapter 2 modeling the process and life-cycle
 
Historical Perspective on the Challenge Facing the Somali Sacral Unity
Historical Perspective on the Challenge Facing the Somali Sacral UnityHistorical Perspective on the Challenge Facing the Somali Sacral Unity
Historical Perspective on the Challenge Facing the Somali Sacral Unity
 
Colonial intrusion and the Somali Resistance
Colonial intrusion and the Somali ResistanceColonial intrusion and the Somali Resistance
Colonial intrusion and the Somali Resistance
 
Lecture 8 (information systems and strategy planning)
Lecture 8  (information systems and strategy planning)Lecture 8  (information systems and strategy planning)
Lecture 8 (information systems and strategy planning)
 
Lecture 4 (using information technology for competitive advantage)
Lecture 4 (using information technology for competitive advantage)Lecture 4 (using information technology for competitive advantage)
Lecture 4 (using information technology for competitive advantage)
 
Lecture1 data structure(introduction)
Lecture1 data structure(introduction)Lecture1 data structure(introduction)
Lecture1 data structure(introduction)
 
Lecture2 is331 data&infomanag(databaseenv)
Lecture2 is331 data&infomanag(databaseenv)Lecture2 is331 data&infomanag(databaseenv)
Lecture2 is331 data&infomanag(databaseenv)
 
Lecture1 is322 data&infomanag(introduction)(old curr)
Lecture1 is322 data&infomanag(introduction)(old curr)Lecture1 is322 data&infomanag(introduction)(old curr)
Lecture1 is322 data&infomanag(introduction)(old curr)
 
Lecture6 is353(ea&data viewpoint )
Lecture6 is353(ea&data viewpoint )Lecture6 is353(ea&data viewpoint )
Lecture6 is353(ea&data viewpoint )
 
Lecture4 is353-ea(fea)
Lecture4 is353-ea(fea)Lecture4 is353-ea(fea)
Lecture4 is353-ea(fea)
 
Lecture3 is353-ea(togaf)
Lecture3 is353-ea(togaf)Lecture3 is353-ea(togaf)
Lecture3 is353-ea(togaf)
 
Lecture2 is353-ea(the zachma framework)
Lecture2 is353-ea(the zachma framework)Lecture2 is353-ea(the zachma framework)
Lecture2 is353-ea(the zachma framework)
 

Último

PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationAnamaria Contreras
 
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxGo for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxRakhi Bazaar
 
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...SOFTTECHHUB
 
digital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingdigital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingrajputmeenakshi733
 
Excvation Safety for safety officers reference
Excvation Safety for safety officers referenceExcvation Safety for safety officers reference
Excvation Safety for safety officers referencessuser2c065e
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMVoces Mineras
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environmentelijahj01012
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFChandresh Chudasama
 
Technical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamTechnical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamArik Fletcher
 
NAB Show Exhibitor List 2024 - Exhibitors Data
NAB Show Exhibitor List 2024 - Exhibitors DataNAB Show Exhibitor List 2024 - Exhibitors Data
NAB Show Exhibitor List 2024 - Exhibitors DataExhibitors Data
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfRbc Rbcua
 
Driving Business Impact for PMs with Jon Harmer
Driving Business Impact for PMs with Jon HarmerDriving Business Impact for PMs with Jon Harmer
Driving Business Impact for PMs with Jon HarmerAggregage
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfDanny Diep To
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsIndiaMART InterMESH Limited
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxmbikashkanyari
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Anamaria Contreras
 
BAILMENT & PLEDGE business law notes.pptx
BAILMENT & PLEDGE business law notes.pptxBAILMENT & PLEDGE business law notes.pptx
BAILMENT & PLEDGE business law notes.pptxran17april2001
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckHajeJanKamps
 

Último (20)

PSCC - Capability Statement Presentation
PSCC - Capability Statement PresentationPSCC - Capability Statement Presentation
PSCC - Capability Statement Presentation
 
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptxGo for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
Go for Rakhi Bazaar and Pick the Latest Bhaiya Bhabhi Rakhi.pptx
 
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
How To Simplify Your Scheduling with AI Calendarfly The Hassle-Free Online Bo...
 
digital marketing , introduction of digital marketing
digital marketing , introduction of digital marketingdigital marketing , introduction of digital marketing
digital marketing , introduction of digital marketing
 
Excvation Safety for safety officers reference
Excvation Safety for safety officers referenceExcvation Safety for safety officers reference
Excvation Safety for safety officers reference
 
Memorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQMMemorándum de Entendimiento (MoU) entre Codelco y SQM
Memorándum de Entendimiento (MoU) entre Codelco y SQM
 
Cyber Security Training in Office Environment
Cyber Security Training in Office EnvironmentCyber Security Training in Office Environment
Cyber Security Training in Office Environment
 
Guide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDFGuide Complete Set of Residential Architectural Drawings PDF
Guide Complete Set of Residential Architectural Drawings PDF
 
Technical Leaders - Working with the Management Team
Technical Leaders - Working with the Management TeamTechnical Leaders - Working with the Management Team
Technical Leaders - Working with the Management Team
 
WAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdfWAM Corporate Presentation April 12 2024.pdf
WAM Corporate Presentation April 12 2024.pdf
 
NAB Show Exhibitor List 2024 - Exhibitors Data
NAB Show Exhibitor List 2024 - Exhibitors DataNAB Show Exhibitor List 2024 - Exhibitors Data
NAB Show Exhibitor List 2024 - Exhibitors Data
 
APRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdfAPRIL2024_UKRAINE_xml_0000000000000 .pdf
APRIL2024_UKRAINE_xml_0000000000000 .pdf
 
Driving Business Impact for PMs with Jon Harmer
Driving Business Impact for PMs with Jon HarmerDriving Business Impact for PMs with Jon Harmer
Driving Business Impact for PMs with Jon Harmer
 
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdfGUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
GUIDELINES ON USEFUL FORMS IN FREIGHT FORWARDING (F) Danny Diep Toh MBA.pdf
 
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptxThe Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
The Bizz Quiz-E-Summit-E-Cell-IITPatna.pptx
 
Welding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan DynamicsWelding Electrode Making Machine By Deccan Dynamics
Welding Electrode Making Machine By Deccan Dynamics
 
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptxThe-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
The-Ethical-issues-ghhhhhhhhjof-Byjus.pptx
 
Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.Traction part 2 - EOS Model JAX Bridges.
Traction part 2 - EOS Model JAX Bridges.
 
BAILMENT & PLEDGE business law notes.pptx
BAILMENT & PLEDGE business law notes.pptxBAILMENT & PLEDGE business law notes.pptx
BAILMENT & PLEDGE business law notes.pptx
 
Pitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deckPitch Deck Teardown: Xpanceo's $40M Seed deck
Pitch Deck Teardown: Xpanceo's $40M Seed deck
 

Lecture8 data structure(graph)

  • 1. Lecture 8 Graph Data Structure (CS221) Abdisalam Issa-Salwe Taibah University College of Computer Science & Engineering Computer Science Department Outline Graph Data Type Graph Concepts Graph Data Structure Directed/undirected Graph Graph Relationship Graph implementation 2 1
  • 2. Learning Outcomes Describe a Graph ADT Understand how to implement a Graph ADT Describe algorithms to traverse a graph 3 The Graph ADT A graph is a collection of nodes connected by edges If an edge e connects vertex u and v, we denote it as (u; v).if u = v, e is called a loop 4 2
  • 3. Graph Concepts A tree is an example of a graph In a graph a node may be it’s own ancestor In general a graph has no root node Formally, a graph is an ordered pair of sets (N,E) Both nodes and edges may have data values associated 5 Graph Data Structure (cont…) Graph is a data structure that consists of a set of nodes and a set of edges that relate the nodes to one another It is made up of a set of nodes called vertices and a set of lines called edges (or arcs) that connect the nodes. If the edges in the graph have no direction it is called an undirected graph. A graph whose edges are directed from one vertex to another is called a directed graph, or digraph 6 3
  • 4. Graphs Data Structure (cont…) More definition: • Like a tree, is a NON-Linear structure consisting of nodes and links between the nodes Types: Undirected graph Directed graph Graphs are often used to solve problems 7 Undirected Graph • An undirected graph is a set of nodes and a set of links between the nodes. • Each NODE is called a VERTEX V0 V1 • Each LINK is called an EDGE E0 • The order of the two connected vertices is unimportant ex: whether “V0 connects V1” or “V1 connects V0” means the same thing 8 4
  • 5. Undirected Graph examples 5 vertices 6 edges V0 E0 E1 V2 E5 V1 E4 E2 V4 V3 E3 9 Undirected Graph examples 5 vertices 6 edges V3 E4 V2 E2 E1 E0 V0 V1 E3 V4 E5 In drawing, the placement of the vertices is UNIMPORTANT same as previous graph 10 5
  • 6. Directed Graph A directed graph is a finite set of vertices together with a finite set of edges. If both are empty then we have an empty graph V1 SOURCE V0 V2 V1 V4 V3 TARGET V3 11 Directed Graph • Loops: a loop connects a vertex to itself LOOP Vertex • Path: is a sequence of vertices P0, P1, P2,… Pn , each adjacent pairs of vertices Pi and Pi+1 are connected by an edge path V1 V3 SOURCE TARGET 12 6
  • 7. Directed Graph • Multiple edges: a graph may have two or more edges connecting the same two vertices in the same direction Directed Undirected V0 V0 V2 V2 V1 V1 V4 V3 V3 V4 13 Directed Graph • Simple graph: • No loops • No multiple edges • Directed • Undirected • Directed graph representation: • Using a 2-Dim array • Using a Linked List for each vertex • Using the set class from the C++ Standard Library ( edge sets ) 14 7
  • 8. Graph Relationship Adjacent vertices: Two vertices in a graph that are connected by an edge Path: A sequence of vertices that connects two nodes in a graph Complete graph: A graph in which every vertex is directly connected to every other vertex Weighted graph: A graph in which each edge carries a value 15 Graph Relationship (cont…) In a complete graph, every vertex is adjacent to every other vertex. If there are N vertices, there will be N * (N - 1) edges in a complete directed graph and N * (N - 1) / 2 edges in a complete undirected graph. 16 8
  • 9. Weighted graphs can be used to represent Weighted graph applications in which the value of the connection between the vertices is important, not just the existence of a connection. 17 Complete graph 18 9
  • 10. Degree In an undirected graph, the degree of a vertex u is the number of edges connected to u. In a directed graph, the out-degree of a vertex u is the number edges leaving u, and its in-degree is the number of edges ending at u Each vertex is associated with a linked list that enumerates all the vertices that are connected to u 19 Graph Traversals (cont…) In general: •Both traversal algorithms 1. Start at one vertex of a graph 2. Process the information contained at that vertex 3. Move along an edge to process a neighbor 20 10
  • 11. Graph Traversals (cont…) • The traversal algorithm should be careful that it doesn’t enter a “Repetitive Cycle”. Therefore we will mark each vertex as it is processed.. • When the traversal finishes, all of the vertices that can be reached from the start vertex have been processed. • Some of the vertices may not be processed because there is NO PATH from the START VERTEX 21 Solving a simple problem using a graph A network of computers can be represented By a graph, with • each vertex representing One of the machines in the network, and • an Edge representing a communication wire Between the two machines. The question of whether one machine can send a message to another machine boils down to whether the corresponding vertices are Connected by a path 22 11
  • 12. Solving a simple problem using a graph V0 6 1 V0 to V3 = 1 3 V1 V3 V3 to V1 = 3 2 V1 to V2 = 2 7 V2 Total 6 6 • Each edge has a NON-Negative Integer value attached to it called the weight or cost of the edge The path with the lowest cost is called the Shortest path 23 Node ADT Essential Operations create: Element → Node changeElement: Node´Element → Node getElement: Node → Element 24 12
  • 13. Edge ADT Essential Operations • create: Node´Node´Attribute → Edge • changeAttribute: Edge´Attribute → Edge • getAttribute: Edge → Attribute • getNodes: Edge → Node´Node • getEdge: Node´Node → Edge 25 Digraph ADT create: → Graph addNode: Node´Graph → Graph addEdge: Edge´Graph → Graph containsNode: Node´Graph → Boolean containsEdge: Node´Node´Graph → Boolean removeNode: Node´Graph → Graph removeEdge: Node´Node´Graph → Graph numNodes: Graph → Integer numEdges: Graph → Integer 26 13
  • 14. Digraph ADT Other helpful operations an iterator over all nodes in the graph; an iterator over all edges in the graph; for each node, an iterator over all nodes to which it has an edge. 27 Digraph Implementations Edge Set implementation Set of Nodes Set of Edges - (node, node, attribute) Standard method of representing sets e.g. hash table, BSTree 28 14
  • 15. Digraph Implementations (cont…) Adjacency Set (or Adjacency List) implementation Set of Nodes Data at each node includes list of adjacent nodes and edge attributes Standard method of representing sets e.g. hash table, BSTree 29 15