SlideShare a Scribd company logo
1 of 34
Graph Representation
What is Graph ?

          A graph G consists of a finite set of
ordered pairs, called edges E, of certain
entities called vertices V.
   Edges are also called as arcs or links.
   Vertices are also called as nodes or points.
G=(V,E)

• A graph is a set of vertices and edges. A
  vertex may represent a state or a condition
  while the edge may represent a relation
  between two vertices.
Types of Representation
      Two ways are there for representing graph
  in the memory of a computer.
They are:-
  – Sequential Representation
  – Linked Representation
Sequential Representation
        Graphs can be represented through matrix
in system’s memory. This is sequential in nature.
This type of representation is called sequential
representation of graphs.
Types of Sequential Representation
•   Adjacency Matrix Representation
•   Incidence Matrix Representation
•   Circuit Matrix Representation
•   Cut Set Matrix Representation
•   Path Matrix Representation
Linked Representation
• Graphs can be represented through Linked List
  in system’s memory. This is Linked in nature.
  This type of representation is called Linked
  representation of graphs.
Types of Linked Representation
• Adjacency List Representation
Adjacency Matrix Representation

         The Adjacency matrix of a graph G
with n vertices is N x N. It is given by A=[aij].

   aij =1 if ith and jth vertices are adjacent.
       =0 if ith and jth vertices are not adjacent.
Examples
Incidence Matrix Representation
• The Incidence matrix of a graph G with N
  vertices and E edges is N x E.

     mij = 1 if ej is incident on vi
         = 0 otherwise
Examples



           e1 e2 e3 e4

       1
       2
       3
       4
Circuit Matrix Representation
• Circuit Matrix is represented by the number of
  different circuits T and the number of edges E
  is T x E in the graph. The Circuit Matrix C=Cij.

      Cij=1 if ith circuit includes jth edge.
         = 0 otherwise.
Examples
Cut Set Matrix Representation
• A Matrix S = Sij Rows correspond to cut sets
  and columns correspond to edges of the graph
  is defined to be a cut set matrix.

     Sij = 1 if the ith cut set contains the jth edge
         = 0 otherwise
Examples
Path Matrix Representation
• A path matrix is generally defined for a
  specific pair of vertices then the path matrix
  denoted as P(u,v) = Pij .

  Pij = 1 if the jth edge lies in the ith path
     = 0 otherwise
Examples
Adjacency List representation
• Adjacency List representation is one of the
  alternatives to adjacency matrix. It requires
  less amount of memory. For every vertex
  adjacency list stores a list of vertices, which
  are adjacent to current one.
Example
In Computer’s
• Even there are many mathematical
  representations…
           adjacency matrix
                 and
           adjacency lists
  are only used for representing graphs in
  computers.
Dense Graphs and Sparse Graphs

• Dense graph is a graph in which the number
  of edges is close to the maximal number of
  edges. The opposite, a graph with only a few
  edges, is a sparse graph.
Dense Graph
Sparse Graph
Advantages of adjacency matrix

Adjacency matrix is very convenient to work
with. Add (remove) an edge can be done in
O(1) time, the same time is required to check,
if there is an edge between two vertices.
Disadvantages of adjacency matrix
• Adjacency matrix consumes huge amount of
  memory for storing big graphs.
• Adjacency matrix requires huge efforts for
  adding/removing a vertex.
• In many algorithms you need to know the edges,
  adjacent to the current vertex. To draw out such
  an information from the adjacency matrix you
  have to scan over the corresponding row, which
  results in O(|V|) complexity.
Advantages of adjacency lists
• Adjacent list allows us to store graph in more
  compact form, than adjacency matrix.
• Adjacent list allows to get the list
  of adjacent vertices in O(1) time, which is a big
  advantage for some algorithms.
Disadvantages of adjacency lists
• Adding/removing an edge to/from adjacent list is
  not so easy as for adjacency matrix. It requires,
  on the average,O(|E| / |V|) time, which may
  result in cubical complexity for dense graphs to
  add all edges.
• If there is an edge between two vertices can be
  done in O(|E| / |V|) when list of adjacent
  vertices is unordered or O(log2(|E| / |V|)) when
  it is sorted. This operation stays quite cheap.
Disadvantages of adjacency lists (cont…)
• Adjacent list doesn't allow us to make an
  efficient implementation, if dynamically
  change of vertices number is required. Adding
  new vertex can be done in O(V), but removal
  results in O(E) complexity.
Conclusion
• Adjacency matrix is good for dense graphs.
• Adjacency lists is good for sparse graphs and
  also for changing the no of nodes.
Thank You!

More Related Content

What's hot

Graph data structure
Graph data structureGraph data structure
Graph data structure
Tech_MX
 

What's hot (20)

