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.
7. for to nif then next i
The actual number of elementary operations performed.
We are given a snippet below.
The first elementary operation is assignment, so count is
Now for loop will execute times which is equal to
Inside for loop there are two elementary operations one is comparison and other is assignment
In worst case both operations will be executed in every iteration
The polynomial order of the given algorithm.
Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!Get Started