FaSe22 / phpalgorithms

learning basics...
1 stars 0 forks source link

Selectionsort #14

Open dimitrijjedich opened 1 week ago

dimitrijjedich commented 1 week ago

Selectionsort

Implementation happens on the following initial description:

We pick up the first element and assume it is the smallest in the array. After that we iterate trough the array searching for the real smallest element. If we find one, we switch our current with the found one and continue with the next element.

🤔 Thoughts

This is basicly the reverse of the Insertionsort. The easiest way to compare the two is to imagine a hand full of playing cards that should be sorted.

Insertion

We let the first card be and go to the second one. Pick it up and compare it the cards to the left and keep moving left until the card we are holding is bigger then the card to the left and drop it there. To back to our starting point and repeat the process until the last card was picked up and droped.

Selectionsort

We look at our first card and go trough all cards to the right. On the way we mark the lowest card we found. After we went all the way back to the right, we remember the marked card and switch it with the first one and repeat the process with the second card and so on until we reach the last card on the right.

sonarcloud[bot] commented 1 week ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud