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.
18. for to nfor to n next jnext i
Compute the actual number of the elementary operation by execution of algorithm.
Given algorithm segments iteration of inner for-loop execute x:=i*j exactly done once .Let us determine the number of iteration of inner for-loop j goes up to (i+1)/2 to n ,which are n-(i+1)/2-1 possible value the for-loop have to iterate and for-loop I goes 1 to n.
First case when n is even then n+1 is odd thus no of iteration is
Second case when n is odd then n+1 is odd thus no of iteration is
Use the theorem on polynomial order to find the order for the algorithm segments.
Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!Get Started