- 1. (8 points) Consider the weighted graph below:
(a) Demonstrate Prim’s algorithm starting from vertex A. Write the edges in the order they were added
to the minimum spanning tree.
(b) If each edge weight is increased by 1 will this change the minimum spanning tree? Explain.
- 2. (7 points) A region contains a number of towns connected by road Each road is labeled by the average number of minutes required for a fire engine to travel to it. Each intersection is labeled with a circle. Suppose that you work for a city that has decided to place a fire station at location G. (While this problem is small, you want to devise a method to solve much larger problems).
(a) What algorithm would you recommend be used to find the fastest route from the fire station to each of the intersections? Demonstrate how it would work on the example above if the fire station is placed at G. Show the resulting routes and times.
(b) Suppose one ”optimal” location (maybe instead of G) must be selected for the fire station such that it minimizes the time to the farthest intersection. Devise an algorithm to solve this problem given an arbitrary road map. Analyze the running time complexity of your algorithm when there are f possible locations for the fire station (which must be at one of the intersections) and r possible roads.
(c) In the above graph what is the “optimal” location to place the fire station? Explain.
- 3. (15 points) Suppose there are two types of professional wrestlers: “Babyfaces” (“good guys”) and “Heels” (“bad guys”). Between any pair of professional wrestlers, there may or may not be a rivalry. Suppose we have n wrestlers and we have a list of r pairs of rivalrie
(a) Give pseudocode for an efficient algorithm that determines whether it is possible to designate some of the wrestlers as Babyfaces and the remainder as Heels such that each rivalry is between a Babyface and a Heel. If it is possible to perform such a designation, your algorithm should produce it.
(b) What is the running time of your algorithm?
(c) Implement: Babyfaces vs Heels in C, C++ or Python. Name your program wrestler and include compile and executions instructions in the README file.
Input: Input is read in from a file specified in the command line at run time. The file contains the number of wrestlers, n, followed by their names, the number of rivalries r and rivalries listed in pairs. Note: The file only contains one list of rivalries
Output: Results are outputted to the terminal.
- Yes, if possible followed by a list of the Babyface wrestlers and a list of the Heels.
- No, if impossible.
Sample Input file:
Ace Duke Jax Biggs Stone
Ace Duke Ace Biggs Jax Duke Stone Biggs Stone Duke Biggs Jax
Babyfaces: Ace Jax Stone
Heels: Biggs Duke
Note: There can be alternative solutions. For consistency assign the first wrestler in the list to be a
Submit a copy of your files including a README file that explains how to compile and run your code in a ZIP file to TEACH.