How far is any actor from the Marvel Cinematic Universe?
Search an actor and discover their path to the MCU.
The idea that any two people on Earth are connected through at most six acquaintances.
Originally based on the actor Kevin Bacon, the parlor game challenges players to connect any actor to Bacon through shared movie appearances. Each shared movie counts as one "degree" of separation.
We replace Kevin Bacon with the entire MCU ensemble. Instead of connecting to one actor, we find the shortest path from any actor to any of the 30+ core MCU cast members — Iron Man, Captain America, Thor, and beyond.
Mathematically, this is a shortest-path problem in a bipartite graph. Actors and movies form nodes, and "appeared in" forms edges. We use Breadth-First Search (BFS) to find the minimum number of hops.
This example shows a 2-degree connection: Actor → Movie → Actor → Movie → MCU Actor
A step-by-step breakdown of the Breadth-First Search algorithm that powers every connection discovery.
You type an actor's name and we query the TMDB API (/search/person) in real-time. Results appear with autocomplete as you type.
TMDB API → /search/person?query={name}Before running the algorithm, we check PostgreSQL for a cached result. If this actor was searched before, we return the result instantly.
SELECT * FROM cached_paths WHERE source_actor_id = ?We load the 30+ MCU seed actors as our target set. The search actor becomes the root of our BFS tree. We initialize the visited set.
Queue = [sourceActor], Visited = {sourceActor}, Targets = MCU_SETFor each actor in the current BFS level, we fetch their movie credits from TMDB. We examine the top 15 movies sorted by cast billing order.
TMDB API → /person/{id}/movie_creditsFor each movie, we get the full cast list. We check each co-star: are they in the MCU set? If YES → path found! If NO → add to next BFS level.
TMDB API → /movie/{id}/credits → Check cast ∩ MCU_SETOnce a connection is found, we build the full path, generate graph data for visualization, cache the result in PostgreSQL, and return it.
INSERT INTO cached_paths (path_data) → Return GraphDataTime Complexity: O(bd) where b = branching factor (co-stars per movie × movies per actor) and d = depth.
Space Complexity: O(bd) for the visited set. Cached results return in O(1).