Question
1. Use pseudocode to express the following algorithm for finding the smallest and largest integers in a list of n integers. Examine pairs of successive
1. Use pseudocode to express the following algorithm for finding the smallest and largest integers in a list of n integers.
Examine pairs of successive elements, keeping track of a temporary maximum and a temporary minimum. If n is odd, both the temporary maximum and the temporary minimum should be initialized to the first element. If n is even, the initial values of the temporary maximum and temporary minimum should be found by comparing the first two elements of the list. The temporary maximum and temporary minimum should be updated by comparing them to the maximum and minimum of the pair of elements being examined.
2. Show that this algorithm uses O(n) comparisons in the worst case, with C = 1.5. Note: if your implementation uses more than 1.5n comparisons, you have not correctly implemented the algorithm.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started