11.07.2015 Views

CMPUT 204 – Problem Set 1

CMPUT 204 – Problem Set 1

CMPUT 204 – Problem Set 1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>CMPUT</strong> <strong>204</strong> <strong>–</strong> <strong>Problem</strong> <strong>Set</strong> 1(Preparation for quizzes on Monday (09/25), Tuesday (09/26), and Wednesday (09/27))Scope. Continuing the review of inductive proofs and basic mathematical relations thatarise frequently in the analysis of algorithms, problems on asymptotic notations, and designand analysis of simple algorithms.1. Solve the following problems (review the formulas in Appendix A):n∑(a) Find a closed form expression for 3 · i + 3 i .i=2(b) Find a closed form expression for 1 + 3 + 5 + · · · + 2n − 1 for n ≥ 1 and provethe result by induction.(c) Prove n! > 2 n for sufficiently large n by induction. Reminder: n! = n · (n − 1)!for n > 0 and 0! = 1. Pronounced: “n factorial”.2. For each of the following pairs of functions f(n) and g(n), n > 0, either f(n) ∈ O(g(n))or g(n) ∈ O(f(n)), but not both. Determine which is the case. Justify your answers.(a) f(n) = n + lg n, g(n) = n √ n.(b) f(n) = n 1/3 + lg n, g(n) = (lg n) 2 .3. Give, in O-notation, the worst case number of times operation ⊕ is executed. Youmay assume that all variables are integers. Justify your answers.(a) procedure p1 (n: integer);beginfor i:= 1 to n-1 dofor j:= i+1 to n dofor k:= 1 to j dox := x ⊕ j ⊕ k;end(b) procedure p2 (n: integer);beginfor i:= 1 to n doif odd(i) then beginfor j:= i to n dox:= x ⊕ 1;for j:= 1 to i doy:= y + 1;endend1


4. Design an algorithm for the following problem: given a set of n points in the plane,determine whether all of them lie on the same circle circumference. Organize youranswer in three sections:• Basic idea (English prose)• Commented pseudo-code of the algorithm• Runtime analysisNote: it is very important for the marker to get most of the structure of your algorithmfrom your description of the basic idea (without having to read the pseudo-code).Give a simple (yet tight) O-expression of the running time T (n) as a function of thenumber of input points n. You may analyze the algorithm based on the numberof operations involving the points (e.g., computing a distance between two points,comparing the coordinates of two points, etc.)2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!