Median Medians vs TreeMap

I was wondering if using TreeMapthe array of numbers to get through and getting a sorted result is better than using the Median of Medians algorithm to find the Kth largest element in an unsorted array? Do they work in linear time?

+4
source share
1 answer

Do they work in linear time?

Of course, they are: when the data is on the tree map, the search for K-order statistics is an O (N) * operation . Moreover, the likelihood that the operating system TreeMapwill have a lower constant coefficient if you do not decide to write a sorted container to an array.

, TreeMap - O (N * log 2 N), Median of Medians , . TreeMap .

* O (log 2 N), .

+1

Source: https://habr.com/ru/post/1619919/


All Articles