SlideShare a Scribd company logo
DATA STRUCTURE
Chapter 9: Graph
Prepared & Presented by
Mr. Mahmoud R. Alfarra
2011-2012
College of Science & Technology
Dep. Of Computer Science & IT
BCs of Information Technology
http://mfarra.cst.ps
Out Line
 What is a graph ?
 What is a directed graph?
 What is an Unordered graph?
 Graph’s terms
 Real world systems modeled by graphs
 The Graph class
 Representing Vertices
 Representing Edges
 Adjacency matrix
2
What is a graph ?
 A graph consists of a set of vertices and a set
of edges.
 Think of a map of your state.
 A map is a type of graph. Each town is a
vertex and a road that connects two towns is
an edge.
 Edges are specified as a pair, (v1, v2), where
v1 and v2 are two vertices in the graph.
 A vertex can also have a weight, sometimes
also called a cost.
3
What is a directed graph?
4
 A graph whose pairs are ordered is called a
directed graph, or just a digraph.
What is an Unordered graph?
5
 If a graph is not ordered, it is called an
unordered graph, or just a graph.
Graph’s terms
6
 A path is a sequence of vertices in a graph such
that all vertices are connected by edges.
 The length of a path is the number of edges from
the first vertex in the path to the last vertex.
 A path can also consist of a vertex to itself, which is
called a loop. Loops have a length of 0.
 A cycle is a path of at least 1 in a directed graph so
that the beginning vertex is also the ending vertex.
In a directed graph, the edges can be the same
edge, but in an undirected graph, the edges must
be distinct.
Connected Graph
7
‫البيانات‬ ‫تراكيب‬ ‫مساق‬
‫إعداد‬ ‫العلمية‬ ‫المادة‬
/
‫أ‬
.
‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬
 An undirected graph is considered connected
if there is a path from every vertex to every
other vertex.
Connected Graph
8
 In a directed graph, this condition is called
strongly connected.
 A directed graph that is not strongly
connected, but is considered connected, is
called weakly connected.
 If a graph has an edge between every set of
vertices, it is said to be a complete graph.
Real world systems modeled by
graphs
9
 Graphs are used to model many different
types of real world systems.
 One example is traffic flow.
 The vertices represent street intersections and
the edges represent the streets themselves.
 Weighted edges can be used to represent
speed limits or the number of lanes.
The Graph class
10
 At first glance, a graph looks much like a tree and
you might be tempted to try to build a graph class
like a tree.
 There are problems with using a reference based
implementation, however, so we will look at a
different scheme for representing both vertices and
edges. Vertices
Edges
Graph
Representing Vertices
11
 The first step we have to take to build a Graph
class is to build a Vertex class to store the
vertices of a graph.
 This class has the same duties the Node class
had in the LinkedList and BinarySearchTree
classes.
 The Vertex class needs two data members:
1. One for the data that identifies the vertex.
2. The other a Boolean member we use to keep
track of “visits” to the vertex.
Representing Edges
12
 We will store the list of vertices in an array and
will reference them in the Graph class by their
position in the array.
 The method we’ll choose for representing the
edges of a graph is called an adjacency
matrix.
 This is a two-dimensional array where the
elements indicate whether an edge exists
between two vertices.
Adjacency matrix
13
 The vertices are listed as the headings for the rows
and columns.
 If an edge exists between two vertices, a 1 is placed
in that position. If an edge doesn’t exist, a 0 is used.
Obviously, you can also use Boolean values here.
Thank You …
14
Remember that: question is the key of knowledge
Ahl Eljanna 

ْ‫ل‬‫ا‬ ‫ا‬
‫َل‬ِ‫إ‬ ‫ا‬
‫ت‬ْ
‫و‬‫ا‬
‫ْم‬‫ل‬‫ا‬ ‫ا‬‫ا‬
‫يه‬ِ‫ف‬ ‫ا‬
‫ن‬‫و‬ُ‫ق‬‫و‬ُ
‫ذ‬‫ا‬‫ي‬ ‫ا‬
‫َل‬
‫ا‬‫ق‬‫ا‬
‫و‬‫ا‬
‫و‬ ‫ا‬
‫وَل‬ُْ
‫اْل‬ ‫ا‬‫ة‬‫ا‬‫ت‬ْ
‫و‬‫ا‬
‫م‬
‫ا‬
‫اب‬‫ا‬
‫ذ‬‫ا‬
‫ع‬ ْ
‫م‬ُ
‫اه‬
ِ
‫يم‬ِ
‫ح‬‫ا‬ْ
‫ْل‬‫ا‬
15

More Related Content

PPTX
Graph Basic In Data structure
PDF
Graph Data Structure
PPTX
Graphs in data structure
PPT
2.1 graph basic
PPTX
Graph data structure and algorithms
PPTX
Graph in data structure
PPT
Graphs in c language
PPTX
Graph Data Structure
Graph Basic In Data structure
Graph Data Structure
Graphs in data structure
2.1 graph basic
Graph data structure and algorithms
Graph in data structure
Graphs in c language
Graph Data Structure

What's hot (20)

PPT
PPTX
Data structure - Graph
PPT
Data structure computer graphs
PPTX
Graphs in Data Structure
PPTX
Graph representation
PPT
Graphs in Data Structure
PPTX
Graph in data structure
PDF
Graph in Data Structure
PPTX
Adjacency list
PPTX
Data Structures - Lecture 10 [Graphs]
PPTX
Application Of Graph Data Structure
PPTX
Data Structure Graph DMZ #DMZone
PDF
Skiena algorithm 2007 lecture10 graph data strctures
PPT
Graphs in data structures
PPTX
Matrix representation of graph
PPT
Graph
PPTX
Graph (Data structure)
PPTX
Graphs data structures
Data structure - Graph
Data structure computer graphs
Graphs in Data Structure
Graph representation
Graphs in Data Structure
Graph in data structure
Graph in Data Structure
Adjacency list
Data Structures - Lecture 10 [Graphs]
Application Of Graph Data Structure
Data Structure Graph DMZ #DMZone
Skiena algorithm 2007 lecture10 graph data strctures
Graphs in data structures
Matrix representation of graph
Graph
Graph (Data structure)
Graphs data structures
Ad

Similar to Chapter9 graph data structure (20)

PPT
Lecture 5b graphs and hashing
PPT
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
PPTX
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
PPT
Graphs
PPTX
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
PPT
Graphs (1)
PPTX
graphssssssssssssssssssssssssssssss.pptx
PPTX
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
PDF
graphs in data structure for Btech students.pdf
PPTX
Data Structures and Agorithm: DS 21 Graph Theory.pptx
PPT
Graphs Presentation of University by Coordinator
PPTX
Data Structure of computer science and technology
PPTX
ppt 1.pptx
PPTX
Unit ix graph
PDF
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
PPTX
Unit 9 graph
PPTX
Data Structures - Introduction to Graph.pptx
PPT
lec 09-graphs-bfs-dfs.ppt
PPTX
Graph data structures for ppt for understanding.pptx
Lecture 5b graphs and hashing
Graphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.pptGraphs.ppt
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH.pptx
Graphs
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Graphs (1)
graphssssssssssssssssssssssssssssss.pptx
UNIT IV NON LINEAR DATA STRUCTURES - GRAPH
graphs in data structure for Btech students.pdf
Data Structures and Agorithm: DS 21 Graph Theory.pptx
Graphs Presentation of University by Coordinator
Data Structure of computer science and technology
ppt 1.pptx
Unit ix graph
Graphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.pdf
Unit 9 graph
Data Structures - Introduction to Graph.pptx
lec 09-graphs-bfs-dfs.ppt
Graph data structures for ppt for understanding.pptx
Ad

More from Mahmoud Alfarra (20)

PPT
Computer Programming, Loops using Java - part 2
PPT
Computer Programming, Loops using Java
PPT
Chapter 10: hashing data structure
PPT
Chapter 8: tree data structure
PPT
Chapter 7: Queue data structure
PPT
Chapter 6: stack data structure
PPT
Chapter 5: linked list data structure
PPT
Chapter 4: basic search algorithms data structure
PPT
Chapter 3: basic sorting algorithms data structure
PPT
Chapter 2: array and array list data structure
PPT
Chapter1 intro toprincipleofc#_datastructure_b_cs
PPT
Chapter 0: introduction to data structure
PPTX
3 classification
PPT
8 programming-using-java decision-making practices 20102011
PPT
7 programming-using-java decision-making220102011
PPT
6 programming-using-java decision-making20102011-
PPT
5 programming-using-java intro-tooop20102011
PPT
4 programming-using-java intro-tojava20102011
PPT
3 programming-using-java introduction-to computer
PPT
2 programming-using-java how to built application
Computer Programming, Loops using Java - part 2
Computer Programming, Loops using Java
Chapter 10: hashing data structure
Chapter 8: tree data structure
Chapter 7: Queue data structure
Chapter 6: stack data structure
Chapter 5: linked list data structure
Chapter 4: basic search algorithms data structure
Chapter 3: basic sorting algorithms data structure
Chapter 2: array and array list data structure
Chapter1 intro toprincipleofc#_datastructure_b_cs
Chapter 0: introduction to data structure
3 classification
8 programming-using-java decision-making practices 20102011
7 programming-using-java decision-making220102011
6 programming-using-java decision-making20102011-
5 programming-using-java intro-tooop20102011
4 programming-using-java intro-tojava20102011
3 programming-using-java introduction-to computer
2 programming-using-java how to built application

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
RMMM.pdf make it easy to upload and study
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Institutional Correction lecture only . . .
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
Basic Mud Logging Guide for educational purpose
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
master seminar digital applications in india
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
RMMM.pdf make it easy to upload and study
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
2.FourierTransform-ShortQuestionswithAnswers.pdf
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Institutional Correction lecture only . . .
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Pre independence Education in Inndia.pdf
Basic Mud Logging Guide for educational purpose
human mycosis Human fungal infections are called human mycosis..pptx
master seminar digital applications in india
Final Presentation General Medicine 03-08-2024.pptx
Renaissance Architecture: A Journey from Faith to Humanism
TR - Agricultural Crops Production NC III.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
O5-L3 Freight Transport Ops (International) V1.pdf

