Chapter 3: Q26E (page 231)
Describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described inExercise 28 of Section 3.1.
Short Answer
O(log n)
Chapter 3: Q26E (page 231)
Describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described inExercise 28 of Section 3.1.
O(log n)
All the tools & learning materials you need for study success - in one app.
Get started for freeSuppose we have three men and three women . Furthermore, suppose that the preference rankings of the men for the three women, from highest to lowest, are and the preference rankings of the women for the three men, from highest to lowest, are . For each of the six possible matchings of men and women to form three couples, determine whether this matching is stable.
Use the bubble sort to sort 3, 1, 5, 7, 4, showing the lists obtained at each step.
Describe an algorithm that takes as input a list of n distinct integers and finds the location of the largest even integer in the list or returns 0 if there are no even integers in the list.
a) Describe an algorithm for finding the first and second largest elements in a list of integers.
b) Estimate the number of comparisons used.
Specify the steps of an algorithm that locates an element in a list of increasing integers by successively splitting the list into four sublists of equal (or as close to equal as possible) size, and restricting the search to the appropriate piece. In a list of elements, the same element may appear several times. A mode of such a list is an element that occurs at least as often as each of the other elements; a list has more than one mode when more than one element appears the maximum number of times.
What do you think about this solution?
We value your feedback to improve our textbook solutions.