performance - Big(0) running time for selection sort -


you given list of 100 integers have been read file. if values zero, running time (in terms of o-notation) of selection sort algorithm.

i thought o(n) because selection sort starts leftmost number sorted side. goes through rest of array find smallest number , swaps the first number in sorted side. since zeros won't swap numbers (or think).

my teacher said o(n^2). can explain why?

selection sort not adaptive. each element compared each other element (compare n elements n other elements → n^2 comparisons). thus, selection sort has o(n^2) comparisons. has, however, o(n) swaps.

think of table n rows , n colums, , each cell needs comparison fill value (except diagonal).

more info on amazing website


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -