Download presentation

Presentation is loading. Please wait.

Published byAspen Elmes Modified over 2 years ago

1
**ICOM 4035 – Data Structures Lecture 15 – Graph ADT**

Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico, Mayagüez ©Manuel Rodriguez – All rights reserved

2
**Lecture Organization Part I – Introduction to the Graph ADT**

Part II – Implementation of the Graph ADT using an adjacency lists M. Rodriguez-Martinez ICOM 4035

3
**Objectives Introduce the concept of a graph**

Collection of nodes interconnected by edges Discuss design and implementation of graph adt Provide motivating examples M. Rodriguez-Martinez ICOM 4035

4
**Companion videos Lecture15 videos**

Contains the coding process associated with this lecture Shows how to build the interfaces, concrete classes, and factory classes mentioned here M. Rodriguez-Martinez ICOM 4035

5
Part I Introduction to the Graph ADT M. Rodriguez-Martinez ICOM 4035

6
**Uses of graphs Graphs Graphs are used to represent:**

Collection of nodes connected by edges G = (V,E) V = collection of nodes E = collection of edges Graphs are used to represent: Roads/airline routes between cities Relationships between persons Facebook friendship Connections between computers on a network Job scheduling An many more … M. Rodriguez-Martinez ICOM 4035

7
**Introduction to Graphs**

San Juan Bob Hatillo Fajardo Apu Ned Aguadilla Ponce Money debtor Mayaguez Roads between cities Collection of nodes interconnected by edges M. Rodriguez-Martinez ICOM 4035

8
**Introduction to Graphs (2)**

UPRRP UPRM UPR RCM UPRA UPR AC Classic use for graphs: network modeling M. Rodriguez-Martinez ICOM 4035

9
**Directed Graph Directed Graph**

A Graph G=(V,E) is directed graph whenever the edges have an associated direction i.e., edge (a,b) is different from (b,a) or (b,a) might not be present Bob Directed Graph Apu Ned Money debtor M. Rodriguez-Martinez ICOM 4035

10
**Undirected Graph Undirected Graph**

San Juan A Graph G=(V,E) is undirected graph whenever the edges have no associated direction i.e., edge (a,b) is the same as (b,a) Hatillo Fajardo Aguadilla Ponce Mayaguez Roads between cities Undirected Graph M. Rodriguez-Martinez ICOM 4035

11
**Graph vs Tree A Tree is a special case of a undirected graph**

In general, graphs: Have no notion of root node Have no notion of leaf nodes Can have cycles Can be disconnected M. Rodriguez-Martinez ICOM 4035

12
**Disconnected Graph Notice that Aguadilla and Mayaguez are disconnected**

San Juan Hatillo Fajardo Notice that Aguadilla and Mayaguez are disconnected Aguadilla Ponce Mayaguez Roads between cities M. Rodriguez-Martinez ICOM 4035

13
Path in Graph Path: Given a graph G = (V, E), a path P in G is a collection of edges P = {e1, e2, …, ek} such that e1 = (n1, n2), e2 (n2, n3), …, ek = (ni-1, ni). A path is made by connecting consecutive edges Alternative notation: P = {n1, n2, n3, ...,ni-1, ni} Left to right order is important. Leftmost starts the path Paths can have cycles One or more nodes repeat M. Rodriguez-Martinez ICOM 4035

14
**Paths in a graph Example Paths:**

San Juan Example Paths: P1 = {San Juan, Ponce, Mayaguez, Aguadilla, Hatillo, San Juan, Fajardo} P2 = {Ponce, San Juan, Fajardo} Hatillo Fajardo Aguadilla Ponce Mayaguez Roads between cities M. Rodriguez-Martinez ICOM 4035

15
**Part II Implementation of the Graph ADT using an adjacency lists**

M. Rodriguez-Martinez ICOM 4035

16
**Representation of Graphs**

There two main methods to implement Graphs Adjacency Matrix Adjacency List M. Rodriguez-Martinez ICOM 4035

17
**Adjacency Matrix Bob Ned Apu 1 Bob Apu Ned You use a boolean matrix**

1 Bob Apu Ned You use a boolean matrix 0 means there is no edge between nodes a,b 1 means there is an edge between nodes a,b Wastes too much space if matrix is sparse M. Rodriguez-Martinez ICOM 4035

18
**Adjacency Lists Bob Apu Ned You use an array of linked lists**

Each node has a list with the nodes that are adjacent to it. Saves space, and is easier to implement. M. Rodriguez-Martinez ICOM 4035

19
**Summary Introduced the concept a Graph Discussed application of Graphs**

Unbalanced ordered tree Discussed application of Graphs Illustrated implementation of directed Graphs using adjacency lists M. Rodriguez-Martinez ICOM 4035

20
**Questions? Email: manuel.rodriguez7@upr.edu M. Rodriguez-Martinez**

ICOM 4035

Similar presentations

OK

Graphs. Graph Definitions A graph G is denoted by G = (V, E) where V is the set of vertices or nodes of the graph E is the set of edges or arcs connecting.

Graphs. Graph Definitions A graph G is denoted by G = (V, E) where V is the set of vertices or nodes of the graph E is the set of edges or arcs connecting.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Download ppt on the rime of ancient mariner part 1 Ppt on basics of ms word 2007 Ppt on singapore business tourism Ppt on struts framework in java Convert pdf ppt to ppt online ticket Ppt on gender inequality in education Ppt on inhabiting other planets in the solar Ppt on surface water definition Ppt on land pollution in india Ppt on you can win lyrics