java - Three greatest values in an array -


to find 3 greatest elements in array(length 100), combination of loop , if statement(s) effective way, or there more efficient method?

your question not clear me.

the efficient way maintain max heap of size 3 , insert array elements max heap 1 one.

at end 3 elements in max heap 3 largest elements in original array.

in general problem of finding max m elements in array of size n best solved maintaining max heap of size m.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -