Let’s say that you have some music files on your computer and you keep a record of the play count of each artist’s songs.
You want to sort this list by fewest plays to build a ranking of your favorite artists. How to do it?
One way is to go through the entire list and find the artist which
songs are most played, and adding it to a new list.
Next, in the same way, we are looking for the second most played artist.
Moving forward this way we will get a sorted list.
Selection Sort is an interesting but not very fast algorithm. The quicksort algorithm is faster and it has an execution time of O (n log n). I will write about it in my later posts.
Let’s see how it looks in code. The example is showing an easy way to sort tables in ascending order.
Using this function we can write a selection sort algorithm.
Comments
Post a Comment