
-----------------------------------
chilli
Sat Jun 14, 2008 6:13 am

selection sort best/worst case
-----------------------------------
hi,

 i have an array of these numbers:

38 71 14 29 65 7 81 44 75 27

can somebody tell me how the worst and best case look like ? i would say 

bc:

7 14 27 29 38 44 65 71 81 95

wc:

95 81 71 65 44 38 29 27 14 7

is that correct?

-----------------------------------
Epic Tissue
Sat Jun 14, 2008 6:34 am

Re: selection sort best/worst case
-----------------------------------
This might be slightly more noticed in the Mod edit:  Moved to Java Help.

-----------------------------------
chilli
Sat Jun 14, 2008 7:35 am

Re: selection sort best/worst case
-----------------------------------
i would like t know how to implement the worst case and the best case  in java of these numbers ?

-----------------------------------
Zeroth
Sat Jun 14, 2008 8:49 am

Re: selection sort best/worst case
-----------------------------------
Worst/best case has nothing to do with the implementation. They are merely descriptions of what the worst performance for an algorithm might be. Or conversely, best performance, since the algorithm behaves differently towards different arrangements of arrays. To give an analogy, when a runner has a bad day, its because of various conditions, not because he ran differently. The same for algorithms. Best/worst case describe how the algorithm behaves, and gives an idea on how much time it would take on two different extremes of data input. 

So, with that said, there is only one implementation you need to do with selection sort. I'm not going to provide any code, since that would not let you learn at all. But here's some pseudocode, straight from 
for i &#8592; 0 to n-2 do
    min &#8592; i
    for j &#8592; (i + 1) to n-1 do
        if A[j] < A[min]
            min &#8592; j
    swap A[i] and A[min]

I hope that helps!
