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
Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.
Be the first to comment