Solution Found!
An algorithm is called optimal for the solution of a
Chapter 3, Problem 24E(choose chapter or problem)
Problem 24E
An algorithm is called optimal for the solution of a problem with respect to a specified operation if there is no algorithm for solving this problem using fewer operations.
a) Show that Algorithm 1 in Section 3.1 is an optimal algorithm with respect to the number of comparisons of integers. [Note: Comparisons used for bookkeeping in the loop are not of concern here.]
b) Is the linear search algorithm optimal with respect to the number of comparisons of integers (not including comparisons used for bookkeeping in the loop)?
Questions & Answers
QUESTION:
Problem 24E
An algorithm is called optimal for the solution of a problem with respect to a specified operation if there is no algorithm for solving this problem using fewer operations.
a) Show that Algorithm 1 in Section 3.1 is an optimal algorithm with respect to the number of comparisons of integers. [Note: Comparisons used for bookkeeping in the loop are not of concern here.]
b) Is the linear search algorithm optimal with respect to the number of comparisons of integers (not including comparisons used for bookkeeping in the loop)?
ANSWER:
Solution
In this question,
a) We have to show that as mentioned in algorithm 1 in section 3.1 it is an optimal algorithm with respect to number of comparisons of integers (Comparisons used for bookkeeping in the loop are not of concern here).
b) Also if the linear search algorithm is optimal with respect to the number of comparisons of integers (not including comparisons used for bookkeeping in the loop)?
Step 1
a) As mentioned in the algorithm in section 3.1
It is algorithm for finding the maximum element in a finite sequence.
procedure max (
if then
{max is the largest element}