Question Details

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 >= 0) y = x + y;

 

else y = y - x;

 

(2) /* precondition : m <= n */

 

s = 0;

 

for (i = m; i <= n; i++)

 

s += i;

 

(3) i = 1;

 

c = 0;

 

while (i <= n)

 

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

 

else i = i + 1;}

 

(4) m = a[1];

 

i = 2;

 

while (i <= n)

 

{ if a[i] > m) then m = a[i];

 

else i = i +1; }

 

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

 

/* precond: 1 <= b */

 

i = 1;

 

c = 1;

 

while (i <= 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 <= high)

 

{ mid = (low + high)/2;

 

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

 

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

 

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

 

return (not_found);

 


 

(2)

 

sum = 0;

 

for( i = 0; i < n; i++ )

 

for( j = 0; j < n; j++ )

 

sum++;

 

(3)

 

sum = 0;

 

for( i = 0; i < n; i++ )

 

for( j = 0; j < i; j++ )

 

sum++;

 

(4)

 

sum = 0;

 

for( i = 0; i < n; i++ )

 

for( j = 0; j < i*i; j++ )

 

for( k = 0; k < j; k++ )

 

sum++;

 

(5)

 

sum = 0;

 

for( i = 1; i < n; i++ )

 

for( j = 1; j < i*i; j++ )

 

if( j%i ==0 )

 

for( k = 0; k < 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>=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
Answered
QUALITY
Approved
ANSWER RATING

This question was answered on: Sep 18, 2020

PRICE: $15

Solution~0001185687.zip (25.37 KB)

Buy this answer for only: $15

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 .
SiteLock

About this Question

STATUS

Answered

QUALITY

Approved

DATE ANSWERED

Sep 18, 2020

EXPERT

Tutor

ANSWER RATING

GET INSTANT HELP/h4>

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

  • As a reference for in-depth understanding of the subject.
  • As a source of ideas / reasoning for your own research (if properly referenced)
  • For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student.

NEW ASSIGNMENT HELP?

Order New Solution. Quick Turnaround

Click on the button below in order to Order for a New, Original and High-Quality Essay Solutions. New orders are original solutions and precise to your writing instruction requirements. Place a New Order using the button below.

WE GUARANTEE, THAT YOUR PAPER WILL BE WRITTEN FROM SCRATCH AND WITHIN YOUR SET DEADLINE.

Order Now