Chapter9 graph data structure

  • 1. DATA STRUCTURE Chapter 9: Graph Prepared & Presented by Mr. Mahmoud R. Alfarra 2011-2012 College of Science & Technology Dep. Of Computer Science & IT BCs of Information Technology http://mfarra.cst.ps
  • 2. Out Line  What is a graph ?  What is a directed graph?  What is an Unordered graph?  Graph’s terms  Real world systems modeled by graphs  The Graph class  Representing Vertices  Representing Edges  Adjacency matrix 2
  • 3. What is a graph ?  A graph consists of a set of vertices and a set of edges.  Think of a map of your state.  A map is a type of graph. Each town is a vertex and a road that connects two towns is an edge.  Edges are specified as a pair, (v1, v2), where v1 and v2 are two vertices in the graph.  A vertex can also have a weight, sometimes also called a cost. 3
  • 4. What is a directed graph? 4  A graph whose pairs are ordered is called a directed graph, or just a digraph.
  • 5. What is an Unordered graph? 5  If a graph is not ordered, it is called an unordered graph, or just a graph.
  • 6. Graph’s terms 6  A path is a sequence of vertices in a graph such that all vertices are connected by edges.  The length of a path is the number of edges from the first vertex in the path to the last vertex.  A path can also consist of a vertex to itself, which is called a loop. Loops have a length of 0.  A cycle is a path of at least 1 in a directed graph so that the beginning vertex is also the ending vertex. In a directed graph, the edges can be the same edge, but in an undirected graph, the edges must be distinct.
  • 7. Connected Graph 7 ‫البيانات‬ ‫تراكيب‬ ‫مساق‬ ‫إعداد‬ ‫العلمية‬ ‫المادة‬ / ‫أ‬ . ‫ا‬ َّ‫الفــر‬ ‫رفيق‬ ‫محمود‬  An undirected graph is considered connected if there is a path from every vertex to every other vertex.
  • 8. Connected Graph 8  In a directed graph, this condition is called strongly connected.  A directed graph that is not strongly connected, but is considered connected, is called weakly connected.  If a graph has an edge between every set of vertices, it is said to be a complete graph.
  • 9. Real world systems modeled by graphs 9  Graphs are used to model many different types of real world systems.  One example is traffic flow.  The vertices represent street intersections and the edges represent the streets themselves.  Weighted edges can be used to represent speed limits or the number of lanes.
  • 10. The Graph class 10  At first glance, a graph looks much like a tree and you might be tempted to try to build a graph class like a tree.  There are problems with using a reference based implementation, however, so we will look at a different scheme for representing both vertices and edges. Vertices Edges Graph
  • 11. Representing Vertices 11  The first step we have to take to build a Graph class is to build a Vertex class to store the vertices of a graph.  This class has the same duties the Node class had in the LinkedList and BinarySearchTree classes.  The Vertex class needs two data members: 1. One for the data that identifies the vertex. 2. The other a Boolean member we use to keep track of “visits” to the vertex.
  • 12. Representing Edges 12  We will store the list of vertices in an array and will reference them in the Graph class by their position in the array.  The method we’ll choose for representing the edges of a graph is called an adjacency matrix.  This is a two-dimensional array where the elements indicate whether an edge exists between two vertices.
  • 13. Adjacency matrix 13  The vertices are listed as the headings for the rows and columns.  If an edge exists between two vertices, a 1 is placed in that position. If an edge doesn’t exist, a 0 is used. Obviously, you can also use Boolean values here.
  • 14. Thank You … 14 Remember that: question is the key of knowledge
  • 15. Ahl Eljanna   ْ‫ل‬‫ا‬ ‫ا‬ ‫َل‬ِ‫إ‬ ‫ا‬ ‫ت‬ْ ‫و‬‫ا‬ ‫ْم‬‫ل‬‫ا‬ ‫ا‬‫ا‬ ‫يه‬ِ‫ف‬ ‫ا‬ ‫ن‬‫و‬ُ‫ق‬‫و‬ُ ‫ذ‬‫ا‬‫ي‬ ‫ا‬ ‫َل‬ ‫ا‬‫ق‬‫ا‬ ‫و‬‫ا‬ ‫و‬ ‫ا‬ ‫وَل‬ُْ ‫اْل‬ ‫ا‬‫ة‬‫ا‬‫ت‬ْ ‫و‬‫ا‬ ‫م‬ ‫ا‬ ‫اب‬‫ا‬ ‫ذ‬‫ا‬ ‫ع‬ ْ ‫م‬ُ ‫اه‬ ِ ‫يم‬ِ ‫ح‬‫ا‬ْ ‫ْل‬‫ا‬ 15