For a description of the Kevin Bacon game, follow this occasionally unreliable link or look at Exercise 14.23 in the text. Try the game a few times and see if you can find someone with a Bacon Number higher than 3. In this assignment, you will find all persons with a Bacon Number of 8 or higher.
This is basically a shortest path problem. After that is done, find the large Bacon numbers by scanning the bacon numbers and print out the high-numbered actors and their chains. To print out a high-numbered actor, you should use recursion. Specifically, if some actor x has a Bacon number of b, then you know that they must have been in a movie with someone, call them actor y with a Bacon number of b-1. To print out x's chain, you would print out y's chain (recursively) and then the movie that x and y had in common.
The datafile contains approximately 1,171,600 actors/actresses in a total of 331,500 movies, with 3,925,000 roles. Because of the large data, you may need to increase the Virtual Machine size depending on your current defaults. You may use up to 400Mbytes. You may not increase it any higher than that. If you are running the java interpreter from the command line, the magic option is -Xmx400m. If you are using an IDE, you will have to consult their documentation --- don't ask me.
Runtime rt = Runtime.getRuntime( ); int vmsize = (int) rt.totalMemory( ); System.out.println( "Virtual machine size: " + vmsize );You cannot receive credit for a working program if your program fails to produce a large set of actors and actresses with Bacon Numbers of 8 or higher. Note: the data you will work on and the data the Oracle uses (and the IMDB data) are all slightly out of sync. So you might not be able to exactly reproduce the results, but it is definitely the case that some of the people your program will produce do indeed have a Bacon number of 8 according to the Oracle.
// typically invoked with "Bacon, Kevin" as parameter // Returns a map in which keys are names of the actors, // values are their bacon numbers public Map<String,Integer> computeBaconNumbers( String centralActor ) { MAINTAIN A QUEUE MAINTAIN A MAP TO STORE AND RETURN BACON NUMBERS MAINTAIN A SET TO AVOID LOOKING AT A MOVIE TWICE enqueue the central actor set the central actor's number to 0 while the queue is not empty { Remove an actor (the current actor), from the queue for each movie m in which the current actor has a role { if movie m has already been looked at continue for each Actor, otherActor who appeared in m { if otherActor does not yet have a Bacon number { set otherActor's Bacon number to current's Bacon number + 1; enqueue the otherActor } } } } return the map }