Skip to main content

Posts

Showing posts with the label The Crazy Programmer Left View of Binary Tree in Java Left View of Binary Tree in Java The Crazy Programmer

Left View of Binary Tree in Java Vijay Sinha The Crazy Programmer

In this article, we look into a problem related to binary tree. Given a binary tree, we have to print its Left View. We will see the different methods to solve this problem with their implementations in java. Along with this, we will also look into the time and space complexities of our methods. By left of binary tree, we mean the nodes visible to us when the tree is visited from the left side starting from the root. In other words, the nodes which are present at the starting of each level in a binary tree. Also Read: Right View of Binary Tree in Java Let us consider this binary tree:   The left view of above binary tree will give output: 1 2 4 7. The nodes are highlighted in the figure. We start from the root node 1 at level 1 then we go down each level printing the first node encountered. At level 2 node 2 is the first node so print it, at level 3 node 4 and at the last level 4 node 7 is the only node. Note: If a level contains only one node then that node is a part of Lef