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

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

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -

asp.net - call stack missing info on mono with apache and mod_mono -