Coding Challenge #68.1: Breadth-First Search Part 1

In this two part challenge, I cover the Breadth-First Search algorithm is and implement it in JavaScript. My demo application is “6 Degrees of Kevin Bacon” (finding the closest relationship between Kevin Bacon and another actor). This challenge is part of the spring 2017 ITP “Intelligence and Learning” course (

Part 2:

Support this channel on Patreon:
To buy Coding Train merchandise:

Send me your questions and coding challenges!:

The Coding Train website:

Links discussed in this video:
The Nature of Code Part 2 (Spring 2017) – Intelligence and Learning:
Nature of Code:
My Video on Prototypes:
My Video on Associative Arrays:
The Oracle of Bacon:
Breadth-First Search on Wikipedia:

Books and Papers:
Grokking Algorithms book:

Source Code for the all Video Lessons:


For More Coding Challenges:
For an Intro to Programming using p5.js:

Help us caption & translate this video!






39 responses to “Coding Challenge #68.1: Breadth-First Search Part 1”

  1. David Li Avatar

    This was the most entertaining video I've ever watched

  2. Jackson Rollins Avatar

    Lol you forgot the correct method declaration on node.js:9 @ 16:44 but when you switched back to the file @ 18:37 it was magically fixed! Nice try Mister Coding Train ( ;

  3. ashish rawat Avatar

    which application you are using so that i can start immediately pls help

  4. Rukshar Alam Avatar

    I have used BFS to determine graph connectivity in Java. Check out the description and the solution 馃檪 !!!

  5. Ryac de Barros Avatar

    Hi. Just want to say I love you and do you do live streams? If so when and where? I would love to watch you live but I don't get any notifications and stuff so please help me out anyone?

  6. Algorhythm Avatar

    Hey Daniel!

    Thank for these amazing videos. I love your enthusiasm. I need that in order to learn. Almost done with my CS degree but its great to see these implementations. I just bought the book Grokking Algorithms that you mentioned. Cannot wait to read it. Thank you for these videos. I'm excited to watch the rest of the series!

    Jose Ortiz

  7. 谞讚讘 讜讜讬住 Avatar

    In sketch.js: graph.addNode should be inside the if

  8. Ahmed saidi Avatar

    Hi Daniel i know it is not the same subject i have problem with a json file that i cannot display it in js..the json file is
    "a": {
    "a-simple": {
    "6222": {
    "id": 6222,
    "id1": 112,
    "id2": 1,
    "text": " text1"
    "6223": {
    "id": 6223,
    "id1": 112,
    "id2": 2,
    how i can point to text..i cannot do a.a-simple."6222".text not acceptable
    any help pls

  9. SC K Avatar

    Shiffman => use some webpack and es6 style of classes or typescript etc … it's more fun than raw vanilla js

  10. Ajani Bilby Avatar

    This video came out on the day I handed in an assignment of which did a degrees of separation for wikipedia XD

    Shameless promotion :p >

  11. MintyPlays Avatar

    1:08 did Alice just move?

  12. beenbeen Avatar

    Breath-first VS. Death-first

  13. Connor Nicholls Avatar

    are you sure the kevin bacon website uses breadth first, and not dijkstra's algorithm?

  14. Andr谩s Gyarmati Avatar

    google also gives you bacon numbers 馃榾

  15. MaCH Avatar

    you remind me of mat from achievement hunter XD

  16. Daniel Boa Avatar

    My copy of Grokking Algorithms is in the mail, looking forward to it!

  17. PsyNeur Avatar

    common use some ES6 features. I want to see class {} notation!

  18. Tymski Avatar

    I recently started using js's object oriented programming features and i like it. You can do sth like this:
    class Node {
    this.value = something;
    node = new Node(value)

  19. Ibakon Ferba Avatar

    The inventor of the gif format himself pronounces it jif, so it's jif

  20. Yanick Rochon Avatar

    At 19:16, you can simply write : if (!actorNode) { … } It is not only the JavaScript-way of testing "truthy" values, it prevents the case where null !== undefined. (Also, === is preferred to == because JavaScript's loose type syntax (ex: 0 == '' is true, but 0 === '' is false)

  21. Bastiaan van der Laaken Avatar

    Just a random thank you… Both your enthusiasm & teaching methodology make a world of difference to learning many of these concepts. It truly is addictive…

  22. Yanick Rochon Avatar

    Again, at 18:30, you need to put line 27 inside the condition block. Because Graph.addNode does two things, push the node to nodes and add it to the set. While the latter makes no difference if the node is added twice, the former will create duplicates within the nodes array.

  23. Taras Zakrevskiy Avatar

    you picked quite complicated example with movies and actors. Would be much easier to explain BFS with a simpler nodes ( say a subway stations ) IMHO. Still like your videos, and thanks for your time recording them!

  24. lorenzM Avatar

    can u maybe in your intellegence and learing or as a coding challenge do a simulation of an ecosystem? maybe with a genetic algorithm or some kind of other algorithm i dont know yet, that u can teach in the video 馃檪 also thanks for all the things i learned through you


    Can you do a video on dynamic programming?

  26. Harshit Dubey Avatar

    Google also has this "easter egg" where you can search for "Bacon number" followed by the actor's name for similar results.

  27. Jacob JG Avatar

    I don't know if this has happened before but this is the first time I've noticed it. Your hair slightly transparent and it keeps putting me off xD

  28. Subhojit Mondal Avatar

    hey can you please make some great "create js" tutorials as you made p5.js tutorials (those videos is very helpful and awesome)

  29. Burak Temizel Avatar

    You are an artist. Best artist 馃槢

  30. Archit Naik Avatar

    I love Your Videos A lot specially coz of regular uploads!!

  31. Nola1222 Avatar

    What did you study?

  32. Matt Churchyard Avatar

    I guess this stuff has already been fixed but you don't need to add the actor node to the graph if it's returned by getNode. Also calling the argument in getNode 'actor' is a bit ugly as that object can be used to store anything, not just actors. Something like 'key' would make more sense.

  33. Jaiveer Avatar

    you're not stiffman Daniel you are stuff man

  34. CSRocks Avatar

    great content as always!

  35. CyberD Avatar

    What is the name of the book and the author?

  36. Dan P Avatar

    I love watching these even though I'm absolutely terrible at programming, most if not all of it is jibberish to me 馃榾

  37. Tre Turner Design Avatar

    Love these videos! By the way, what color theme do you use for your Atom editor? It is very pleasing to the eye holes.

Leave a Reply

Your email address will not be published. Required fields are marked *