aspose file tools*
The moose likes Beginning Java and the fly likes java's TreeMap implementation - Algorithm ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Watch "java New topic
Author

java's TreeMap implementation - Algorithm ?

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1376
Whether java's TreeMap implementation is Binary Search Tree Algorithm ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40


The javadoc (actually reachable from your post) actually talks about the implementation. In fact, it is mentioned right in the beginning.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1376
As per the java doc
Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's Introduction to Algorithms.
. I do not see binary search algorithm.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14157
    
  19

If you want to know all the details, then you can lookup the source code for class TreeMap. In your JDK installation directory, there is a file named src.zip. In there you will find the source code for all the standard Java API classes, including the source code for java.util.TreeMap.

As the documentation says, it is implemented with a red-black tree. And Wikipedia says:
A red-black tree is a binary search tree where each node has a color attribute, the value of which is either red or black. In addition to the ordinary requirements imposed on binary search trees, the following additional requirements apply to red-black trees: ...


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40

kri shan wrote:As per the java doc
Algorithms are adaptations of those in Cormen, Leiserson, and Rivest's Introduction to Algorithms.
. I do not see binary search algorithm.


As already mentioned by Jesper; it is mentioned in the JavaDoc in the very first sentence,

A Red-Black tree based NavigableMap implementation.


Henry
 
wood burning stoves
 
subject: java's TreeMap implementation - Algorithm ?