How to find all subtrees, given a Linked binary tree in java, or even a regular binary tree? -
I had to face an interview question, for which I find a method to find all the sub-bits within a binary tree Needless to say I was unable to understand it, how would I have to answer this question? Is it an easy way to use repetition? Should I go to the list?
{Private Object Data; Private node & lieutenant; Object & gt; Left ; Private node & lieutenant; Object & gt; right ; Public node () {this (empty, empty, empty); } Public Node (Object D, Node & Lt; Object & gt; L, Node & L; Object & gt; R) {Data = D; Left = L; True = r; } Public object getData () {return data; } Public Zero Set Data (Object D) {Data = D; } Public node & lieutenant; Object & gt; GetLeft () {return left; } Public node & lieutenant; Object & gt; GetRight () {Return correct; } Public Zero Set Lift (node node) {left = node; } Public Zero setRight (node node) {true = node; }} Any advice is appreciated! public class node & lieutenant; Object & gt; Any advice is highly appreciated!
Depending on the meaning of "searching" what is the meaning in each node, therefore Finding or calculating them for finding all the nodes must be enough for your choice of the first before the fourth or fourth quarter of the depth of the paste.
If the "sub-category" is to be detected by a particular person or something to do with it, then it can make one of those two traversals, more appropriate strategy than the other.
Comments
Post a Comment