Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphs.

Similar presentations


Presentation on theme: "Graphs."— Presentation transcript:

1 Graphs

2 Graphs Graphs is a data structure that differ from all the others in one major concept , each node may have multiple predecessors as well as multiple successors . Graphs are very useful structure . They can be used to solve complex routing problems ,such as : * designing and routing airlines among the air ports they serve . * route messages over a computer network from one node to another .

3 Terminology Graph collection of nodes (vertices)
collection of line segments connecting vertices (edges) Graph may be : Directed Each line segment has a direction (Arc) to its successor Undirected No direction on any line segment (Edge)

4

5 Neighbors Two vertices are said to be neighbors if an edge directly connects them Path A sequence of vertices in which each vertex is adjacent to the other Cycle A path that start and ends with the same vertex Loop A single Arc that begins and ends with the same vertex

6 Strongly connected If there is a path from each vertex to every other vertex in the directed graph . Weakly connected If at least two vertices are not connected Disjoint A graph is disjoint if it not connected

7 Weakly connected A B E G F C D H I

8 Strongly connected A B E G F C D H I

9 Disjoint A B E G F C D H I

10 Degree of vertex Is the number of lines incident to it . Out degree of vertex in digraph Is the number of arcs leaving the vertex Indegree Is the number of arcs entering the vertex

11 Operations Add Vertex Insert a new vertex in the graph
When a vertex is added it is disjoint , it is not connected to any other vertices in the list . B A B A AddVertix C C E E

12 Delete Vertex Removes a vertex from the graph .When a vertex is deleted , all connecting edges are removed . B A B A C E C E

13 Connect a vertex to a destination vertex .
Add edge Connect a vertex to a destination vertex . If the graph is a digraph , then one of the edges must be the source and the other is the destination . B A B A C E C E

14 Find Vertex Traverse the graph looking for a specified vertex. If the vertex is found , its data are returned . If it is not founded , an error is indicated .

15 Graph Storage Structures
To represent a graph , we need to store two sets : The vertices of the graph The edges or arcs . The two common structures used to store these sets are array and linked list .

16 Adjacency matrix Uses a vector ( one –dimensional array ) for the vertices and a matrix (two - dimensional array) to store the edges .

17 Adjacency list Uses a two- dimensional ragged array to store the edges . The vertex list is a singly linked list of the vertices in the list .


Download ppt "Graphs."

Similar presentations


Ads by Google