You are on page 1of 4

CS 170, Spring 2020 HW 1 A. Chiesa & J.

Nelson

CS 170 HW 1
Due 1/27/2020, at 10:00 pm (grace period until 10:30pm)

1 Study Group
List the names and SIDs of the members in your study group. If you have no collaborators,
you must explicitly write none.

2 Course Policies
(a) What dates and times are the exams for CS170 this semester?
If you have any conflicts, please fill out the exam conflicts form:
https://forms.gle/oFtgYRU3u1iTF84u5
Filling out the exam conflict form does not guarantee you will be granted accommodation.

(b) Homework is due at 10:00pm, with a late deadline at 10:30pm. At what time do we
recommend you have your homework finished?

(c) We provide 2 homework drops for cases of emergency or technical issues that may arise
due to homework submission. If you miss the Gradescope late deadline (even by a few
minutes) and need to submit the homework, what should you do?

(d) What is the primary source of communication for CS170 to reach students? We will email
out all important deadlines through this medium, and you are responsible for checking
your emails and reading each announcement fully.

(e) Please read all of the following:

(i) Syllabus and Policies: https://cs170.org/syllabus/


(ii) Homework Guidelines: https://cs170.org/resources/homework-guidelines/
(iii) Regrade Etiquette: https://cs170.org/resources/regrade-etiquette/
(iv) Piazza Etiquette: https://cs170.org/resources/piazza-etiquette/

Once you have read them, copy and sign the following sentence on your homework sub-
mission.
”I have read and understood the course syllabus and policies.”

1
CS 170, Spring 2020 HW 1 A. Chiesa & J. Nelson

3 Understanding Academic Dishonesty


Before you answer any of the following questions, make sure you have read over the syllabus
and course policies (https://cs170.org/syllabus/) carefully. For each statement below,
write OK if it is allowed by the course policies and Not OK otherwise.

(a) You ask a friend who took CS 170 previously for their homework solutions, some of which
overlap with this semester’s problem sets. You look at their solutions, then later write
them down in your own words.

(b) You had 5 midterms on the same day and are behind on your homework. You decide to
ask your classmate, who’s already done the homework, for help. They tell you how to do
the first three problems.

(c) You look up a homework problem online and find the exact solution. You then write it
in your words and cite the source.

(d) You were looking up Dijkstra’s on the internet, and run into a website with a problem
very similar to one on your homework. You read it, including the solution, and then you
close the website, write up your solution, and cite the website URL in your homework
writeup.

2
CS 170, Spring 2020 HW 1 A. Chiesa & J. Nelson

4 Asymptotic Complexity Comparisons


(a) 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.
• f1 (n) = 3n
1
• f2 (n) = n 3
• 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 , . . .
(b) 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.
f (n) g(n)
(i) log3 n log4 (n)
(ii) n log(n4 ) n2 log(n3 )

(iii) n (log n)3
(iv) n + log n n + (log n)2

5 Computing Factorials
Consider the problem of computing N ! = 1 × 2 × · · · × N .
(a) N is log N 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.
Hint: You may use Stirling’s formula:

n
X √  n n 
log k ∼ log 2πn
e
k=1
f (n)
Where f (n) ∼ g(n) means that lim = 1.
n→∞ g(n)
Note: There are ways to solve this problem without using Stirling’s formula. Any answer
that adequately proves a theta bound will receive full points.

(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 a 3-part solution.

3
CS 170, Spring 2020 HW 1 A. Chiesa & J. Nelson

6 Polynomial Evaluation
Given coefficients a0 , . . . , an ∈ N, consider the polynomial:
n
X
p(x) = ak xk
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.

You might also like