Level Order Tree Traversal in F#

Another common problem I see during my preparation for technical interviews is the Level Order Tree Traversal (or Breadth-First) problem.

I always like to think with my F# hat on when I solve algorithm problem, so here’s an implementation in F# .

Here we have a nested recursive loop function that:

  • yields the value from the nodes on the current level
  • then find all the children of the nodes on the current level and recurse with them


Try it Yourself



Yan Cui

I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.

You can contact me via Email, Twitter and LinkedIn.

Hire me.