Skip to content

(BFS) Breadth First Search Algorithm to determine degrees of separation between two actors

Notifications You must be signed in to change notification settings

vuurball/ai-0-bfs-degrees

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BFS algorithm implementation

we’re interested in finding the shortest path between any two actors by choosing a sequence of movies that connects them. For example, the shortest path between Jennifer Lawrence and Tom Hanks is 2: Jennifer Lawrence is connected to Kevin Bacon by both starring in “X-Men: First Class,” and Kevin Bacon is connected to Tom Hanks by both starring in “Apollo 13.”

We can frame this as a search problem: our states are people. Our actions are movies, which take us from one actor to another (it’s true that a movie could take us to multiple different actors, but that’s okay for this problem). Our initial state and goal state are defined by the two people we’re trying to connect. By using breadth-first search, we can find the shortest path from one actor to another.

  • using StackFrontier() instead of QueueFrontier() will switch to Depth-First-Search, however it is not optimal in solving this problem

About

(BFS) Breadth First Search Algorithm to determine degrees of separation between two actors

Topics

Resources

Stars

Watchers

Forks

Languages