In this article, we will discuss how to print nodes at k distance from the root of a binary tree. The trees are hierarchical data structures unlike Arrays, Linked Lists, Stack and queues, which are linear data structures. In the tree, the topmost node is known as the root of the tree. Other elements that are directly under an element are called its children. The element directly above something is called its parent. Let’s see the following diagram of the binary tree data structure: Let’s see the tree node representation in Java code like the following: In previous
The post Print nodes at k distance from the root appeared first on Dinesh on Java.