Are they AVL trees, red-black trees, or something else?
Asked
Active
Viewed 1.7k times
19
-
10It's the second and third words in the JavaDocs. – Steve Kuo Aug 27 '10 at 03:47
5 Answers
23
From the java.util.TreeMap<K,V> documentation:
A Red-Black tree based
NavigableMapimplementation.
For questions like these, you should always first consult the documentation. The API shouldn't describe ALL of the inner-workings of a class, but elementary informations such as general data structures and algorithms used are usually documented.
Other Java Collections Framework trivias
These are all little trivias that are also clearly documented:
TreeSetis implemented with aTreeMapHashSetis implemented with aHashMapCollections.sortuses modified mergesortMap<K,V>is not aCollection<?>ArrayListdoesn't specify exact growth policy (unlike, say,Vector)
Related questions
Community
- 1
- 1
polygenelubricants
- 364,035
- 124
- 554
- 617
5
It is a red-black tree in the Oracle desktop Java implementation, but an AVL-tree in Android.
WonderCsabo
- 11,731
- 13
- 60
- 105
5
The first sentence of the TreeMap Javadoc states:
A Red-Black tree based
NavigableMapimplementation.
matt b
- 135,500
- 64
- 278
- 339
-5
TreeSet is based on TreeMap. And they uses red-black tree, red-black tree is a kind of AVL.
卢声远 Shengyuan Lu
- 30,386
- 22
- 82
- 125