Question: Exercises 2 . 2 - 1 Express the function n 3 1 0 0 0 - 1 0 0 n 2 - 1 0 0
Exercises
Express the function in terms of notation.
Consider sorting numbers stored in array by first finding the smallest element
of A and exchanging it with the element in Then find the second smallest
element of and exchange it with Continue in this manner for the first
elements of 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 elements, rather than for all elements? Give the bestcase
and worstcase running times of selection sort in notation.
Consider linear search again see Exercise How many elements of the in
put sequence need to be checked on the average, assuming that the element being
searched for is equally likely to be any element in the array? How about in the
worst case? What are the averagecase and worstcase running times of linear
search in notation? Justify your answers.
How can we modify almost any algorithm to have a good bestcase running time?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
