VOOZH about

URL: https://www.geeksforgeeks.org/dsa/print-left-view-binary-tree/

⇱ Left View of a Binary Tree - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Left View of a Binary Tree

Last Updated : 7 Oct, 2025

Given the root of a binary tree, Find its left view.

The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side.

  • It contains the leftmost node at each level, starting from the root (top level) down to the deepest level.
  • Return the nodes in order from the top level to the bottom level.

Examples

Input:

👁 binary_tree_to_string_with_brackets

Output: [1, 2, 4, 7]
Explanation: From the left side of the tree, only the nodes 1, 2, 4 and 7 are visible.

👁 file

Input:

👁 420046674


Output: [1, 2, 4, 5]
Explanation: The first node from each level will be the part of left view of tree.

👁 420046675

[Approach - 1] Using Depth-first search (DFS) - O(n) Time and O(n) Space

The idea is to use DFS and Keep track of current level. For every level of the binary tree, the first node we see from the left side is part of the left view.


Output
1 2 4 5 

[Approach - 2] Using Level Order Traversal (BFS) - O(n) Time and O(n) Space

The left view contains all nodes that are the first nodes in their levels. A simple solution is to do level order traversal and print the first node in every level.


Output
1 2 4 5 
Comment