whenever you see one loop nested within anothersuch as those in the bubble sort and the other sorting algorithms in this you can suspect that an algorithm runs in ( time the outer loop executes timesand the inner loop executes (or perhaps divided by some constanttimes for each cycle of the outer loop this means you're doing something approximately * or times selection sort the selection sort improves on the bubble sort by reducing the number of swaps necessary from ( to (nunfortunatelythe number of comparisons remains ( howeverthe selection sort can still offer significant improvement for large records that must be physically moved around in memorycausing the swap time to be much more important than the comparison time (typicallythis isn' the case in javawhere references are moved aroundnot entire objects selection sort on the baseball players let' consider the baseball players again in the selection sortyou can no longer compare only players standing next to each other thusyou'll need to remember certain player' heightyou can use notebook to write it down magenta-colored towel will also come in handy brief description what' involved in the selection sort is making pass through all the players and picking (or selectinghence the name of the sortthe shortest one this shortest player is then swapped with the player on the left end of the lineat position now the leftmost player is sorted and won' need to be moved again notice that in this algorithm the sorted players accumulate on the left (lower indices)whereas in the bubble sort they accumulated on the right the next time you pass down the row of playersyou start at position andfinding the minimumswap with position this process continues until all the players are sorted more detailed description in more detailstart at the left end of the line of players record the leftmost player' height in your notebook and throw the magenta towel on the ground in front of this person then compare the height of the next player to the right with the height in your notebook if this player is shortercross out the height of the first player and record the second player' height instead also move the towelplacing it in front of this new "shortest(for the time beingplayer continue down the rowcomparing each player with the minimum change the minimum value in your notebook and move the towel whenever you find shorter player when you're donethe magenta towel will be in front of the shortest player