SlideShare ist ein Scribd-Unternehmen logo
1 von 15
GRAPHS
Adjacency Lists
Reporters: Group 10
Graph Jargon:
ď‚› Vertex
(also called a node) is a fundamental
part of a graph.
ď‚› Edge
(also called an arc) is another
fundamental part of a graph. It connects
two vertices to show that there is a
relationship between them.
Definition of Terms
ď‚› Weight
Edges may be weighted to show that
there is a cost to go from one vertex to
another.
ď‚› Path
a sequence of vertices such that any
two consecutive vertices are connected
by an edge.
Definition Of Terms (Con’t.)
Graph Illustration
Path from V3 to V1?
ADJACENCY LIST
Adjacency List
ď‚› A type of graph representation wherein
each vertex holds a list of every other
vertex adjacent to it.
ď‚› In an adjacency list implementation, we
keep a master list of all the vertices in the
Graph object and then each vertex
object in the graph maintains a list of the
other vertices that it is connected to.
Adjacency List
Adjacency List Illustration
Example of an Undirected Graph
Adjacency List Illustration
Node class:
Adjacency List Methods
int Node Node
Node data members:
• Reference to other nodes in the graph
• Reference to the linked list of its adjacent nodes
• Actual value of the node
ď‚› Graph()
creates a new, empty graph.
ď‚› Transformers:
ď‚› addNode()
adds an instance of Vertex to the graph.
ď‚› addEdge(Node1, Node2)
adds a new, directed edge to the graph that
connects two vertices.
ď‚› deleteNode(Node)
removes a node and any edges between this node
and other nodes.
ď‚› deleteEdge(Node1, Node2)
delete the edge between two given nodes: Node1
& Node 2.
Adjacency List Methods
ď‚› Observers:
ď‚› getVertices()
returns the list of all vertices in the graph.
ď‚› isEmpty()
determines whether the graph is empty.
ď‚› isLink(Node1, Node2)
returns true if edge(Node1, Node2) is present in the
graph, false otherwise.
Bonus method/s:
findPath(Node1, Node2)
//pre: Node1 and Node2 are existing in the graph
//post: returns the list of nodes on a path from Node1 to
Node2.
Adjacency List Methods
Pros and Cons of ADT:
ď‚› Advantages:
ď‚› Easy to retrieve all the adjacent nodes of a given
node(just traverse the list associated with the node)
ď‚› Easy to check whether a node has edges starting
from it
ď‚› Less memory space is needed.
ď‚› Limitation:
ď‚› More complex operation for checking whether there
is an edge between two given nodes.
Pros and Cons of ADT
Graph Traversal Algorithms
Depth First Search
ď‚› Puts unvisited nodes in a STACK.
Breadth First Search
ď‚› Puts unvisited nodes in a QUEUE.
Traversal Algorithms
Applications of ADT:
ď‚› The applications for graphs are many and
varied. They can be used to analyze
electrical circuits, develop project
schedules, find shortest routes, analyze
social relationships, and construct models
for the analysis and solution of many other
problems.
Applications of ADT
Applications of ADT Con’t

Weitere ähnliche Inhalte

Was ist angesagt?

Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
Tech_MX
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
DEEPIKA T
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
Zain Zafar
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
Alizay Khan
 

Was ist angesagt? (20)

Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
Spanning trees & applications
Spanning trees & applicationsSpanning trees & applications
Spanning trees & applications
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]Data Structures - Lecture 7 [Linked List]
Data Structures - Lecture 7 [Linked List]
 
Depth first search [dfs]
Depth first search [dfs]Depth first search [dfs]
Depth first search [dfs]
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Leftist heap
Leftist heapLeftist heap
Leftist heap
 
Graphs in data structure
Graphs in data structureGraphs in data structure
Graphs in data structure
 
single linked list
single linked listsingle linked list
single linked list
 
Sparse matrices
Sparse matricesSparse matrices
Sparse matrices
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Graphs
GraphsGraphs
Graphs
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 
Hash table
Hash tableHash table
Hash table
 
Expression trees
Expression treesExpression trees
Expression trees
 
Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
 

Andere mochten auch

Graphs
GraphsGraphs
Graphs
Mohd Arif
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
Kumar
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
Tech_MX
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
Abhishek Pachisia
 

Andere mochten auch (18)

Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015Loom & Functional Graphs in Clojure @ LambdaConf 2015
Loom & Functional Graphs in Clojure @ LambdaConf 2015
 
3 d printer project
3 d printer project3 d printer project
3 d printer project
 
Graph data structure
Graph  data structureGraph  data structure
Graph data structure
 
Graphs
GraphsGraphs
Graphs
 
Graphs in Data Structure
 Graphs in Data Structure Graphs in Data Structure
Graphs in Data Structure
 
Data structure computer graphs
Data structure computer graphsData structure computer graphs
Data structure computer graphs
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
BFS
BFSBFS
BFS
 
Data structures
Data structuresData structures
Data structures
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
Graph data structure
Graph data structureGraph data structure
Graph data structure
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Depth first search and breadth first searching
Depth first search and breadth first searchingDepth first search and breadth first searching
Depth first search and breadth first searching
 
Introduction to graph class 8
Introduction to graph class 8Introduction to graph class 8
Introduction to graph class 8
 
Graph Basic In Data structure
Graph Basic In Data structureGraph Basic In Data structure
Graph Basic In Data structure
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Robotics project ppt
Robotics project pptRobotics project ppt
Robotics project ppt
 

Ă„hnlich wie Adjacency list

Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
Victor Palmar
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
pournima055
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
Aakash deep Singhal
 
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
 

Ă„hnlich wie Adjacency list (20)

Lecture 5b graphs and hashing
Lecture 5b graphs and hashingLecture 5b graphs and hashing
Lecture 5b graphs and hashing
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjteUnit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
Unit II_Graph.pptxkgjrekjgiojtoiejhgnltegjte
 
logic.pptx
logic.pptxlogic.pptx
logic.pptx
 
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
 
Talk on Graph Theory - I
Talk on Graph Theory - ITalk on Graph Theory - I
Talk on Graph Theory - I
 
DATA STRUCTURES.pptx
DATA STRUCTURES.pptxDATA STRUCTURES.pptx
DATA STRUCTURES.pptx
 
Chap 6 Graph.ppt
Chap 6 Graph.pptChap 6 Graph.ppt
Chap 6 Graph.ppt
 
Daa chpater 12
Daa chpater 12Daa chpater 12
Daa chpater 12
 
Chapter9 graph data structure
Chapter9  graph data structureChapter9  graph data structure
Chapter9 graph data structure
 
Lecture 14 data structures and algorithms
Lecture 14 data structures and algorithmsLecture 14 data structures and algorithms
Lecture 14 data structures and algorithms
 
data structures and algorithms Unit 2
data structures and algorithms Unit 2data structures and algorithms Unit 2
data structures and algorithms Unit 2
 
Dijkstra
DijkstraDijkstra
Dijkstra
 
d
dd
d
 
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
 
Graph therory
Graph theroryGraph therory
Graph therory
 
Graphs
GraphsGraphs
Graphs
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________graph_theory_1-11.pdf___________________
graph_theory_1-11.pdf___________________
 
Graph Data Structure
Graph Data StructureGraph Data Structure
Graph Data Structure
 

KĂĽrzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

KĂĽrzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Adjacency list

  • 2. Graph Jargon: ď‚› Vertex (also called a node) is a fundamental part of a graph. ď‚› Edge (also called an arc) is another fundamental part of a graph. It connects two vertices to show that there is a relationship between them. Definition of Terms
  • 3. ď‚› Weight Edges may be weighted to show that there is a cost to go from one vertex to another. ď‚› Path a sequence of vertices such that any two consecutive vertices are connected by an edge. Definition Of Terms (Con’t.)
  • 6. Adjacency List ď‚› A type of graph representation wherein each vertex holds a list of every other vertex adjacent to it. ď‚› In an adjacency list implementation, we keep a master list of all the vertices in the Graph object and then each vertex object in the graph maintains a list of the other vertices that it is connected to. Adjacency List
  • 7. Adjacency List Illustration Example of an Undirected Graph
  • 9. Node class: Adjacency List Methods int Node Node Node data members: • Reference to other nodes in the graph • Reference to the linked list of its adjacent nodes • Actual value of the node
  • 10. ď‚› Graph() creates a new, empty graph. ď‚› Transformers: ď‚› addNode() adds an instance of Vertex to the graph. ď‚› addEdge(Node1, Node2) adds a new, directed edge to the graph that connects two vertices. ď‚› deleteNode(Node) removes a node and any edges between this node and other nodes. ď‚› deleteEdge(Node1, Node2) delete the edge between two given nodes: Node1 & Node 2. Adjacency List Methods
  • 11. ď‚› Observers: ď‚› getVertices() returns the list of all vertices in the graph. ď‚› isEmpty() determines whether the graph is empty. ď‚› isLink(Node1, Node2) returns true if edge(Node1, Node2) is present in the graph, false otherwise. Bonus method/s: findPath(Node1, Node2) //pre: Node1 and Node2 are existing in the graph //post: returns the list of nodes on a path from Node1 to Node2. Adjacency List Methods
  • 12. Pros and Cons of ADT: ď‚› Advantages: ď‚› Easy to retrieve all the adjacent nodes of a given node(just traverse the list associated with the node) ď‚› Easy to check whether a node has edges starting from it ď‚› Less memory space is needed. ď‚› Limitation: ď‚› More complex operation for checking whether there is an edge between two given nodes. Pros and Cons of ADT
  • 13. Graph Traversal Algorithms Depth First Search ď‚› Puts unvisited nodes in a STACK. Breadth First Search ď‚› Puts unvisited nodes in a QUEUE. Traversal Algorithms
  • 14. Applications of ADT: ď‚› The applications for graphs are many and varied. They can be used to analyze electrical circuits, develop project schedules, find shortest routes, analyze social relationships, and construct models for the analysis and solution of many other problems. Applications of ADT
  • 15. Applications of ADT Con’t