0% found this document useful (0 votes)
61 views3 pages

Daa Assign1

The document describes several problems related to algorithms and asymptotic analysis: 1) It asks to express insertion sort recursively and derive its running time recurrence. 2) It asks to modify the MERGE procedure of merge sort to avoid sentinels. 3) It asks to describe an algorithm that determines if a set contains two elements summing to a given value x, in O(n lg n) time.

Uploaded by

Anbu Vasant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Daa Assign1

The document describes several problems related to algorithms and asymptotic analysis: 1) It asks to express insertion sort recursively and derive its running time recurrence. 2) It asks to modify the MERGE procedure of merge sort to avoid sentinels. 3) It asks to describe an algorithm that determines if a set contains two elements summing to a given value x, in O(n lg n) time.

Uploaded by

Anbu Vasant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Design and Analysis of Algorithms

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.

Problem 2-1. Asymptotic Notation


For each of the following statements, decide whether it is always true, never true, or sometimes
true for asymptotically nonnegative functions and  . If it is always true or never true, explain
why. If it is sometimes true, give one example for which it is true, and one for which it is false.
2

 
 
(a)
   
(b)  

!"#$%!"#
(c)
 '&(   $)* "# )
(d)  and  (note the little- )

+
 # ,$
+
- 
(e)  and 

Problem 2-2. Recurrences


"
Give asymptotic upper and lower bounds for .
 0/2143 in each of the following recurrences. Assume
that . is constant for . Make your bounds as tight as possible, and justify your answers.
 $5 6879: ;=< 
(a) . .
" '7 "6?>?"@;=<  
(b) . .
  "6?5?5A
(c) . .
"  CB D%;=< ;=< 
(d) . .
 E143 687?" 1GFIHCJ 
(e) . .
" $F "6?5?"@:K
(f) . .
  "6?5L B " B M 38N M
(g) . .
"  PO 5?@;=<
(h) . .
"  "6?>? N?6?>8"D%"
(i) . . .
"  B   B " 143838
(j) . .
Problem 2-3. Unimodal Search
1 TUT#WV
An array QSR is unimodal if it consists of an increasing
185*UTUT]T^sequence
_I` followed by a decreasing
sequence, or more precisely, if there is an index XZY\[ such that
a QSRcb Ved S Q Rcb
 1]V

for all
1f/ d
b X , and
a QSRcb e
V g  ]
1 V / dD
Q Rcb
S for all X b .
V
In particular, QSRcX is the maximum element, and it is the unique “locally maximum” element
Oj1]V  1]V
surrounded by smaller elements (QhRiX and QhRiX ).
1 TUTkV
(a) Give
-;=<"
an algorithm to compute the maximum element of a unimodal input array h
Q R
in time. Prove the correctness of your algorithm, and prove the bound on its
running time.
14l?3nm
A polygon is convex if all of its internal angles are less than
1 TUTkV
(and none of the edges cross each
other). Figure 1 shows an example. We represent a convex polygon as an array o R
qpe_rs
where
1]V p
each element of the array represents a vertex of the polygon in the form of a coordinate pair
1 TUT#WV.
We are told that o-R is the vertex with the minimum coordinate and that the vertices o R
p
are ordered counterclockwise, as in r the figure. You may also assume that the coordinates of the
vertices are all distinct, as are the coordinates of the vertices.
3

tfucx^w
tfui‚w
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 o R o R
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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy