For each of the algorithm segments in 6—19, assume that n is a positive integer. (a) Compute the actual number of elementary operations (additions, subtractions, multiplications, divisions, and comparisons) that are performed when the algorithm segment is executed. For simplicity, however, count only comparisons that occur within if then statements; ignore those implied by for-next loops. (b) Use the theorem on polynomial orders to find an order for the algorithm segment.
8. for to next i
The computation of actual number of elementary operations performed.
Each iteration of the loop requires one addition and there are as many iterations of the loop as there are integers from 1 to , namely times.
If n is even, then , so the number of elementary operations performed is
An order for the given algorithm segment.
Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!Get Started