The purpose of this assignment is to practice your understanding of graphs as well as various graph manipulations and algorithms.
You are not required to watch Avengers: Infinity War to understand the assignment.
How are the Infinity War assignment files structured?
The assignment consists of the following files:
The following graph creator tool is very helpful in visualizing test cases and debugging your code!
Executing and Debugging:
Implementation Details:
StdIn, StdOut, and StdRandom:
Java Collections Data Structures:
In the MCU (Marvel Cinematic Universe), right after the Big Bang occurred there were 6 singularities contained within Infinity Stones that were spread across the infant universe.
Infinity Stones:Before the events of Avengers: Infinity War, a titan named Thanos witnessed the death of his home planet due to overpopulation. Reeling from his experience, Thanos made it his life mission to exterminate half of all life in the universe to delay overpopulation on other worlds like his.
Thanos determined that using the 6 Infinity Stones which he could hold in his Infinity Gauntlet, a simple snap of his fingers would painlessly eliminate 50% of all life, and he can finally rest in peace victorious.
Locations:
Main Avengers:
Gaurdians of the Galaxy:
Other Characters:
MLA Citation for Algorithms, 4th ed., which was used for StdIn, StdOut, and StdRandom:
Sedgewick, Robert, and Kevin Wayne. Algorithms, 4th ed., Addison-Wesley Professional, 2011. Web.
MLA Citation for MCU:
"Marvel Cinematic Universe." Marvel Studios, LLC, 2023.
MLA Citation for Avengers: Infinity War:
Russo, Anthony, director. Avengers: Infinity War. Marvel Studios, 2018.
MLA Citation for Marvel Entertainment:
Marvel Entertainment, LLC, 2023.
MLA Citation for Marvel Studios:
Marvel Studios, LLC, 2023.
MLA Citation for Marvel Website:
"Marvel.com | The Official Site for Marvel Movies, Characters, Comics, TV" Marvel Entertainment, LLC, 2023, https://www.marvel.com/. Accessed 04 Dec 2023.
MLA Citation for Disney Website:
"The Walt Disney Company." The Walt Disney Company, Disney, 2023, www.thewaltdisneycompany.com.
MLA Citation for Marvel Universe Entertainment Youtube Channel (used for video clips):
"Marvel Universe Entertainment." YouTube, YouTube, 04 Dec 2023, www.youtube.com/@Marvel-Universe-Entertainment.
MLA Citation for Wikipedia Page for the MCU:
"Marvel Cinematic Universe." Wikipedia, Wikimedia Foundation, 04 Dec. 2023, en.wikipedia.org/wiki/Marvel_Cinematic_Universe.
MLA Citation for Marvel Fandom Wikipedia:
Marvel Cinematic Universe Wiki." Fandom, 04 Dec. 2023, marvelcinematicuniverse.fandom.com.
Steps for this task:
Example:
Preconditions
A defeated Hulk is sent to NYC to warn Dr. Strange and Iron Man about the impending arrival of Thanos and his army (the Black Order) to retrieve the Time Stone.
His ship arrives soon and a battle ensues as Iron Man, Spiderman, and Dr. Strange battles Ebony Maw and Cull Obsidian (two of Thanos’ “children”).
After Cull Obsidian dies, Dr. Strange is captured onto Maw’s ship, and Iron Man and Spiderman latch onto it as it departs Earth.
Iron Man blows a hole in the ship and Maw is shot into space.
Meanwhile, the Guardians of the Galaxy (hereby referred to as “Guardians”) rescue Thor and the group splits, where Thor, Rocket, and Groot (a tree-human hybrid) go to Nidavellir to forge Thor’s Stormbreaker, a weapon capable of destroying Thanos.
To forge the Stormbreaker, Thor has to endure the power of a Neutron Star near Nidavellir. The star’s plasma rushes through the opening that Thor is inside, as depicted in the image below.
Fig. 1. Screenshot from Avengers: Infinity War, directed by Anthony Russo and Joe Russo, 2018
In physics, flux is defined as the amount of fluid (or field strength) flowing through an area.
In the image above, the box with the matrix of numbers shows the flux intensity of the sun’s plasma through the opening that Thor is inside. Taking the sum of all the numbers reveals the total flux of the plasma through the opening.
Thus, the flux would be (3 + 4 + 5 + 1 + 2) + (12 - 1 + 7 + 2 + 8) + (11 - 6 + 3 + 5 + 2) = 58.
Task: given a 2D array where the values are the flux intensity data of the Neutron Star, calculate the total flux that Thor has to endure. Write this number into the output file.
Steps for the task:
Example:
Pseudocode for Dijkstra's:
Preconditions:
Meanwhile, the Guardians who did not go to Nidavellir (basically Peter Quill, Gamora, Drax, and Mantis) head to Knowhere to prevent Thanos from acquiring the Reality Stone.
However, this fails as Thanos has already gained the Reality Stone and uses it to trick the Guardians into an illusion, and captures Gamora (Thanos’ daughter) since she knows the location of the Soul Stone.
Thanos tortures his daughter Nebula until Gamora reveals that the Soul Stone is in Vormir. Afterwards, Thanos and Gamora depart there while Nebula begs the Guardians to meet her on Titan, Thanos’ homeworld.
After hijacking the Q-ship from Earth, Dr. Strange, Iron Man, and Spider Man decide to go to Titan. In the MCU, interstellar travel happens via wormholes (Einstein-Rosen Bridges).
Fig. 2. Screenshot from Avengers: Infinity War, directed by Anthony Russo and Joe Russo, 2018
Suppose that the route from Earth to Titan can be represented by a Weighted Undirected Graph where the vertices are wormhole generators and the edges are the wormholes themselves. A wormhole is created by two wormhole generators, so the wormhole would be a “path” between these generators.
Some important points:
Division of Energy Costs:
Task: Use Dijkstra's Algorithm to find the minimum cost for a path between Earth (generator #0) and Titan (generator #(n-1)), using the updated energy costs.
Steps for the task:
Example:
Preconditions:
Iron Man, Dr. Strange, and Spiderman arrive at Titan but are ambushed by the Guardians who think they are part of the Black Order. After some tension, they plan to work together to kill Thanos.
Meanwhile, to protect Vision, the Avengers on Earth head to Wakanda, a country in East Africa which has the technology to remove the Mind Stone in Vision’s head without killing him in the process.
A Wakandan named Shuri attempts to figure out how to remove the Mind Stone from Vision’s head.
Fig. 3. Screenshot from Avengers: Infinity War, directed by Anthony Russo and Joe Russo, 2018
Extracting the Mind Stone from Vision without killing him requires the detection of a specific set of neurons that CONNECT to the Mind Stone. Given a Directed Graph that contains vertices (neurons) and edges (synapses), the MindStoneNeighborNeurons method returns a list of neurons that connect to the Mind Stone.
In the brain, cranial nerves usually have dendrites and an axon. A synapse occurs between a dendrite and an axon. The dendrites receive information from other nerves, and the axon transmits information to other nerves. As such, information always flows from dendrites of a nerve, and then into the axon of that nerve. That is why the graph is directed!
For this method, you can assume that the neurons have multiple dendrites and only one axon. You can also assume that a nerve’s axon always connects to ONLY 1 dendrite of another nerve (or it connects to the Mind Stone).
Also, the Mind Stone does not have any axons, but it does receive information from other nerves. As such, the Mind Stone always has an out-degree of 0. Use this to your advantage!
Task: given a Set of Edges representing Vision’s Neural Network, identify all of the vertices that connect to the Mind Stone. List the names of these neurons in the output file.
Steps for the task:
Example:
Preconditions:
Dr. Strange uses his Time Stone to view possible alternate realities.
Fig. 4. Screenshot from Avengers: Infinity War, directed by Anthony Russo and Joe Russo, 2018
Task: First determine the number of possible timelines in the graph, starting from the first event (event 0, in the above example). Print this value into the output file.
Each “event” also has an expected utility (EU) which is a number that shows how “desirable” the event is.
Task: given an input threshold EU value, next determine the number of timelines starting from event 0 where the total EU is GREATER than OR equal to the threshold. Print this value into the output file in a NEW line!
Steps for this task:
Example:
Seed pseudocode:
Preconditions:
Finally, Thanos shows up in Wakanda to take the Mind Stone. Using his Infinity Stones, Thanos easily blocks and incapacitates many of the characters fighting him there including Captain America, Black Panther, and Bruce Banner.
Using all of her power, Wanda destroys the Mind Stone (reluctantly killing Vision in the process) before Thanos reaches her.
However, using the Time Stone, Thanos reversed time until Vision was still alive, and then grabs the Mind Stone in Vision’s head and kills him.
A final attack by Thor has him dig his Strombreaker through Thanos’ chest. However, Thanos snaps his fingers and teleports away, causing half of all life to disintegrate shortly afterward.
Fig. 5. Screenshot from Avengers: Infinity War, directed by Anthony Russo and Joe Russo, 2018
Example - before Snap:
Example - after Snap:
The social network in the example is not connected since person 6 has no way of contacting person 1 and person 3 (since person 4 disappears).
Task: Return a boolean (true or false) which indicates if the graph is still connected after the removal.