algorithm - Average number of swaps performed in Bubble Sort -
i came across problem right now: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&category=24&page=show_problem&problem=3155 problems asks calculate average number of swaps performed bubble sort algorithm when given data shuffled order of first n (1 n listed randomly) natural numbers.
so, thought that:
- max no of swaps possible=n(n-1)/2. (when in descending order.)
- min no of swaps possible=0. (when in ascending order.)
so, mode of distribution (0+n(n-1)/2)/2 =n(n-1)/4. but, turned out answer. don't understand why did mode coincide mean.
since inputs sorted can random number equal probability of occurrence, distribution symmetrical.
it property of symmetrical distributions mean, median , modes coincide why mean , mode same.
Comments
Post a Comment