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

Algebra & Trigonometry with Analytic Geometry
13th Edition
ISBN:9781133382119
Author:Swokowski
Publisher:Swokowski
Chapter1: Fundamental Concepts Of Algebra
Section1.2: Exponents And Radicals
Problem 92E
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
Algebra & Trigonometry with Analytic Geometry
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:
9781133382119
Author:
Swokowski
Publisher:
Cengage
College Algebra (MindTap Course List)
College Algebra (MindTap Course List)
Algebra
ISBN:
9781305652231
Author:
R. David Gustafson, Jeff Hughes
Publisher:
Cengage Learning
Algebra: Structure And Method, Book 1
Algebra: Structure And Method, Book 1
Algebra
ISBN:
9780395977224
Author:
Richard G. Brown, Mary P. Dolciani, Robert H. Sorgenfrey, William L. Cole
Publisher:
McDougal Littell