Breadth First Search vs. Depth First Search

I graduated from my coding immersive at Grace Hopper Fullstack Academy and am reviewing some data structures and algorithms for interviews. I’ll be posting about some topics here to keep track of my progress and hopefully it will be helpful if you’re learning how to code also! Any tips would also be appreciated :)

Source: https://hamzic.files.wordpress.com/2016/12/fig1.gif?w=630&h=192&crop=1

A) Depth First (by Branch)

  • Pre-Order: Process Root, Left Subtree, Right Subtree
  • In-Order: Process Left Subtree, Root Node, Right Subtree
  • Post-Order: Process Left Subtree, Right Subtree, Root Node

B) Breadth First (by Level)

  • Use a queue!

Resource:

https://visualgo.net/dfsbfs