Chapter 3: Q25E (page 231)
Describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described in Exercise 27 of Section 3.1.
Short Answer
O(log n)
Chapter 3: Q25E (page 231)
Describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described in Exercise 27 of Section 3.1.
O(log n)
All the tools & learning materials you need for study success - in one app.
Get started for freeDevise an algorithm that finds the first term of a sequence of positive integers that is less than the immediately preceding term of the sequence.
Devise an algorithm to compute xn, where xis a real number and nis an integer. [Hint:First give a procedure for computing xnwhen nis nonnegative by successive multiplication by x, starting with 1. Then extend this procedure, and use the fact that x−n=1/xnto compute xnwhen nis negative.]
How many comparisons does the insertion sort use to sort the list n, n – 1,…, 2, 1?
The binary insertion sort is a variation of the insertion sort that uses a binary search technique (see Exercise 44) rather than a linear search technique to insert the element in the correct place among the previously sorted elements.
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?
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.