CS170 Homework 1 Solved

35.00 $

Category:

Description

5/5 - (1 vote)

 

Asymptotic Complexity Comparisons

Order the following functions so that for all i,j, if fi comes before fj in the order then fi = O(fj). Do not justify your answers.

(b)

􏰎 f3(n)=12

􏰎 f4(n) = 2log2 n √

􏰎f5(n)= n

􏰎 f6(n)=2n

􏰎 f7(n) = log2 n √

􏰎 f8(n)=2 n 􏰎 f9(n)=n3

As an answer you may just write the functions as a list, e.g. f8, f9, f1, . . .

In each of the following, indicate whether f = O(g), f = Ω(g), or both (in which case f = Θ(g)). Briefly justify each of your answers. Recall that in terms of asymptotic growth rate, logarithmic < polynomial < exponential.

g(n) log4(n) n2 log(n3) (log n)3

5

Computing Factorials

􏰎 f1(n)=3n 1

􏰎 f2(n)=n3

f(n) log3 n

(i)
(ii)
(iii)
(iv) n+logn n+(logn)2

n log(n4) √n

Consider the problem of computing N ! = 1 × 2 × · · · × N .

(a) N is logN bits long (this is how many bits are needed to store a number the size of N). Find an f(N) so that N! is Θ(f(N))) bits long. Simplify your answer as much as possible, and give an argument for why it is true.

 

(b) Give a simple (naive) algorithm to compute N!. You may assume that multiplying two bits together (e.g. 0 × 0, 0 × 1) takes 1 unit of time.

Please give both the algorithm description and runtime analysis.

6 Polynomial Evaluation

Given coefficients a0, . . . , an ∈ N, consider the polynomial:

n
p(x) = 􏰀akxk

k=0
For this problem, assume that addition and multiplication of two natural numbers takes

only O(1) time (regardless of how large they are).
(a) Describe a naive algorithm that, given [a0, . . . , an] and x, computes p(x). Give an analysis

of its runtime as a function of the degree of the polynomial n. (b) As an alternative, we can compute the following expression:

p(x)=a0 +x(a1 +x(a2 +…+x(an−1 +x·an)…))
Describe and analyze an algorithm that evaluates the polynomial using the above expres-

sion. The runtime should be a function of n as well.
Give a 3-part solution as described in the homework guidelines.

3

  • HW1-zhyj1k.zip