aspose file tools
The moose likes Beginning Java and the fly likes depth of a binary tree ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "depth of a binary tree ?" Watch "depth of a binary tree ?" New topic
Author

depth of a binary tree ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1300
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.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16680
    
  19

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
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1300
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 ?
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1300
I am planning to use LinkedList. Is it right approach ?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: depth of a binary tree ?
 
Similar Threads
Understanding HashMap
Binary Tree Forumula
Heap sort.
Find Binary Tree Height with O(n/2)
Trees