Computers and Technology

Consider sorting n numbers stored in array A by first finding the smallest element of A and exchanging it with the element in A[1]. Then find the second smallest element of A and exchange it with A[2]. Continue in this manner for the first n-1 elements of A. a) This algorithm is known as the selection sort. Write the pseudo code for this algorithm.
b) What loop invariant does this algorithm maintain? Note: You do not have to discuss the three individual properties. You need to only provide the loop invariant.
c) Why does it need to run for only the first n-1 elements, rather than for
all n elements?
d) Give the best-case and worst-case running times of selection sort in O-notation. Explain your answers. (You will receive no credit for this question without the explanations for your answers.)

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 06:30, Nicki3729
Exchanging which type of data uses the least bandwidth? music photographs video voice bandwidth- the amount of data that can be moved between two points in a set time period
Answers: 1
image
Computers and Technology, 24.06.2019 13:00, naomirice24
In a heat transfer course, we can derive the equation for the temperature distribution in a flat rectangular plate. in this example, we will look at a plate at steadystate with three sides being held at t1, and one side held at t2. the temperature for any location on the plate, t(x, y), can be calculated by where create a function (prob3_5) that will take inputs of vectors x and y in feet, scalar n, scalars l and w in feet and scalars t1 and t2 in degrees fahrenheit. it will output a matrix t which is the temperature of each x and y locations. t will have the number of columns equal to the number of elements in x and rows equal to the number of elements in y. though this can be done without loops (perhaps more efficiently), your program must use a nested loop.
Answers: 2
image
Computers and Technology, 25.06.2019 06:30, yushan2751
During which stage do you think is the best time for a company to purchase an emerging technology
Answers: 1
image
Computers and Technology, 25.06.2019 08:10, yangyang718
Rom also called main memory or system memoryis used to stor the essential parts of the operating while the computer is running / true or false
Answers: 2
Do you know the correct answer?
Consider sorting n numbers stored in array A by first finding the smallest element of A and exchangi...

Questions in other subjects:

Konu
Social Studies, 21.10.2019 13:30