Consider the following algorithm segment. Assume that n is a positive integer. for i:= 1 to n for j:= [(i + 1)/2] to n x:= i:j next j next i (a) What is the actual number of elementary operations (additions, subtractions, multiplications, divisions, and comparisons) that are performed when the algorithm segment is executed? For simplicity, count only comparisons that occur within if-then statements, and ignore those implied by for-next loops. Express your answer in terms of n. (Hint: See Example 11.3.4 and Exercise 11.3.17a in the "Read It" link.) 3n + 2n - 1 For odd n the number of operations is 4 3n For even n the number of operations is 4

Advanced Engineering Mathematics
10th Edition
ISBN:9780470458365
Author:Erwin Kreyszig
Publisher:Erwin Kreyszig
Chapter2: Second-order Linear Odes
Section: Chapter Questions
Problem 1RQ
icon
Related questions
Question
Can you show me the step on how to get the answer for this?? I have attached an example problem
for i 1 toA
for j=1 to i+l)/21
17.
エーロールー me malt ¢ 2 Sulonctas o3
per,
rtinton
next
15
2.
121212 3
2.
2.
3.
|+1+2+2+3+る4+?
十112+2+3
201+2)+ ntI
n old 2.
(型)
example
neven 9
cい fm
timple
1ナ+2+243+3
21け2+3)
2(172+.+ 2)
L)(学)。号
19.*
Por 7 1 tn a
3.
Transcribed Image Text:for i 1 toA for j=1 to i+l)/21 17. エーロールー me malt ¢ 2 Sulonctas o3 per, rtinton next 15 2. 121212 3 2. 2. 3. |+1+2+2+3+る4+? 十112+2+3 201+2)+ ntI n old 2. (型) example neven 9 cい fm timple 1ナ+2+243+3 21け2+3) 2(172+.+ 2) L)(学)。号 19.* Por 7 1 tn a 3.
Consider the following algorithm segment. Assume that n is a positive integer.
for i:= 1 ton
for j := [(i + 1)/2] to n
x := i·j
next j
next i
(a) What is the actual number of elementary operations (additions, subtractions, multiplications, divisions, and comparisons) that are performed when the algorithm segment is executed?
For simplicity, count only comparisons that occur within if-then statements, and ignore those implied by for-next loops. Express your answer in terms of n. (Hint: See Example 11.3.4
and Exercise 11.3.17a in the "Read It" link.)
+ 2n - 1
For odd n the number of operations is
4.
3n
For even n the number of operations is
4.
77
2
(b) Apply the theorem on polynomial orders to the expressions in part (a) to find that an order for the algorithm segment is n
Transcribed Image Text:Consider the following algorithm segment. Assume that n is a positive integer. for i:= 1 ton for j := [(i + 1)/2] to n x := i·j next j next i (a) What is the actual number of elementary operations (additions, subtractions, multiplications, divisions, and comparisons) that are performed when the algorithm segment is executed? For simplicity, count only comparisons that occur within if-then statements, and ignore those implied by for-next loops. Express your answer in terms of n. (Hint: See Example 11.3.4 and Exercise 11.3.17a in the "Read It" link.) + 2n - 1 For odd n the number of operations is 4. 3n For even n the number of operations is 4. 77 2 (b) Apply the theorem on polynomial orders to the expressions in part (a) to find that an order for the algorithm segment is n
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Recommended textbooks for you
Advanced Engineering Mathematics
Advanced Engineering Mathematics
Advanced Math
ISBN:
9780470458365
Author:
Erwin Kreyszig
Publisher:
Wiley, John & Sons, Incorporated
Numerical Methods for Engineers
Numerical Methods for Engineers
Advanced Math
ISBN:
9780073397924
Author:
Steven C. Chapra Dr., Raymond P. Canale
Publisher:
McGraw-Hill Education
Introductory Mathematics for Engineering Applicat…
Introductory Mathematics for Engineering Applicat…
Advanced Math
ISBN:
9781118141809
Author:
Nathan Klingbeil
Publisher:
WILEY
Mathematics For Machine Technology
Mathematics For Machine Technology
Advanced Math
ISBN:
9781337798310
Author:
Peterson, John.
Publisher:
Cengage Learning,
Basic Technical Mathematics
Basic Technical Mathematics
Advanced Math
ISBN:
9780134437705
Author:
Washington
Publisher:
PEARSON
Topology
Topology
Advanced Math
ISBN:
9780134689517
Author:
Munkres, James R.
Publisher:
Pearson,