Chapter 3: Q9E (page 202)
A palindrome is a string that reads the same forward and backward. Describe an algorithm for determining whether a string of n characters is a palindrome.
Short Answer
The algorithm is as follows:
Chapter 3: Q9E (page 202)
A palindrome is a string that reads the same forward and backward. Describe an algorithm for determining whether a string of n characters is a palindrome.
The algorithm is as follows:
All the tools & learning materials you need for study success - in one app.
Get started for freea) 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?
Express the binary insertion sort in pseudocode.
Use the bubble sort 6 , 2 , 3, 1 , 5, 4 , to sort showing the lists obtained at each step.
Use the bubble sort to sort 3, 1, 5, 7, 4, showing the lists obtained at each step.
Describe an algorithm that locates the last occurrence of the smallest element in a finite list of integers, where the integers in the list are not necessarily distinct.
What do you think about this solution?
We value your feedback to improve our textbook solutions.