Linked list implementation of Queue
Linked list implementation of QueueLinked list implementation of Queue
Linked list implementation of Queue
 
Red black tree
Red black treeRed black tree
Red black tree
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Application Of Graph Data Structure
Application Of Graph Data StructureApplication Of Graph Data Structure
Application Of Graph Data Structure
 
Breadth first search and depth first search
Breadth first search and  depth first searchBreadth first search and  depth first search
Breadth first search and depth first search
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
stack & queue
stack & queuestack & queue
stack & queue
 
Linear and Binary search
Linear and Binary searchLinear and Binary search
Linear and Binary search
 
Binary trees1
Binary trees1Binary trees1
Binary trees1
 
Graph data structure and algorithms
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithms
 
1.1 binary tree
1.1 binary tree1.1 binary tree
1.1 binary tree
 
Graphs - Discrete Math
Graphs - Discrete MathGraphs - Discrete Math
Graphs - Discrete Math
 

Viewers also liked

Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
zukun
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
Grow From The Core - Adjacent Mark Moves
Grow From The Core - Adjacent Mark Moves Grow From The Core - Adjacent Mark Moves
Grow From The Core - Adjacent Mark Moves
David Sidhu
 

Viewers also liked (20)

Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Lecture8 data structure(graph)
Lecture8 data structure(graph)Lecture8 data structure(graph)
Lecture8 data structure(graph)
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Graphs
GraphsGraphs
Graphs
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
The Graph Traversal Programming Pattern
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Graph
GraphGraph
Graph
 
Skiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
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
 
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
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
Hashing
HashingHashing
Hashing
 
Network topology
Network topologyNetwork topology
Network topology
 
Syabus
SyabusSyabus
Syabus
 
Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
2.4 Other Types of Graphs
2.4 Other Types of Graphs2.4 Other Types of Graphs
2.4 Other Types of Graphs
 
Grow From The Core - Adjacent Mark Moves
Grow From The Core - Adjacent Mark Moves Grow From The Core - Adjacent Mark Moves
Grow From The Core - Adjacent Mark Moves
 

Similar to Graph representation

Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
asimshahzad8611
 
09_Graphs_handout.pdf
09_Graphs_handout.pdf09_Graphs_handout.pdf
09_Graphs_handout.pdf
Israr63
 

Similar to Graph representation (20)

BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptxBRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Graph 1
Graph 1Graph 1
Graph 1
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
Graphs in datastructures
Graphs in datastructuresGraphs in datastructures
Graphs in datastructures
 
Graphs data structures
Graphs data structuresGraphs data structures
Graphs data structures
 
ppt 1.pptx
ppt 1.pptxppt 1.pptx
ppt 1.pptx
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 
graphs presentation .pptx
graphs presentation .pptxgraphs presentation .pptx
graphs presentation .pptx
 
Graphs
GraphsGraphs
Graphs
 
Graphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ programGraphs and eularian circuit & path with c++ program
Graphs and eularian circuit & path with c++ program
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.ppt
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Lec28
Lec28Lec28
Lec28
 
UNIT III.pptx
UNIT III.pptxUNIT III.pptx
UNIT III.pptx
 
Unit-6 Graph.ppsx ppt
Unit-6 Graph.ppsx                                       pptUnit-6 Graph.ppsx                                       ppt
Unit-6 Graph.ppsx ppt
 
09_Graphs_handout.pdf
09_Graphs_handout.pdf09_Graphs_handout.pdf
09_Graphs_handout.pdf
 
Basics of graph
Basics of graphBasics of graph
Basics of graph
 
Graph
GraphGraph
Graph
 

More from Tech_MX

Virtual base class
Virtual base classVirtual base class
Virtual base class
Tech_MX
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
Tech_MX
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
Tech_MX
 
String & its application
String & its applicationString & its application
String & its application
Tech_MX
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
Tech_MX
 
Set data structure
Set data structure Set data structure
Set data structure
Tech_MX
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
Tech_MX
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
Tech_MX
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
Tech_MX
 
More on Lex
More on LexMore on Lex
More on Lex
Tech_MX
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_MX
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
Tech_MX
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
Tech_MX
 

More from Tech_MX (20)

Virtual base class
Virtual base classVirtual base class
Virtual base class
 
Uid
UidUid
Uid
 
Theory of estimation
Theory of estimationTheory of estimation
Theory of estimation
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
String & its application
String & its applicationString & its application
String & its application
 
Statistical quality__control_2
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Data Structure & It's Application
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
 
Spss
SpssSpss
Spss
 
Set data structure 2
Set data structure 2Set data structure 2
Set data structure 2
 
Set data structure
Set data structure Set data structure
Set data structure
 
