Breadth-first search is an algorithm for finding (or traversing) graph data structures. You start at the root and explore the branch as wide as possible before going back (also called backtracking).
Let’s consider the next graph:
While finding I, algorithm will start with A and go as wide as possible and go to the next node:
BFS written in Ruby: