SlideShare ist ein Scribd-Unternehmen logo
1 von 18
using Java
2015
Data Structure
Prepared by: Mahmoud Rafeek Al-farra
in Java
10. Graphs
mfarra.cst.ps www.fb.com/MahmoudRFarra
Contents
Representing Graphs
Basic Graph Terminologies
Introduction
Modeling Graphs (Implementation)
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A graph is a nonlinear data structure with many
important applications.
 Many real-world problems can be solved using graph
algorithms.
 For example:
 The problem to find the least number of flights
between two cities can be modeled using a graph,
where the vertices represent cities and the edges
represent the flights between two adjacent
cities.
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The study of graph problems is known as graph
theory.
 There were two islands on the river. The city and
islands were connected by seven bridges.
 The question is, can one take a walk, cross each
bridge exactly once, and return to the starting
point?
 Euler proved that it is not possible.
Introduction
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Euler proved that it is not possible.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A graph is a mathematical structure that represents
relationships among entities in the real world.
 A graph consists of a nonempty set of vertices (also
known as nodes or points), and a set of edges that
connect the vertices.
 For convenience:
 We define a graph as G = (V, E). Where
 V represents a set of vertices
 E represents a set of edges.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 For example, V and E for the graph in first figure
are as follows:
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A graph may be directed or undirected.
 In a directed graph, each edge has a direction, which
indicates that you can move from one vertex to the
other through the edge.
 You can model parent/child relationships using a
directed graph, where an edge from vertex A to B
indicates that A is a parent of B.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A graph may has many forms.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
Before we introduce graph algorithms and applications, it is helpful to
get acquainted with graphs using the interactive tool at
www.cs.armstrong.edu/liang/animation/GraphLearningTool.html
 In an undirected graph, you can move in both
directions between vertices.
 Edges may be weighted or unweighted.
 For example, you can assign a weight for each edge in
the graph. (e.x.: To indicate the flight time between
the two cities.)
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Two vertices in a graph are said to be adjacent:
 if they are connected by the same edge.
 (Edges) if they are connected to the same vertex.
 An edge in a graph that joins two vertices is said to
be incident to both vertices.
 The degree of a vertex is the number of edges
incident to it.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Two vertices are called neighbors if they are
adjacent. Similarly, two edges are called neighbors if
they are adjacent.
 A loop is an edge that links a vertex to itself.
 If two vertices are connected by two or more edges,
these edges are called parallel edges.
 A simple graph is one that has
doesn’t have any loops or parallel
edges.
 In a complete graph, every two
pairs of vertices are connected, as
shown.
Basic Graph Terminologies
mfarra.cst.ps www.fb.com/MahmoudRFarra
 A graph is connected if there exists a path between
any two vertices in the graph.
 A subgraph of a graph G is a graph whose vertex set
is a subset of that of G and whose edge set is a
subset of that of G.
Representing Graphs
mfarra.cst.ps www.fb.com/MahmoudRFarra
 Representing a graph is to store its vertices and
edges in a program.
 The data structure for storing a graph is arrays or
lists.
Representing Graphs
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The edges can be represented using a two-
dimensional array.
 The vertices and edges in the following figure can be
represented as follows:
Modeling Graphs (Implementation)
mfarra.cst.ps www.fb.com/MahmoudRFarra
 The Graph interface defines the common operations
for a graph.
using Java
2015
FB: M a h m o u d R F a r r a
YouTube: M a h m o u d R F a r
SlidesShare: mralfarra
Thank you

Weitere ähnliche Inhalte

Was ist angesagt?

Graph representation
Graph representationGraph representation
Graph representation
Tech_MX
 
CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1CPSC 125 Ch 5 Sec 1
CPSC 125 Ch 5 Sec 1
David Wood
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar
 
Applications of graphs
Applications of graphsApplications of graphs
Applications of graphs
Tech_MX
 

