slide1
Download
Skip this Video
Download Presentation
Graphs

Loading in 2 Seconds...

play fullscreen
1 / 60

Graphs - PowerPoint PPT Presentation


  • 200 Views
  • Uploaded on

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.

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

PowerPoint Slideshow about 'Graphs' - Sophia


An Image/Link below is provided (as is) to download presentation

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
slide1

Graphs

  • Ed. 2. and 3.: Chapter 12
  • Ed. 4.: Chapter 13
slide2

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
slide4

(u, v)

u

v

(Toronto)

(Winnipeg)

(v, u)

slide5

u

v

(New York)

(Winnipeg)

(v, u)

slide45

element

c1

c2

rank

c3

slide46

Edge Objects

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.

slide47

element

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

slide52

The Adjacency List Structure

adjacency list

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

added to vertex objects and

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

slide53

AC201

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:

slide57

Here is how the information is stored: Assume there are

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

].

ad