Adjacency list
Upcoming SlideShare
Loading in...5
×
 

Adjacency list

on

  • 919 views

 

Statistics

Views

Total Views
919
Views on SlideShare
919
Embed Views
0

Actions

Likes
0
Downloads
15
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Adjacency list Adjacency list Presentation Transcript

  • 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