This preview shows page 1. Sign up to view the full content.
Unformatted text preview: In general, the program has to perform 2(n-1) comparisons inside the loop. In the worst case for finding max (i.e., the input array is already in increasing order), the program needs (n-1) assignments in (*) and no assignment in (**) since the worst case of max is the best case of min and vice versa. The same argument applies for the worst case for finding min. Therefore, the total number of comparisons and assignments in the worst case is: 2(n-1) + (n-1) = 3n 3....
View Full Document
- Spring '08