1 / 60

Graphs - PowerPoint PPT Presentation

Graphs. Ed. 2. and 3.: Chapter 12 Ed. 4.: Chapter 13. Graphs Graph ADT - What is a graph? - Graph methods Data structure for graphs - Edge list structure, adjacency list structure, adjacency matrix Graph Traversal - Depth-first search - Breadth-first search Directed graphs.

Related searches for Graphs

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

PowerPoint Slideshow about 'Graphs' - Sophia

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

• Ed. 2. and 3.: Chapter 12

• Ed. 4.: Chapter 13

• Graphs

• - What is a graph?

• - Graph methods

• Data structure for graphs

• - Edge list structure, adjacency list

• Graph Traversal

• - Depth-first search

• Directed graphs

(u, v)

u

v

(Toronto)

(Winnipeg)

(v, u)

v

(New York)

(Winnipeg)

(v, u)

c1

c2

rank

c3

The edge object for an edge

e

storing element

o

has data fields

for

A reference to

o

·

A Boolean indicator of whether e is directed or not

·

·

References to the vertex objects in

V

associated with the

endpoint vertices of

e

(if the edge

e

is undir

ected) or to

the origin and destination vertices of

e

(if the edge

e

is

directed)

·

A reference to the position of the edge

-

object in container

E

Note: The last data field is the rank of the edge object in the

container

E

if

E

is a vector.

With an edge list, some methods (edge

-

based) are fast while

others need some efforts.

For example, methods endVertices(), origin(), and destination()

are fast because we can access edges directly.

end vertex

1 or 0

end vertex

The

structure for a graph

extends the edge list

G

structure. Like the edge list structure, the adjacency list

structure has a container

for the vertices and

for the edges.

V

E

More data structures and fields are

edge objects.

The vertex object

holds a reference to a container

(

),

v

I

v

·

called the incidence container, that stores references to

the edges incident on

. If directed edges are allowed,

v

then we partition

(

) into

(

)

,

(

)

, and

(

)

that

I

v

I

v

I

v

I

v

in

ou

t

un

store the in

-

coming, out

-

going, and undirected edges

incident to

.

v

AC112

Ottawa

JG120

AC200

Vancouver

Winnipeg

Calgary

JG131

WJ75

WJ35

Toronto

JG130

The edge object for an edge (

u

,

v

) holds references to the

·

positions of the edge in the incidence containers

I

(

u

) and

I

(

v

).

Example:

n

vertices in the graph

A vertex

v

also stores a distinct integer key in the range 0,

·

1, …,

n

-

1, called the index of

v

(or simply “index

v

”).

In the

n

x

n

array

A

, the cell

A

[

i

,

j

] holds a referenc

e to

·

the edge object

e

that goes from the vertex with index

i

to

the vertex with index

j

, if such edge exists. If the edge

e

is

undirected, we store references to

e

in both

A

[

i

,

j

] and

A

[

j

,

i

]. If there is no edge from vertex

i

to vertex

j

, we

store a null

object in both

A

[

i

,

j

] and

A

[

j

,

i

].