19

Are they AVL trees, red-black trees, or something else?

Craig P. Motlin
  • 26,452
  • 17
  • 99
  • 126

5 Answers5

26

Red-black trees as described in the first line of the javadoc.

John R Perry
  • 3,916
  • 2
  • 38
  • 62
Kru
  • 4,195
  • 24
  • 31
23

From the java.util.TreeMap<K,V> documentation:

A Red-Black tree based NavigableMap implementation.

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:

Related questions

Community
  • 1
  • 1
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
5

It is a red-black tree in the Oracle desktop Java implementation, but an AVL-tree in Android.

WonderCsabo
  • 11,947
  • 13
  • 63
  • 105
5

The first sentence of the TreeMap Javadoc states:

A Red-Black tree based NavigableMap implementation.

matt b
  • 138,234
  • 66
  • 282
  • 345
-5

TreeSet is based on TreeMap. And they uses red-black tree, red-black tree is a kind of AVL.

卢声远 Shengyuan Lu
  • 31,208
  • 22
  • 85
  • 130