Chapter 3: Q12E (page 202)
Describe an algorithm that uses only assignment statements that replaces the triple (x, y, z)with (y, z, x). What is the minimum number of assignment statements needed?
Short Answer
The required algorithm is
Chapter 3: Q12E (page 202)
Describe an algorithm that uses only assignment statements that replaces the triple (x, y, z)with (y, z, x). What is the minimum number of assignment statements needed?
The required algorithm is
All the tools & learning materials you need for study success - in one app.
Get started for freea) Give an algorithm to determine whether a bit string contains a pair of consecutive zeros.
b) How many comparisons does the algorithm use?
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?
Describe an algorithm that locates the first occurrence of the largest element in a finite list of integers, where the integers in the list are not necessarily distinct.
a.) State the definition of the fact that f(n)is , where and are functions from the set of positive integers to the set of real numbers.
b.) Use the definition of the fact that f(n)isdirectly to prove or disprove that is .
c.) Use the definition of the fact that f(n)isdirectly to prove or disprove thatis.
Use the insertion sort to sort the list in Exercise 35, showing the list obtained at each step.
What do you think about this solution?
We value your feedback to improve our textbook solutions.