Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
1. You are given an array A of n distinct positive integers.
(a) Design an algorithm which decides in time O(n2
log n) (in the
worst case) if there exist four distinct integers m; s; k; p in A
such that m2
+ s = k + p2
(10 points)
(b) Solve the same problem but with an algorithm which runs in the
expected time of O(n2
). (10 points)
2. You are given a set of n fractions of the form xi=yi (1 i n), where xi
and yi are positive integers. Unfortunately, all values yi are incorrect;
they are all of the form yi = ci+E where numbers ci 1 are the correct
values and E is a positive number (equal for all yi). Fortunately, you are
also given a number S which is equal to the correct sum S = Pn
i=1 xi=ci.
Design an algorithm which nds all the correct values of fractions xi=ci
and which runs in time O(n logminfyi : 1 i ng). (20 points)
3. You are given an array A consisting of n positive integers, not neces-
sarily all distinct. You are also given n pairs of integers (Li; Ui) and
have to determine for all 1 i n the number of elements of A which
satisfy Li A[m] Ui by an algorithm which runs in time O(n log n).
(20 points)
4. You are given an array containing a sequence of 2n 1 consecutive
positive integers starting with 1 except that one number was skipped;
thus the sequence is of the form 1; 2; 3; : : : ; k 1; k+1; : : : ; 2n. You have
to determine the missing term accessing at most O(n) many elements
of A. (20 points)
5. Read about the asymptotic notation in the review material and deter-
mine if f(n) = O(g(n)) or g(n) = O(f(n) or both (i.e., f(n) = (g(n)))
or neither of the two, for the following pairs of functions
(a) f(n) = log2(n); g(n) = 10
pn; (6 points)
(b) f(n) = nn; g(n) = 2n log(n2)
; (6 points)
(c) f(n) = n1+sin(n)
; g(n) = n: (8 points)
You might nd useful L’H^opital’s rule: if f(x); g(x) ! 1 and they are
dierentiable, then limx!1 f(x)=g(x) = limx!1 f0
(x)=g0
(x)