book-notes

Chapter 6 - Breadth-first search (BFS)

Graphs

Breadth-first search (BFS)

It helps answer 2 types of questions

  1. Is there a path from node A to node B?
  2. what is the short path from node A to node B?

Queues

Implementing the graph

Implementing the algorithm

Screen Shot 2022-07-12 at 2.03.40 PM.png

  1. Keep a queue containg the people to check
  2. pop a person off the queue
  3. check if this perons is a mango seller
    1. if yes, you are done!
    2. if no, add all their neighbors to the queue
  4. loop back to step2
  5. if the queue is empty, there are no mango sellers in your networks

Running time

Recap

Leetcode

trees