menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Print the ...
source image

Prodevelopertutorial

1M

read

384

img
dot

Image Credit: Prodevelopertutorial

Print the nodes at k distance from the root of a binary tree

  • To print all the nodes that are k distance from root, we can use recursive approach.
  • The base cases are when the node becomes null or the k value becomes 0.
  • We make a recursive call to both the left and right child, decrementing the k value.
  • The recursion tree shows the process for k = 2.

Read Full Article

like

23 Likes

For uninterrupted reading, download the app