educative.io

Should we first create a adjacency list?

Its usually easier to traverse if graph is stored in an adjacency list.
why we dont use that approach? is it less efficient for binary tree?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Binary Tree Level Order Traversal (easy) - Grokking the Coding Interview: Patterns for Coding Questions

Hi @bee1

Since it’s a binary tree, so we need to add all the nodes according to the definition of the binary tree. The method used is preferred as the problem is to traverse the nodes level by level.