Wednesday, 15 May 2013

java - Get Minimum and maximum numbers from a list -



java - Get Minimum and maximum numbers from a list -

assuming have list containing integers , need find min & max. best way ? can think of next :

if number of reads much higher writes; maintain list in sorted manner. whenever number added; add together in sorted manner. min , max can first , lastly element of list.

if number of writes higher reads; iterate on list , homecoming result. o(n) looks expensive.

is there other improve way ?

assuming can observe mutation list, store (cache) min , max values , perchance update cached values when number added / removed. @ point, order of list doens't matter.

java algorithm sorting data-structures

No comments:

Post a Comment