Real time Operating System
Real time Operating SystemReal time Operating System
Real time Operating System
 
Parsing
ParsingParsing
Parsing
 
Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
 
Motherboard of a pc
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
 
More on Lex
More on LexMore on Lex
More on Lex
 
MultiMedia dbms
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
 
Merging files (Data Structure)
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
 
Memory dbms
Memory dbmsMemory dbms
Memory dbms
 
Linkers
LinkersLinkers
Linkers
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

Graph representation

  • 2. What is Graph ? A graph G consists of a finite set of ordered pairs, called edges E, of certain entities called vertices V. Edges are also called as arcs or links. Vertices are also called as nodes or points.
  • 3. G=(V,E) • A graph is a set of vertices and edges. A vertex may represent a state or a condition while the edge may represent a relation between two vertices.
  • 4.
  • 5. Types of Representation Two ways are there for representing graph in the memory of a computer. They are:- – Sequential Representation – Linked Representation
  • 6. Sequential Representation Graphs can be represented through matrix in system’s memory. This is sequential in nature. This type of representation is called sequential representation of graphs.
  • 7. Types of Sequential Representation • Adjacency Matrix Representation • Incidence Matrix Representation • Circuit Matrix Representation • Cut Set Matrix Representation • Path Matrix Representation
  • 8. Linked Representation • Graphs can be represented through Linked List in system’s memory. This is Linked in nature. This type of representation is called Linked representation of graphs.
  • 9. Types of Linked Representation • Adjacency List Representation
  • 10. Adjacency Matrix Representation The Adjacency matrix of a graph G with n vertices is N x N. It is given by A=[aij]. aij =1 if ith and jth vertices are adjacent. =0 if ith and jth vertices are not adjacent.
  • 12.
  • 13. Incidence Matrix Representation • The Incidence matrix of a graph G with N vertices and E edges is N x E. mij = 1 if ej is incident on vi = 0 otherwise
  • 14. Examples e1 e2 e3 e4 1 2 3 4
  • 15. Circuit Matrix Representation • Circuit Matrix is represented by the number of different circuits T and the number of edges E is T x E in the graph. The Circuit Matrix C=Cij. Cij=1 if ith circuit includes jth edge. = 0 otherwise.
  • 17. Cut Set Matrix Representation • A Matrix S = Sij Rows correspond to cut sets and columns correspond to edges of the graph is defined to be a cut set matrix. Sij = 1 if the ith cut set contains the jth edge = 0 otherwise
  • 19. Path Matrix Representation • A path matrix is generally defined for a specific pair of vertices then the path matrix denoted as P(u,v) = Pij . Pij = 1 if the jth edge lies in the ith path = 0 otherwise
  • 21. Adjacency List representation • Adjacency List representation is one of the alternatives to adjacency matrix. It requires less amount of memory. For every vertex adjacency list stores a list of vertices, which are adjacent to current one.
  • 23.
  • 24. In Computer’s • Even there are many mathematical representations… adjacency matrix and adjacency lists are only used for representing graphs in computers.
  • 25. Dense Graphs and Sparse Graphs • Dense graph is a graph in which the number of edges is close to the maximal number of edges. The opposite, a graph with only a few edges, is a sparse graph.
  • 28. Advantages of adjacency matrix Adjacency matrix is very convenient to work with. Add (remove) an edge can be done in O(1) time, the same time is required to check, if there is an edge between two vertices.
  • 29. Disadvantages of adjacency matrix • Adjacency matrix consumes huge amount of memory for storing big graphs. • Adjacency matrix requires huge efforts for adding/removing a vertex. • In many algorithms you need to know the edges, adjacent to the current vertex. To draw out such an information from the adjacency matrix you have to scan over the corresponding row, which results in O(|V|) complexity.
  • 30. Advantages of adjacency lists • Adjacent list allows us to store graph in more compact form, than adjacency matrix. • Adjacent list allows to get the list of adjacent vertices in O(1) time, which is a big advantage for some algorithms.
  • 31. Disadvantages of adjacency lists • Adding/removing an edge to/from adjacent list is not so easy as for adjacency matrix. It requires, on the average,O(|E| / |V|) time, which may result in cubical complexity for dense graphs to add all edges. • If there is an edge between two vertices can be done in O(|E| / |V|) when list of adjacent vertices is unordered or O(log2(|E| / |V|)) when it is sorted. This operation stays quite cheap.
  • 32. Disadvantages of adjacency lists (cont…) • Adjacent list doesn't allow us to make an efficient implementation, if dynamically change of vertices number is required. Adding new vertex can be done in O(V), but removal results in O(E) complexity.
  • 33. Conclusion • Adjacency matrix is good for dense graphs. • Adjacency lists is good for sparse graphs and also for changing the no of nodes.