Chapter 3: Q45E (page 203)
How many comparisons does the insertion sort use to sort the list 1,2,3,…,n?
Short Answer
The number of comparisons to sort 1,2,..,n using insertion sort is,
.
Chapter 3: Q45E (page 203)
How many comparisons does the insertion sort use to sort the list 1,2,3,…,n?
The number of comparisons to sort 1,2,..,n using insertion sort is,
.
All the tools & learning materials you need for study success - in one app.
Get started for freeUse the greedy algorithm to make change using quarters, dimes, and pennies (but no nickels) for each of the amounts given in Exercise 52. For which of these amounts does the greedy algorithm use the fewest coins of these denominations possible?
a) Describe in detail (and in English) the steps of an algorithm that finds the maximum and minimum of a sequence of elements by examining pairs of successive elements, keeping track of a temporary maximum and a temporary minimum. Ifn is odd, both the temporary maximum and temporary minimum should initially equal the first term, and ifn is even, the temporary minimum and temporary maximum should be found by comparing the initial two elements. The temporary maximum and temporary minimum should be updated by comparing them with the maximum and minimum of the pair of elements being examined.
b) Express the algorithm described in part (a) in pseudocode.
c) How many comparisons of elements of the sequence are carried out by this algorithm? (Do not count comparisons used to determine whether the end of the sequence has been reached.) How does this compare to the number of comparisons used by the algorithm in Exercise 5?
a) Describe an algorithm for finding the first and second largest elements in a list of integers.
b) Estimate the number of comparisons used.
a.) Explain the concept of a greedy algorithm.
b.) Prove the example of a greedy algorithm that produces an optimal solution and explain why it produces an optimal solution.
c.) Provide an example of a greedy algorithm that does not always produce an optimal solution and explain why it fails to do so.
a) Suppose that a list contains integers that are in order of largest to smallest and an integer can appear repeatedly in this list. Devise an algorithm that locates all occurrences of an integerxin the list.
b) Estimate the number of comparisons used.
What do you think about this solution?
We value your feedback to improve our textbook solutions.