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
Post a Comment