Adjacency list

4,928 views 15 slides Aug 03, 2013
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

No description available for this slideshow.


Slide Content

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