SlideShare a Scribd company logo
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

More Related Content

PPTX
Application Of Graph Data Structure
PPT
Graphs in Data Structure
PPTX
Data Structure Graph DMZ #DMZone
PDF
Graph in Data Structure
PPTX
Adjacency list
PPTX
Graph Basic In Data structure
PPTX
Graphs in Data Structure
PPTX
Matrix representation of graph
Application Of Graph Data Structure
Graphs in Data Structure
Data Structure Graph DMZ #DMZone
Graph in Data Structure
Adjacency list
Graph Basic In Data structure
Graphs in Data Structure
Matrix representation of graph

What's hot (20)

PDF
Graph Data Structure
PPTX
Graph representation
PDF
Graph Theory: Matrix representation of graphs
PPTX
Graphs data structures
KEY
CPSC 125 Ch 5 Sec 1
PPTX
Graph in data structure
PPTX
PPT
Data structure computer graphs
PPT
Applications of graphs
PPTX
Graph theory
PPTX
Graph data structure and algorithms
PPTX
Data Structures - Lecture 10 [Graphs]
PPTX
Graph Data Structure
PPT
PDF
Graph applications chapter
PPTX
Data structure - Graph
PPTX
Graphs in data structure
PPTX
Graph in data structure
PPTX
Graphs Algorithms
Graph Data Structure
Graph representation
Graph Theory: Matrix representation of graphs
Graphs data structures
CPSC 125 Ch 5 Sec 1
Graph in data structure
Data structure computer graphs
Applications of graphs
Graph theory
Graph data structure and algorithms
Data Structures - Lecture 10 [Graphs]
Graph Data Structure
Graph applications chapter
Data structure - Graph
Graphs in data structure
Graph in data structure
Graphs Algorithms
Ad

Viewers also liked (20)

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

Similar to Graphs data Structure (20)

PPTX
Chapter10.pptx jtuffuryrufhrhrurrufudurhrhr
PPT
Chapter9 graph data structure
PPTX
Slides Chapter10.1 10.2
PPTX
Spanningtreesppt
PDF
The Graph Abstract Data Type-DATA STRUCTURE.pdf
DOCX
Discrete2
DOCX
Discrete ad
DOCX
Research
PPTX
Lecture 2.3.1 Graph.pptx
PPTX
VANU no sql ppt.pptx
PPTX
Vanmathy no sql
PDF
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
PPTX
Graph Application in Traffic Control
DOCX
105575916 maths-edit-new
PDF
Map Coloring and Some of Its Applications
PPTX
NON-LINEAR DATA STRUCTURE-Graphs.pptx
PPTX
Graph Theory in Theoretical computer science
PDF
3D Graph Drawings: Good Viewing for Occluded Vertices
PPTX
Data structure
PDF
graph representation.pdf
Chapter10.pptx jtuffuryrufhrhrurrufudurhrhr
Chapter9 graph data structure
Slides Chapter10.1 10.2
Spanningtreesppt
The Graph Abstract Data Type-DATA STRUCTURE.pdf
Discrete2
Discrete ad
Research
Lecture 2.3.1 Graph.pptx
VANU no sql ppt.pptx
Vanmathy no sql
FREQUENT SUBGRAPH MINING ALGORITHMS - A SURVEY AND FRAMEWORK FOR CLASSIFICATION
Graph Application in Traffic Control
105575916 maths-edit-new
Map Coloring and Some of Its Applications
NON-LINEAR DATA STRUCTURE-Graphs.pptx
Graph Theory in Theoretical computer science
3D Graph Drawings: Good Viewing for Occluded Vertices
Data structure
graph representation.pdf

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)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Sports Quiz easy sports quiz sports quiz
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Pre independence Education in Inndia.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
01-Introduction-to-Information-Management.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Complications of Minimal Access Surgery at WLH
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPH.pptx obstetrics and gynecology in nursing
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Sports Quiz easy sports quiz sports quiz
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
Pre independence Education in Inndia.pdf
Anesthesia in Laparoscopic Surgery in India
01-Introduction-to-Information-Management.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
STATICS OF THE RIGID BODIES Hibbelers.pdf
RMMM.pdf make it easy to upload and study
VCE English Exam - Section C Student Revision Booklet
Microbial diseases, their pathogenesis and prophylaxis
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Basic Mud Logging Guide for educational purpose
Complications of Minimal Access Surgery at WLH
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism

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