In this article we will discuss the approach to find out the nodes at k distance from the given node.
Let us assume we have a binary tree. Let the node given to us be 'Target Node'. Now, we need to find all nodes at distance k from 'Target Node'. Those k nodes could be parent as well as child nodes of the 'Target Node'.
Below is the code that represents the implementation of the Tree:
class Tree{ int value; Tree right; Tree left;}
We can follow two major techniques:
1. Breadth Fir...
Published on February 28, 2021 12:57