This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

depth of a binary tree ?

 
kri shan
Ranch Hand
Posts: 1472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21385
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am planning to use LinkedList. Is it right approach ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic