I have found out that selection sort uses Brute Force strategy. However, I think that it uses Greedy strategy.
Why do I think that it uses Greedy: it goes from 0 to n-1 at it outer loop and from i+1 to n-1. This is really naive. It selects the minimum element in one every iteration - it chooses best locally. Everything like in Greedy but it is not.
Can you please explain me why it is not how I think? Information about this issue I have not found in the Internet.
A selection sort could indeed be described as a greedy algorithm, in the sense that it:
As it happens, the same description could be applied to most other sorting algorithms, as well — the only real difference is the choice of subproblems. For example:
Indeed, off the top of my head, I can't think of any practical sorting algorithm that wouldn't be greedy in this sense. (Bogosort isn't, but can hardly be called practical.) Furthermore, formulating these sorting algorithms as greedy optimization problems like this rather obscures the details that actually matter in practice when comparing sorting algorithms.
Thus, I'd say that characterizing selection sort, or any other sorting algorithm, as greedy is technically valid but practically useless, since such classification provides no real useful information.
Let A be a list of intgers such that: A = [5, 4, 3, 6, 1, 2, 7 ]
A greedy algorithm will look for the most promising direction, therefore :
so a sorted list using this approach will result in a list sorted as such: [3, 4, 5, 1, 2, 7]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With