graphs – searching for relationships comp 200 & comp 130 john greiner & stephen wong

27
Graphs – Searching for Relationships COMP 200 & COMP 130 John Greiner & Stephen Wong

Upload: dulcie-white

Post on 16-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Graphs – Searching for Relationships

COMP 200 & COMP 130

John Greiner & Stephen Wong

Graphs – A Reminder

Vertices/nodes + edges connecting vertices

1

3

2

5

4

Directed

1

3

2

5

4

Undirected

Social graph

How are you connected to

someone else?

Math co-authors, centered on Paul Erdös.

Can Introducing Hepocyte Growth Factor Lead to Apoptosis?

How are Two Species Related?

7

Discovering Your Own Relations

8

How to Solve a Maze?

9

Solving a Maze: Right-Hand Rule

Good when you don’t know the maze layout.

10

How to Get to Work?

12

Focus on Three Algorithms

• Depth-first Search

• Breadth-first Search

• Dijkstra’s Shortest Path

First, just quick introductions to each.

13

Depth- vs. Breadth-First Search

1 7

2

3

8

9

5

4

6

1 2c

2b

2a

3c

4b

3b

3a

4a

DFS BFS

14

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

15

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

7?

3?

4?

16

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

7?

3

4?

17

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5?

3

4?

8?

18

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5?

3

4

8?

19

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5?

3

4

8?

6?

12?

20

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8?

6?

12?

21

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8?

6

12?

22

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

12?

23

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

9?

24

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

9

25

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

913?

12?

26

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

913?

12

27

Dijkstra’s Shortest Path

4

5

3

2

7

1

8

2

3

4

0

5

3

4

8

6

913

12