Was ist angesagt? (20)

Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graph representation
Graph representationGraph representation
Graph representation
 
Graph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphsGraph Theory: Matrix representation of graphs
Graph Theory: Matrix representation of graphs
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs 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
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graphs
GraphsGraphs
Graphs
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graphs
GraphsGraphs
Graphs
 
Applications of graphs
Applications of graphsApplications of graphs
Applications of graphs
 
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
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
Graphs
GraphsGraphs
Graphs
 
Graph applications chapter
Graph applications chapterGraph applications chapter
Graph applications chapter
 
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
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Graphs Algorithms
Graphs AlgorithmsGraphs Algorithms
Graphs Algorithms
 

Andere mochten auch

Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
Anuj Modi
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
Arvind Devaraj
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
Kumar
 

Andere mochten auch (20)

Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Graphs In Data Structure
Graphs In Data StructureGraphs In Data Structure
Graphs In Data Structure
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية البرمجة الهدفية بلغة جافا - مفاهيم أساسية
البرمجة الهدفية بلغة جافا - مفاهيم أساسية
 
Chapter2 array of objects
Chapter2 array of objectsChapter2 array of objects
Chapter2 array of objects
 
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية  بلغة جافا - مصفوفة الكائناتالبرمجة الهدفية  بلغة جافا - مصفوفة الكائنات
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
 
البرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكالالبرمجة الهدفية بلغة جافا - تعدد الأشكال
البرمجة الهدفية بلغة جافا - تعدد الأشكال
 
L6 structure
L6 structureL6 structure
L6 structure
 
linked list
linked listlinked list
linked list
 
01 05 - introduction xml
01  05 - introduction xml01  05 - introduction xml
01 05 - introduction xml
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
5 Array List, data structure course
5 Array List, data structure course5 Array List, data structure course
5 Array List, data structure course
 
3 Array operations
3   Array operations3   Array operations
3 Array operations
 
Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)
 

Ähnlich wie Graphs data Structure

Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
showslidedump
 

Ähnlich wie Graphs data Structure (20)

Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Slides Chapter10.1 10.2
Slides Chapter10.1 10.2Slides Chapter10.1 10.2
Slides Chapter10.1 10.2
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
Research
ResearchResearch
Research
 
Discrete2
Discrete2Discrete2
Discrete2
 
Discrete ad
Discrete adDiscrete ad
Discrete ad
 
Lecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptxLecture 2.3.1 Graph.pptx
Lecture 2.3.1 Graph.pptx
 
VANU no sql ppt.pptx
VANU no sql ppt.pptxVANU no sql ppt.pptx
VANU no sql ppt.pptx
 
Vanmathy no sql
Vanmathy no sql Vanmathy no sql
Vanmathy no sql
 
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATIONFREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
 
Graph Application in Traffic Control
Graph Application in Traffic ControlGraph Application in Traffic Control
Graph Application in Traffic Control
 
105575916 maths-edit-new
105575916 maths-edit-new105575916 maths-edit-new
105575916 maths-edit-new
 
Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications
 
NON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptxNON-LINEAR DATA STRUCTURE-Graphs.pptx
NON-LINEAR DATA STRUCTURE-Graphs.pptx
 
3D Graph Drawings: Good Viewing for Occluded Vertices
3D Graph Drawings: Good Viewing for Occluded Vertices3D Graph Drawings: Good Viewing for Occluded Vertices
3D Graph Drawings: Good Viewing for Occluded Vertices
 
Data structure
Data structureData structure
Data structure
 
graph representation.pdf
graph representation.pdfgraph representation.pdf
graph representation.pdf
 
nosql.pptx
nosql.pptxnosql.pptx
nosql.pptx
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Application of Graph Theory in Computer science using Data Structure.pdf
Application of Graph Theory in Computer science using Data Structure.pdfApplication of Graph Theory in Computer science using Data Structure.pdf
Application of Graph Theory in Computer science using Data Structure.pdf
 

