Member-only story

JavaScript Coding Problem: Binary Tree Level Order Traversal

Kavit (zenwraight)
4 min readJul 9, 2020

--

Problem Statement

Given a binary tree, return the bottom-up level order traversal of its nodes values. (ie, from left to right, level by level from leaf to root).

For example: Given Below binary tree

the output should be

Problem Explanation

Basically the problem asks us to perform a binary tree traversal and at each level for the tree, print the values of the nodes from left to right direction and the order should be bottom to top.

So, if we look at the above problem, we have -

(i) node 15 and 7 at level 2

(ii)node 9 and 20 at level 1

and node 3 at level 0

so, we return in the bottom top manner, from left to right.

Algorithm

Let’s jump into the main crux of the logic and see how we can solve it.

We will be using two major data structures:-

(i) Map - Store Key as level and value as array of node values at that…

--

--

Kavit (zenwraight)
Kavit (zenwraight)

No responses yet