Binary tree - balanced binary search tree TreeSet, TreeMap

The bottom layer of TreeSet and TreeMap in java is a red- black tree

The operation of accessing elements internally is O(logN), while ordinary HashMap accessing elements is O(1)

However, the internal elements of TreeSet and TreeMap are sorted . When you need to find elements of certain sizes and output elements in order, the results are ideal.

TreeMap is a sorted version of HashMap of internal elements

TreeSet is implemented by encapsulating HashSet member variables

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325258381&siteId=291194637