Mehr von Mahmoud Alfarra

8 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 201020118 programming-using-java decision-making practices 20102011
8 programming-using-java decision-making practices 20102011
Mahmoud Alfarra
 

Mehr von Mahmoud Alfarra (20)

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

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 

Graphs data Structure

  • 1. using Java 2015 Data Structure Prepared by: Mahmoud Rafeek Al-farra in Java 10. Graphs
  • 2. mfarra.cst.ps www.fb.com/MahmoudRFarra Contents Representing Graphs Basic Graph Terminologies Introduction Modeling Graphs (Implementation)
  • 3. Introduction mfarra.cst.ps www.fb.com/MahmoudRFarra  A graph is a nonlinear data structure with many important applications.  Many real-world problems can be solved using graph algorithms.  For example:  The problem to find the least number of flights between two cities can be modeled using a graph, where the vertices represent cities and the edges represent the flights between two adjacent cities.
  • 5. Introduction mfarra.cst.ps www.fb.com/MahmoudRFarra  The study of graph problems is known as graph theory.  There were two islands on the river. The city and islands were connected by seven bridges.  The question is, can one take a walk, cross each bridge exactly once, and return to the starting point?  Euler proved that it is not possible.
  • 7. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  A graph is a mathematical structure that represents relationships among entities in the real world.  A graph consists of a nonempty set of vertices (also known as nodes or points), and a set of edges that connect the vertices.  For convenience:  We define a graph as G = (V, E). Where  V represents a set of vertices  E represents a set of edges.
  • 8. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  For example, V and E for the graph in first figure are as follows:
  • 9. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  A graph may be directed or undirected.  In a directed graph, each edge has a direction, which indicates that you can move from one vertex to the other through the edge.  You can model parent/child relationships using a directed graph, where an edge from vertex A to B indicates that A is a parent of B.
  • 10. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  A graph may has many forms.
  • 11. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra Before we introduce graph algorithms and applications, it is helpful to get acquainted with graphs using the interactive tool at www.cs.armstrong.edu/liang/animation/GraphLearningTool.html  In an undirected graph, you can move in both directions between vertices.  Edges may be weighted or unweighted.  For example, you can assign a weight for each edge in the graph. (e.x.: To indicate the flight time between the two cities.)
  • 12. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  Two vertices in a graph are said to be adjacent:  if they are connected by the same edge.  (Edges) if they are connected to the same vertex.  An edge in a graph that joins two vertices is said to be incident to both vertices.  The degree of a vertex is the number of edges incident to it.
  • 13. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  Two vertices are called neighbors if they are adjacent. Similarly, two edges are called neighbors if they are adjacent.  A loop is an edge that links a vertex to itself.  If two vertices are connected by two or more edges, these edges are called parallel edges.  A simple graph is one that has doesn’t have any loops or parallel edges.  In a complete graph, every two pairs of vertices are connected, as shown.
  • 14. Basic Graph Terminologies mfarra.cst.ps www.fb.com/MahmoudRFarra  A graph is connected if there exists a path between any two vertices in the graph.  A subgraph of a graph G is a graph whose vertex set is a subset of that of G and whose edge set is a subset of that of G.
  • 15. Representing Graphs mfarra.cst.ps www.fb.com/MahmoudRFarra  Representing a graph is to store its vertices and edges in a program.  The data structure for storing a graph is arrays or lists.
  • 16. Representing Graphs mfarra.cst.ps www.fb.com/MahmoudRFarra  The edges can be represented using a two- dimensional array.  The vertices and edges in the following figure can be represented as follows:
  • 17. Modeling Graphs (Implementation) mfarra.cst.ps www.fb.com/MahmoudRFarra  The Graph interface defines the common operations for a graph.
  • 18. using Java 2015 FB: M a h m o u d R F a r r a YouTube: M a h m o u d R F a r SlidesShare: mralfarra Thank you