Algorithms and analysis | Computer Science homework help

CS277 – Homework 1

Total points: 85

1. Consider the following polynomial with n terms, where ai is the ith coefficient:

P (x) =
n−1∑
i=0

aix
i = a0 + a1x+ a2x

2 + …+ an−1x
n−1

Below is pseudocode of a naive algorithm that calculates P (x) for some input x:

1 Function pow(x, i):
2 // x is a number, i is an integer, returns xi

3 exp := 1
4 p := 1
5 while p ≤ i do
6 exp = exp ∗ x
7 p += 1

8 return exp

9 Function calculatePoly1(x, a, n):
10 // x is a number, a is a list of numbers, n is the length of a
11 sum := 0
12 i := 0
13 while i < n do
14 sum += a[i] * pow(x, i)
15 i += 1

16 return sum

(a) (4 points) Prove a tight bound for the runtime complexity of calculatePoly1 using sum-
mations.

(b) (4 points) Give a tight bound for the space complexity of calculatePoly1. Explain your
bound.

Assume that all integers and floats require the same, constant amount of memory.

Note: Unless otherwise specified, we ignore the space required to store the input argu-
ments, since this will remain the same for all algorithms that solve the same problem.

(c) (10 points) Propose an algorithm calculatePoly2 with asymptotically better runtime
compared to calculatePoly1 and provide its pseudocode.

Give tight bounds for your algorithm’s runtime and space complexity. Explain your
bounds.

1

Your answer may not use a built-in exponentiation operator (like xˆn or x**n). You may
use other basic operators like addition, multiplication, etc.

2. For each of the following questions, briefly explain your answer.

(a) (4 points) If an algorithm’s best case runtime is Θ(n), is it possible that it takes Θ(n2)
time on some inputs?

(b) (4 points) If an algorithm’s best case runtime is Θ(n), is it possible that it takes Θ(n2)
time on all inputs?

(c) (4 points) If an algorithm’s worst case runtime is O(n2), is it possible that it takes o(n2)
time on some inputs?

(d) (4 points) If an algorithm’s worst case runtime is O(n2), is it possible that it takes o(n2)
time on all inputs?

3. (6 points) Prove the following bound using the inequality definition of O: 18n lg(n) + 2n2 =
O(n2)

4. (10 points) Consider all exponential functions of the form f(n) = kn, where k is a positive
constant.

Do there exist two exponential functions of this form with different bases (e.g. f(n) = 2n and
g(n) = 3n) such that their growth rates are asymptotically equivalent?

Prove your answer.

5. (10 points) Prove the property of transitivity for O: For any two asymptotically non-negative
functions f and g, if f(n) = O(g(n)) and g(n) = O(h(n)), then f(n) = O(h(n)).

6. (25 points) Order the following functions from least to greatest growth rate, such that for any
two functions f and g, if f comes before g, then f(n) = O(g(n)). You must prove each
ranking.

For example, if the functions were f, g, h and you gave the order g, h, f , then you would need
to prove that g(n) = O(h(n)), g(n) = O(f(n)), and h(n) = O(f(n)).

• f1(n) =

n

• f2(n) = nn

• f3(n) = n0.00001

• f4(n) = n!

• f5(n) = lg(n)

Hint: Reusing results previously proved in this assignment may save you a lot of work.

Page 2

Calculate Your Essay Price
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more