Topic: Graph Wrapup CS302 The Kevin Bacon Game Object: Link a - - PDF document

topic graph wrapup cs302 the kevin bacon game
SMART_READER_LITE
LIVE PREVIEW

Topic: Graph Wrapup CS302 The Kevin Bacon Game Object: Link a - - PDF document

Nov. 22, 2005 Tuesday, Topic: Graph Wrapup CS302 The Kevin Bacon Game Object: Link a movie actor to Kevin Bacon via shared movie roles. For example: Tom Hanks has Bacon number of 1 (Hanks and Bacon were in Apollo 13


slide-1
SLIDE 1

CS302 Topic: Graph Wrapup

Tuesday,

  • Nov. 22, 2005
slide-2
SLIDE 2

The Kevin Bacon Game

  • Object:

Link a movie actor to Kevin Bacon via shared movie roles.

  • For example:
  • Tom Hanks has Bacon number
  • f 1 (Hanks and Bacon were in

Apollo 13 together)

  • Sally Fields has Bacon number

(she was in Forrest Gump with Hanks, who was in Apollo 13 with Bacon)

  • Question:
  • How do you find an actor’s

Bacon number? Kevin Bacon

slide-3
SLIDE 3

The Kevin Bacon Game (con’t)

  • Answer:
  • Vertex = actor
  • Edge (u,v) actors u and v had shared movie role
  • Do BFS from Bacon to find other actors’ Bacon

Number

slide-4
SLIDE 4

Crazy Football Rankings

  • Input: list of football game scores

(no ties)

  • Proof of “betterness”: Use silly

transitivity to “prove” that a team is better than another

  • Question:
  • Given scores, and 2 teams (X and

Y), how do you prove that X is better than Y (or vice versa), or indicate that no proof exists?

slide-5
SLIDE 5

Crazy Football Rankings (con’t.)

  • Answer:
  • Vertex = team
  • Edge (u,v) team u

defeated v

  • Given X, Y, find path from X

to Y (or Y to X).

UT LSU FL Vandy AL

slide-6
SLIDE 6

Word changes

  • A word can be changed to another word by a 1-

character substitution.

  • Assume a dictionary of 5-letter words exists.
  • Question:
  • How can we determine if word A can be

transformed to word B by a series of 1-character substitutions (and give the sequence of words)?

  • Example:
  • A: bleed
  • B: blood
  • A turns into B through sequence bleed, blend,

blond, blood

slide-7
SLIDE 7

Word changes (con’t.)

Answer:

  • Vertex = word
  • Edge from (u,v) Words u and v differ by one

character

  • Given X and Y, find path from X to Y

blood bleed blond blend flood bland breed

slide-8
SLIDE 8

Arbitrage

Input:

  • Collection of currencies and their exchange rates

Question:

  • Is there a series of exchanges that makes

money instantly?

Example:

X Y Z X 1 0.5 1/ 3 Y 2 1 0.5 Z 3 2 1 300 Z’s buys 100 X’s, which will buy 200 Y’s, which will buy 400 Z’s Made 100 Z’s just through exchanges

slide-9
SLIDE 9

Arbitrage (con’t.)

Answer:

  • Vertex = currency
  • Edge (u,v) has weight log C, where exchange

rate from u to v is C.

  • Search for negative cycle – this represents

arbitrage play

Note:

multiplication of exchange rates But, when finding paths, we add costs. So, convert to form that works when adding costs: log( ) (log ) each edge is the log of the exchange rate

i i i i i i

r r r ∏ = ∏ = ⇒

Y Z X 0.48

  • 0.48
  • 0.3

0.3 0.3

  • 0.3
slide-10
SLIDE 10

Team competition

Winning team: 10 points homework extra credit Losing team: 3 points homework extra credit

slide-11
SLIDE 11

(1) DFS

Give the order that the vertices are visited using DFS on this graph, starting at v0, with the tie- breaking rule being that vertices are visited alphabetically:

v6 v2 v3 v0 v5 v1 v4

Answer: v0 v1 v3 v5 v6 v4 v2

slide-12
SLIDE 12

(2) BFS

Give the order that the vertices are visited using BFS on this graph, starting at v0, with the tie- breaking rule being that vertices are visited alphabetically:

v6 v2 v3 v0 v5 v1 v4

Answer: v0 v1 v4 v3 v5 v6 v2

slide-13
SLIDE 13

(3) Airline flights

Suppose you have a directed graph representing all the flights that an airline flies. What algorithm might be used to find the best sequence of connections from one city to another?

a) Breadth first search b) Depth first search c) A cycle-finding algorithm d) A shortest-path algorithm Answer: d

slide-14
SLIDE 14

(4) Topological Sort

Give a topological sort of the following graph:

v6 v2 v3 v0 v5 v1 v4

Some possible answers: v2 v0 v4 v1 v3 v6 v5 v2 v0 v1 v3 v6 v5 v4 v2 v0 v1 v3 v4 v5 v6

slide-15
SLIDE 15

(5) Adjacency matrix representation

If G is a directed graph with 20 vertices, how many boolean values will be needed to represent G using an adjacency matrix?

a) 20 b) 40 c) 200 d) 400 Answer: d

slide-16
SLIDE 16

(6) Adjacency list representation

How many linked lists are used to represent a graph with n nodes and m edges, using an adjacency list representation?

a) m b) n c) m + n d) m * n Answer: b

slide-17
SLIDE 17

(7) Spanning trees

How many spanning trees does the following graph have?

a) 4 b) 8 c) 3 d) 6

A C F D B E

Answer: a

slide-18
SLIDE 18

(8) Kruskal’s algorithm

Using Kruskal’s algorithm which edge should we choose second?

a) CD b) AB c) AC d) BD

A D B E C 25 10 5 30 11 22 18 15 8 20

Answer: c

slide-19
SLIDE 19

(9) Kruskal’s algorithm

Using Kruskal’s algorithm which edge should we choose third?

a) AC b) CD c) AB d) BD

A D B E C 25 10 5 30 11 22 18 15 8 20

Answer: d

slide-20
SLIDE 20

(10) Trees

Which of the following are trees?

Answer: Graphs 1 and 3

slide-21
SLIDE 21

(11) Network Flow

What is the value of the maximum flow in the following graph?

s C F t B E 3 2 1 1 4 3 2 3

Answer: 4

slide-22
SLIDE 22

(12) Dijkstra’s algorithm

  • Below is an intermediate

stage of Dijkstra’s algorithm operating on this graph.

  • What is the next vertex

selected?

v1 v6 v2 v7 v3 v4 v5 4 10 1 3 2 6 4 8 5 1 v1 v2 v3 v4 v5 v6 v7 T F F T F F F 2 3 1 3 9 5 v1 v4 v1 v4 v4 v4 2 Known? dv pv

Answer: v2

2

slide-23
SLIDE 23

(13) Dijkstra’s algorithm

  • Assume v2 has been

selected for processing by Dijkstra’s algorithm.

  • What are the changes to

the dv column?

v1 v6 v2 v7 v3 v4 v5 4 10 1 3 2 6 4 8 5 1 2 v1 v2 v3 v4 v5 v6 v7 T F F T F F F 2 3 1 3 9 5 v1 v4 v1 v4 v4 v4 Known? dv pv 2

Answer: no changes made

slide-24
SLIDE 24

(14) Articulation points

Name all the articulation points of this graph

E B C H J I K F G D A

Answer: C, E, F