   Chapter 11.3, Problem 17ES ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193

#### Solutions

Chapter
Section ### Discrete Mathematics With Applicat...

5th Edition
EPP + 1 other
ISBN: 9781337694193
Textbook Problem
1 views

# 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.17. for i : = 1 to nfor j : = 1 to ⌊ ( i + 1 ) / 2 ⌋ a : = ( n − i ) ⋅ ( n − j ) next jnext i

To determine

(a)

To compute the actual number of elementary operations (addition, subtractions, multiplication, division and comparisons) that are performed when the algorithm segment is executed.

Explanation

Given:

for i=1 to n

for j=1 to [i+12]

a=(ni)(nj)

Next j

Next i

Calculation:

Each iteration of the inner loop requires one multiplication and two subtraction.

So the total number of elementary operation is three times the number of iterations of the inner loop.

If i is odd, [i+12]=i+12 ,

Now the inner loop is iterated

1 times when i=1

2 times when i=3

n+12 times when i=n

if i is even [i+12]=i2.

Now the inner loop is iterated

1 times when i=2

2 times when i=4

n12 times when i=n1

Hence the total number of iterations of the inner loop is 3×((1+2+...+n+12)+(1+2+...+n12))

So,

3×((1+2+

To determine

(b)

To find an order for the algorithm segment by using the theorem on polynomial orders.

for i=1 to n

for j=1 to [i+12]

a=(ni)(nj)

Next j

Next i

### Still sussing out bartleby?

Check out a sample textbook solution.

See a sample solution

#### The Solution to Your Study Problems

Bartleby provides explanations to thousands of textbook problems written by our experts, many with advanced degrees!

Get Started 