Graph representation

T
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.
Graph representation
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
Graph representation
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
Graph representation
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!
1 de 34

Recomendados

Data structure - Graph por
Data structure - GraphData structure - Graph
Data structure - GraphMadhu Bala
6.3K vistas28 diapositivas
Graph in data structure por
Graph in data structureGraph in data structure
Graph in data structureAbrish06
42.9K vistas24 diapositivas
Graphs In Data Structure por
Graphs In Data StructureGraphs In Data Structure
Graphs In Data StructureAnuj Modi
45.6K vistas32 diapositivas
Graph traversals in Data Structures por
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data StructuresAnandhasilambarasan D
4.4K vistas11 diapositivas
Tree traversal techniques por
Tree traversal techniquesTree traversal techniques
Tree traversal techniquesSyed Zaid Irshad
3.1K vistas34 diapositivas
Red black tree por
Red black treeRed black tree
Red black treeDr Sandeep Kumar Poonia
14.6K vistas87 diapositivas

Más contenido relacionado

La actualidad más candente

Arrays por
ArraysArrays
ArraysSARITHA REDDY
26.1K vistas50 diapositivas
Spanning trees por
Spanning treesSpanning trees
Spanning treesShareb Ismaeel
9.3K vistas14 diapositivas
trees in data structure por
trees in data structure trees in data structure
trees in data structure shameen khan
3.5K vistas55 diapositivas
Queue ppt por
Queue pptQueue ppt
Queue pptSouravKumar328
20.2K vistas16 diapositivas
Graph data structure and algorithms por
Graph data structure and algorithmsGraph data structure and algorithms
Graph data structure and algorithmsAnandhasilambarasan D
2.2K vistas10 diapositivas
Presentation on queue por
Presentation on queuePresentation on queue
Presentation on queueRojan Pariyar
8.1K vistas15 diapositivas

La actualidad más candente(20)

trees in data structure por shameen khan
trees in data structure trees in data structure
trees in data structure
shameen khan3.5K vistas
Presentation on queue por Rojan Pariyar
Presentation on queuePresentation on queue
Presentation on queue
Rojan Pariyar8.1K vistas
linked list in data structure por shameen khan
linked list in data structure linked list in data structure
linked list in data structure
shameen khan39.1K vistas
Graphs in data structure por hamza javed
Graphs in data structureGraphs in data structure
Graphs in data structure
hamza javed1.8K vistas
Graph Traversal Algorithm por jyothimonc
Graph Traversal AlgorithmGraph Traversal Algorithm
Graph Traversal Algorithm
jyothimonc7.3K vistas
Sorting Algorithms por Pranay Neema
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Pranay Neema6.4K vistas
Graph traversal-BFS & DFS por Rajandeep Gill
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
Rajandeep Gill1.2K vistas
1.1 binary tree por Krish_ver2
1.1 binary tree1.1 binary tree
1.1 binary tree
Krish_ver218.3K vistas
Threaded Binary Tree por khabbab_h
Threaded Binary TreeThreaded Binary Tree
Threaded Binary Tree
khabbab_h23.8K vistas

Destacado

Matrix Representation Of Graph por
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of GraphAbhishek Pachisia
26K vistas8 diapositivas
Data structure computer graphs por
Data structure computer graphsData structure computer graphs
Data structure computer graphsKumar
4.4K vistas22 diapositivas
Data Structures - Lecture 10 [Graphs] por
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Muhammad Hammad Waseem
6.4K vistas52 diapositivas
Graph data structure por
Graph data structureGraph data structure
Graph data structureTech_MX
14.1K vistas28 diapositivas
Graphs por
GraphsGraphs
GraphsMohd Arif
5.6K vistas91 diapositivas

Destacado(20)

