Westonci.ca is the premier destination for reliable answers to your questions, provided by a community of experts. Discover reliable solutions to your questions from a wide network of experts on our comprehensive Q&A platform. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.

consider sorting nn numbers stored in array aa by first finding the smallest element of aa and exchanging it with the element in a[1]a[1]. then find the second smallest element of aa, and exchange it with a[2]a[2]. continue in this manner for the first n-1n−1 elements of aa. write pseudocode for this algorithm, which is known as selection sort. what loop invariant does this algorithm maintain? why does it need to run for only the first n-1n−1 elements, rather than for all nn elements? give the best-case and worst-case running times of selection sort in \thetaθ-notation.