Taking a stab at this I would think that number 1 would be n

Taking a stab at this I would think that number 1 would be n-1 additions for 2(a), n-1 additions for 2(b), n-1 additions for 2(c) and we can only exit step 2 when k =n thus we have n comparisons. So would the answer to this be 4n-3?

For number 3:
Step 2 has n-1 additions (2a) and 2(b) and 2(c) are only replacing so they are not counted and then another n-1 additons for 2(d). Since step 2 keeps going until k=n we have n comparisons. Thus the equation would be 3n - 2 is this also correct?

Thanks for the help!

2. (Similar to Exercise 14Question 28 on page 34How many elementary operations are used in the following algorithm? According to page 25 of the textbook, the elementary operations are comparison operations (such as > and 9 and mathematical operations (such as addition, subtraction, multiplication division, etc.). Step 1 Set S=a, k=1, and t=a. Step 2 while kn (a)Replace twith t+d (b)Replace S with S+t (c)Replacek with k+1 endwhile Step 3 Print S. 3. (Similar to Exercise 1.4 Question 30 on page 34) How many elementary operations are used in the following algorithm? According to page 25 of the textbookthe elementary operations are comparison operations (such as and 9) and mathematical operations (such as addition, subtraction, multiplication, division, etc.). Step 1 Sot a=1, b= =2, and k=1. Step 2 while kn (a)Replace c with at (BReplace a with (CReplace b with a (d)Replace k with k+1 endwhile Step 3 Print

Solution

2) 2.a t+d=a+d

       b.s+a =a+a

       c. k=k+1

   3. if n=k then exit

        3(n-1)+n

     =3n-3+n

    =4n-3

3) yes here

as above have two addtitions and two not have any operations

and n comparaasions.

   = 2(n-1)+n

= 2n-2+n

=3n-2

Taking a stab at this I would think that number 1 would be n-1 additions for 2(a), n-1 additions for 2(b), n-1 additions for 2(c) and we can only exit step 2 wh

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site