Forums Register Login

depth of a binary tree ?

+Pie Number of slices to send: Send
Arrays.binarySearch(int[], key) gives Searches the specified array of the specified value using the binary search algorithm. How to find the depth of a binary tree based on key or value of any node.
+Pie Number of slices to send: Send
 

kri shan wrote:Arrays.binarySearch(int[], key) gives Searches the specified array of the specified value using the binary search algorithm. How to find the depth of a binary tree based on key or value of any node.



The Arrays.binarySearch() method searches arrays -- there isn't any binary tree, and hence, no "depth" to speak of. Now, if you meant, how many iterations before the element is found, I don't think you can get that data. It just returns where it is found, and where between, if not found.

Henry
+Pie Number of slices to send: Send
depthBinarySearch(root node, Element )
Element is left node / right node element needs depth of the binary search tree.
Start from the root node, compare each right node / left node and add counter increment until find the element. Is it right approach ?
+Pie Number of slices to send: Send
I am planning to use LinkedList. Is it right approach ?
+Pie Number of slices to send: Send
 

kri shan wrote:
Start from the root node, compare each right node / left node and add counter increment until find the element. Is it right approach ?


Correct! .

kri shan wrote:
I am planning to use LinkedList. Is it right approach ?


you are on right path. LinkedList data structure is the basic to implement Tree.
You can thank my dental hygienist for my untimely aliveness. So tiny:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3753 times.
Similar Threads
Trees
Understanding HashMap
Heap sort.
Binary Tree Forumula
Find Binary Tree Height with O(n/2)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:10:05.