Complexity of Treemap insertion vs HashMap insertion

前端 未结 4 1330
北海茫月
北海茫月 2021-02-05 10:08

I am confused with the time complexity of these two algorithms.

//time complexity O(nlog(n))
public void usingTreeMap(){
    Map map = ne         


        
4条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 10:22

    Is the time complexity to the usingTreeMap algorithm correct.

    The time complexities of the basic TreeMap operations are specified correctly in the Javadoc.

    I do know in treemap the insertion time is log(n)

    Correct.

    but if we iterate over an array of 10 elements does it become nlog(n).

    If this means inserting those 10 elements the time complexity is M*log(N) where M is the size of the array and N is the size of the TreeMap. If it doesn't mean that, the question is unclear.

提交回复
热议问题