Daa Assign1
Daa Assign1
Assignment-1
1.1
Insertion sort can be expressed as a recursive procedure as follows. In order to sort
A[1 . . n], we recursively sort A[1 . . n −1] and then insert A[n] into the sorted array
A[1 . . n − 1]. Write a recurrence for the running time of this recursive version of
insertion sort.
1.2
Rewrite the M ERGE procedure so that it does not use sentinels, instead stopping
once either array L or R has had all its elements copied back to A and then copying
the remainder of the other array back into A.
1.3
Describe a (n lg n)-time algorithm that, given a set S of n integers and another
integer x, determines whether or not there exist two elements in S whose sum is
exactly x.
1.4
Prove that the running time of an algorithm is (g(n)) if and only if its worst-case
running time is O(g(n)) and its best-case running time is (g(n)).
1.4
The recurrence T (n) = 7T (n/2)+n 2 describes the running time of an algorithm A.
A competing algorithm A has a running time of T (n) = aT (n/4) + n 2 . What is
the largest integer value for a such that A is asymptotically faster than A?
1.5
Use the master method to show that the solution to the binary-search recurrence T
(n) = T (n/2) + (1) is T (n) = (lg n).
1.6
Can the master method be applied to the recurrence T (n) = 4T (n/2) + n 2 lg n?
Why or why not? Give an asymptotic upper bound for this recurrence.
1.7
Consider the regularity condition a f (n/b) ≤ c f (n) for some constant c < 1, which
is part of case 3 of the master theorem. Give an example of constants a ≥ 1
and b > 1 and a function f (n) that satisfies a ll t he c onditions i n c ase 3 o f the
master theorem except the regularity condition.
(a)
(b)
!"#$%!"#
(c)
'&( $)* "# )
(d) and (note the little- )
+
# ,$
+
-
(e) and
tfucx^w
tfuiw
tfucy^w
tfuc^w
tfu{z#w
tfucv^w
t|uc}^w
tfu Uw
tfuc~^w
1 TUT_V 1]V
Figure 1: An example of a convex polygon represented by the array oR oR
p 1 TUT#V . is the vertex
with the minimum -coordinate, and oR are ordered counterclockwise.
p
;
<
(b) Give an algorithm to find the vertex with the maximum coordinate in time.
r
;
<
(c) Give an algorithm to find the vertex with the maximum coordinate in time.