topic graph wrapup cs302 the kevin bacon game
play

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


  1. Nov. 22, 2005 Tuesday, Topic: Graph Wrapup CS302

  2. 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 together) � Sally Fields has Bacon number (she was in Forrest Gump with Hanks, who was in Apollo 13 Kevin Bacon with Bacon) � Question: � How do you find an actor’s Bacon number?

  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

  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?

  5. Crazy Football Rankings (con’t.) � Answer: � Vertex = team AL � Edge (u,v) � team u defeated v � Given X, Y, find path from X FL to Y (or Y to X). UT LSU Vandy

  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

  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 flood bleed blood bland breed blend blond

  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 300 Z’s buys 100 X’s, X 1 0.5 1/ 3 which will buy 200 Y’s, which will buy 400 Z’s Y 2 1 0.5 � Made 100 Z’s just Z 3 2 1 through exchanges

  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 0.48 Z � Note: -0.48 X 0.3 ∏ = -0.3 multiplication of exchange rates r 0.3 i i But, when finding paths, we add costs. -0.3 Y So, convert to form that works when adding costs: ∑ ∏ = ⇒ log( r ) (log ) r each edge is the log of the exchange rate i i i i

  10. Team competition � Winning team: 10 points homework extra credit � Losing team: 3 points homework extra credit

  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: v2 v0 v1 v4 v6 v3 v5 Answer: v0 v1 v3 v5 v6 v4 v2

  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: v2 v0 v1 v4 v6 v3 v5 Answer: v0 v1 v4 v3 v5 v6 v2

  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

  14. (4) Topological Sort � Give a topological sort of the following graph: v2 v0 v1 v4 v6 v3 v5 Some possible answers: v2 v0 v4 v1 v3 v6 v5 v2 v0 v1 v3 v6 v5 v4 v2 v0 v1 v3 v4 v5 v6

  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

  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

  17. � How many spanning trees does the following F E D A C (7) Spanning trees B graph have? Answer: a a) 4 b) 8 c) 3 d) 6

  18. (8) Kruskal’s algorithm � Using Kruskal’s algorithm which edge should we choose second? a) CD 10 A b) AB 25 c) AC E 15 d) BD B 8 30 5 18 11 22 C D 20 Answer: c

  19. (9) Kruskal’s algorithm � Using Kruskal’s algorithm which edge should we choose third? a) AC 10 A b) CD 25 c) AB E 15 d) BD B 8 30 5 18 11 22 C D 20 Answer: d

  20. � Which of the following are trees? Answer: Graphs 1 and 3 (10) Trees

  21. (11) Network Flow � What is the value of the maximum flow in the following graph? s 3 2 1 B F 3 1 4 E C 2 3 Answer: 4 t

  22. (12) Dijkstra’s algorithm � Below is an intermediate stage of Dijkstra’s 2 algorithm operating on v2 v1 this graph. � What is the next vertex 1 10 4 3 selected? Known? 2 2 p v d v v3 v4 v5 v1 T 0 0 4 8 v2 F 2 v1 5 6 v3 F 3 v4 v4 T 1 v1 v7 v6 v5 F 3 v4 1 v6 F 9 v4 v7 F 5 v4 Answer: v2

  23. (13) Dijkstra’s algorithm � Assume v2 has been selected for processing by 2 Dijkstra’s algorithm. v2 v1 � What are the changes to 1 10 the d v column? 4 3 Known? 2 2 p v d v v3 v4 v5 v1 T 0 0 4 8 v2 F 2 v1 5 6 v3 F 3 v4 v4 T 1 v1 v7 v6 v5 F 3 v4 1 v6 F 9 v4 v7 F 5 v4 Answer: no changes made

  24. � Name all the articulation points of this graph K J (14) Articulation points H I Answer: C, E, F E G F B C D A

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend