big o - Big-O of PHP arrays -
after reading answers list of big-o php functions got little curious.
the answer of kendall hopkins states php lookups o(n) large arrays , constant time (means o(1) ?!) small. posted image containing graph shows time constant amount of lookups (1 million) take depending on size of array. starts vertically , flattens.
from learned constant time means time taken not function of elements in array means horizontal graph not vertical. think graph looks more o(log n) fit comments stating php implements recursive hash tables.
i did own testing (using script) , graph turned out pretty same (php 5.3.23).
as top rated answer i'm little bit scared. can tell me if i'm getting whole o(x) thing wrong? if please me.
anyway: @kendall hopkins great answer !
you're correct in saying kendall hopkins's statement confusing / incorrect (though rest of post pretty awesome benchmarking reference).
saying algorithm o(1) small inputs rather nonsensical statement. saying algorithm o(1) means running time less constant. therefore, if constrict our input space finite set (i.e. 'small' inputs) algorithm o(1), because can take longest running time set our constant.
what means, that, initial range of inputs, increasing size of array make little difference running-time of array.
if want learn more big-o notation, [http://en.wikipedia.org/wiki/analysis_of_algorithms wikipedia page] great jumping off point.
Comments
Post a Comment