menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Display no...
source image

Prodevelopertutorial

1w

read

342

img
dot

Image Credit: Prodevelopertutorial

Display nodes at given level in Binary Tree

  • Given a binary tree root node and a level, display all the nodes present in that level.
  • Example:
  • Nodes at level 1 are : 16
  • Nodes at level 2 are : 10, 25
  • Nodes at level 3 are : 7, 15, 18, 30
  • Solution: This problem can be solved by recursive traversal.
  • If the level is 1, print the node value.
  • Recursively call the function for the left and right nodes with level reduced by 1.
  • C++ code example provided to demonstrate the solution.
  • Output: Nodes at level 2 are 10, 25

Read Full Article

like

20 Likes

For uninterrupted reading, download the app