Data structure computer graphs por Kumar
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar 4.4K vistas
Graph data structure por Tech_MX
Graph data structureGraph data structure
Graph data structure
Tech_MX14.1K vistas
Graphs por Mohd Arif
GraphsGraphs
Graphs
Mohd Arif5.6K vistas
Trees data structure por Sumit Gupta
Trees data structureTrees data structure
Trees data structure
Sumit Gupta19.4K vistas
The Graph Traversal Programming Pattern por Marko Rodriguez
The Graph Traversal Programming PatternThe Graph Traversal Programming Pattern
The Graph Traversal Programming Pattern
Marko Rodriguez56.3K vistas
DATA STRUCTURES por bca2010
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca201096.8K vistas
Skiena algorithm 2007 lecture10 graph data strctures por zukun
Skiena algorithm 2007 lecture10 graph data strcturesSkiena algorithm 2007 lecture10 graph data strctures
Skiena algorithm 2007 lecture10 graph data strctures
zukun2.2K vistas
Spanning trees & applications por Tech_MX
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX24.6K vistas
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring por Saurabh Kaushik
Graph Theory,Graph Terminologies,Planar Graph & Graph ColouringGraph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Graph Theory,Graph Terminologies,Planar Graph & Graph Colouring
Saurabh Kaushik10.7K vistas
Prim's Algorithm on minimum spanning tree por oneous
Prim's Algorithm on minimum spanning treePrim's Algorithm on minimum spanning tree
Prim's Algorithm on minimum spanning tree
oneous49.3K vistas
Trees (data structure) por Trupti Agrawal
Trees (data structure)Trees (data structure)
Trees (data structure)
Trupti Agrawal12.4K vistas
Network topology por toramamohan
Network topologyNetwork topology
Network topology
toramamohan382 vistas
Lecture 5b graphs and hashing por Victor Palmar
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar1.2K vistas

Similar a Graph representation

BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx por
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptxBRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptxCHIRANTANMONDAL2
69 vistas11 diapositivas
Graph Theory por
Graph TheoryGraph Theory
Graph TheoryRashmi Bhat
303 vistas78 diapositivas
Graph 1 por
Graph 1Graph 1
Graph 1International Islamic University
272 vistas90 diapositivas
Graphs in datastructures por
Graphs in datastructuresGraphs in datastructures
Graphs in datastructuresLikhithaGunturi
140 vistas10 diapositivas
Graphs data structures por
Graphs data structuresGraphs data structures
Graphs data structuresJasleen Kaur (Chandigarh University)
493 vistas55 diapositivas
ppt 1.pptx por
ppt 1.pptxppt 1.pptx
ppt 1.pptxShasidharaniD
5 vistas82 diapositivas

Similar a Graph representation(20)

BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx por CHIRANTANMONDAL2
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptxBRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
BRIEF RELETIONSHIP BETWEEN ADJACENCY MATRIX AND LIST.pptx
CHIRANTANMONDAL269 vistas
Graph Data Structure por Keno benti
Graph Data StructureGraph Data Structure
Graph Data Structure
Keno benti606 vistas
graphs presentation .pptx por ssuser800a48
graphs presentation .pptxgraphs presentation .pptx
graphs presentation .pptx
ssuser800a484 vistas
09_Graphs_handout.pdf por Israr63
09_Graphs_handout.pdf09_Graphs_handout.pdf
09_Graphs_handout.pdf
Israr631 vista
Basics of graph por Khaled Sany
Basics of graphBasics of graph
Basics of graph
Khaled Sany588 vistas
Introduction to graphs and their ability to represent images por Anyline
Introduction to graphs and their ability to represent imagesIntroduction to graphs and their ability to represent images
Introduction to graphs and their ability to represent images
Anyline2.3K vistas
Graph Algorithms por Ashwin Shiv
Graph AlgorithmsGraph Algorithms
Graph Algorithms
Ashwin Shiv121 vistas
Data structure - traveling sales person and mesh algorithm por lavanya marichamy
Data structure - traveling sales person and mesh algorithmData structure - traveling sales person and mesh algorithm
Data structure - traveling sales person and mesh algorithm
lavanya marichamy152 vistas
Graph theory concepts complex networks presents-rouhollah nabati por nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
nabati2.8K vistas

Más de Tech_MX

Virtual base class por
Virtual base classVirtual base class
Virtual base classTech_MX
11.8K vistas13 diapositivas
Uid por
UidUid
UidTech_MX
10.4K vistas33 diapositivas
Theory of estimation por
Theory of estimationTheory of estimation
Theory of estimationTech_MX
45.1K vistas30 diapositivas
Templates in C++ por
Templates in C++Templates in C++
Templates in C++Tech_MX
18.1K vistas21 diapositivas
String & its application por
String & its applicationString & its application
String & its applicationTech_MX
5.5K vistas28 diapositivas
Statistical quality__control_2 por
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2Tech_MX
2.5K vistas34 diapositivas

Más de Tech_MX(20)

Virtual base class por Tech_MX
Virtual base classVirtual base class
Virtual base class
Tech_MX11.8K vistas
Uid por Tech_MX
UidUid
Uid
Tech_MX10.4K vistas
Theory of estimation por Tech_MX
Theory of estimationTheory of estimation
Theory of estimation
Tech_MX45.1K vistas
Templates in C++ por Tech_MX
Templates in C++Templates in C++
Templates in C++
Tech_MX18.1K vistas
String & its application por Tech_MX
String & its applicationString & its application
String & its application
Tech_MX5.5K vistas
Statistical quality__control_2 por Tech_MX
Statistical  quality__control_2Statistical  quality__control_2
Statistical quality__control_2
Tech_MX2.5K vistas
Stack data structure por Tech_MX
Stack data structureStack data structure
Stack data structure
Tech_MX22.7K vistas
Stack Data Structure & It's Application por Tech_MX
Stack Data Structure & It's Application Stack Data Structure & It's Application
Stack Data Structure & It's Application
Tech_MX31.1K vistas
Spss por Tech_MX
SpssSpss
Spss
Tech_MX120.8K vistas
Set data structure 2 por Tech_MX
Set data structure 2Set data structure 2
Set data structure 2
Tech_MX7K vistas
Set data structure por Tech_MX
Set data structure Set data structure
Set data structure
Tech_MX24.8K vistas
Real time Operating System por Tech_MX
Real time Operating SystemReal time Operating System
Real time Operating System
Tech_MX106.5K vistas
Parsing por Tech_MX
ParsingParsing
Parsing
Tech_MX3.7K vistas
Mouse interrupts (Assembly Language & C) por Tech_MX
Mouse interrupts (Assembly Language & C)Mouse interrupts (Assembly Language & C)
Mouse interrupts (Assembly Language & C)
Tech_MX17.3K vistas
Motherboard of a pc por Tech_MX
Motherboard of a pcMotherboard of a pc
Motherboard of a pc
Tech_MX6.1K vistas
More on Lex por Tech_MX
More on LexMore on Lex
More on Lex
Tech_MX8K vistas
MultiMedia dbms por Tech_MX
MultiMedia dbmsMultiMedia dbms
MultiMedia dbms
Tech_MX8.5K vistas
Merging files (Data Structure) por Tech_MX
Merging files (Data Structure)Merging files (Data Structure)
Merging files (Data Structure)
Tech_MX11.1K vistas
Memory dbms por Tech_MX
Memory dbmsMemory dbms
Memory dbms
Tech_MX966 vistas
Linkers por Tech_MX
LinkersLinkers
Linkers
Tech_MX33.2K vistas

Último

Voice Logger - Telephony Integration Solution at Aegis por
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 vistas1 diapositiva
Scaling Knowledge Graph Architectures with AI por
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
30 vistas15 diapositivas
Evolving the Network Automation Journey from Python to Platforms por
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 vistas21 diapositivas
The Research Portal of Catalonia: Growing more (information) & more (services) por
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 vistas25 diapositivas
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 vistas15 diapositivas
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
37 vistas69 diapositivas

Último(20)

Voice Logger - Telephony Integration Solution at Aegis por Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 vistas
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors por sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 vistas
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... por Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker37 vistas
Case Study Copenhagen Energy and Business Central.pdf por Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 vistas
Five Things You SHOULD Know About Postman por Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman33 vistas
SAP Automation Using Bar Code and FIORI.pdf por Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
Virendra Rai, PMP23 vistas
HTTP headers that make your website go faster - devs.gent November 2023 por Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn22 vistas
Unit 1_Lecture 2_Physical Design of IoT.pdf por StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 vistas
Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software263 vistas
Piloting & Scaling Successfully With Microsoft Viva por Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Richard Harbridge12 vistas
PharoJS - Zürich Smalltalk Group Meetup November 2023 por Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 vistas

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.
  • 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.
  • 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.
  • 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.