## Answered: - data structure homework 1 Spring, 2016 Prof. I. J., Chung

do you have any sol of what I've attached?

I would like to get the proper solution.

data structure homework 1

Spring, 2016

Prof. I. J., Chung

For each of the followings, state the precondition or/and postcondition.

(1) if (x &gt;= 0) y = x + y;

else y = y - x;

(2) /* precondition : m &lt;= n */

s = 0;

for (i = m; i &lt;= n; i++)

s += i;

(3) i = 1;

c = 0;

while (i &lt;= n)

{ if a[i] = 17 then c = c + 1;

else i = i + 1;}

(4) m = a;

i = 2;

while (i &lt;= n)

{ if a[i] &gt; m) then m = a[i];

else i = i +1; }

2. (1) State the postcondition and loop invariant for the following code.

/* precond: 1 &lt;= b */

i = 1;

c = 1;

while (i &lt;= b)

{ c = c * a:

i++; }

(2) Show that the above algorithm is totally correct w.r.t. the precondition and

postcondition.

3. What is the time complexity for each of the following algorithm? Just state the big-oh

complexity measure :

(1)

int bs(a, x, n)

{ int low, mid, high;

}

low = 0; high = n-1;

while (low &lt;= high)

{ mid = (low + high)/2;

if (a[mid] &lt; x) low = mid + 1;

else if (a[mid] &lt; x) high = mid - 1;

else return (mid); /* found */ }

return (not_found);

(2)

sum = 0;

for( i = 0; i &lt; n; i++ )

for( j = 0; j &lt; n; j++ )

sum++;

(3)

sum = 0;

for( i = 0; i &lt; n; i++ )

for( j = 0; j &lt; i; j++ )

sum++;

(4)

sum = 0;

for( i = 0; i &lt; n; i++ )

for( j = 0; j &lt; i*i; j++ )

for( k = 0; k &lt; j; k++ )

sum++;

(5)

sum = 0;

for( i = 1; i &lt; n; i++ )

for( j = 1; j &lt; i*i; j++ )

if( j%i ==0 )

for( k = 0; k &lt; j; k++ )

sum++;

5. Consider the following algorithm (known as Horner's rule) to evaluate

f ( x) = ?

n

i= 0

a

i

i

x :

poly = 0;

for( i=n; i&gt;=0; I-- )

poly = x * poly + ai

What is the running time of this algorithm?

6. Order the following functions by growth rate:

n,

n, n

1.5

, n

2

, nlogn ,nloglogn ,n log

2

n ,nlog( n

Indicate which functions grow at the same rate.

2

),2/n , 2

n

, 2

n /2

, 37, n

2

log n , n

3

.

Solution details:
STATUS
QUALITY
Approved

This question was answered on: Sep 18, 2020 Solution~0001185687.zip (25.37 KB)

This attachment is locked

We have a ready expert answer for this paper which you can use for in-depth understanding, research editing or paraphrasing. You can buy it or order for a fresh, original and plagiarism-free copy from our tutoring website www.aceyourhomework.com (Deadline assured. Flexible pricing. TurnItIn Report provided)

##### Pay using PayPal (No PayPal account Required) or your credit card . All your purchases are securely protected by .

STATUS

QUALITY

Approved

Sep 18, 2020

EXPERT

Tutor 