Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

Given the binary tree create linked lists of the nodes at the same level

Problem description :

Convert a given binary tree to a linked list of all the nodes at each depth (if you have a binary tree with depth D, you’ll have D linked lists).

Logic :

  • Modify the pre-order traversal algorithm by passing an extra argument of the current height (level) + 1

This post is a follow-up of
JavaScript Linked List Example
Create a binary search tree in javascript
Binary tree traversal.
I recommend reading those posts first, as the following code uses the method from it.

Solution :

  • CTCI_6_4.3

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *