Question: Exercises 2 . 2 - 1 Express the function n 3 1 0 0 0 - 1 0 0 n 2 - 1 0 0

Exercises
2.2-1
Express the function n31000-100n2-100n+3 in terms of -notation.
2.2-2
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. 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-1 elements, rather than for all n elements? Give the best-case
and worst-case running times of selection sort in -notation.
2.2-3
Consider linear search again (see Exercise 2.1-3). 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 average-case and worst-case running times of linear
search in -notation? Justify your answers.
2.2-4
How can we modify almost any algorithm to have a good best-case running time?
Exercises 2 . 2 - 1 Express the function n 3 1 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!