You are on page 1of 4

Course: Analysis & Design of Algorithms (3466) Semester: Autumn 2020

ASSIGNMENT No. 1
Q. 1 Does every problem has an algorithm? And can we write a computer program for every
algorithm?

Ans. No not all problems have algorithms.. Algorithm is a systematic approach to attempt to
some problems.. We generally use algorithms in bigger/complex problems. However it
is not necessary you always follow algorithm in every problem. You can go with your
own logic sometimes, depending on the situation and requirement. But in that case you
should make sure your logic handles all the cases efficiently. This might be more
tedious and time taking. So we prefer algorithms because they have already been tested
and verified.

Q. 2 Express the function in terms of -notation:

Solution:
n3 2
−100 n −100 n+3
1000
We have,
n3 2 3
−100 n −100 n+3=Θ(n )
1000
n3 2
f ( n )= −100 n −100 n+3
1000
g(n)=n3
3 n3 2 3
C1n ≤ −100 n −100n+ 3≤ C 2 n
1000
For the right side,
3 n3 2
C2n ≥ −100 n −100 n+3
1000
3 n3
C2n ≥ +3
1000
1
C2≥ +3
1000
C 2=4
For the left side,
3 n3 2
C1n ≤ −100 n −100n+ 3
1000
3 n3 2
C1n ≤ −100 n −100n
1000
3 n3 2
C1n ≤ −100 n −100n
1000
1
C1≤ −100 n−100 n2
1000
1
C1≤
2000
The answer is Θ(n3).

Q. 3 Let f(n) and g(n) be asymptotically nonnegative functions. Using the basic definition of
0-notation, prove that max(f(n), g(n)) =  f(f(n) + g(n)).

Sol. From "asymptotically non-negative", we can assume that ∃n 1 , n2:

f ( n ) ≥ 0 ; for n>n1

g ( n ) ≥0 ; for n> n2

Let n0 =max ( n1 , n2 )

Some obvious things for n> n0:

f (n)≤ max ⁡(f ( n ) , g(n))

g(n)≤ max ⁡(f ( n ) , g( n))

f ( n ) + g( n)
≤max ⁡( f ( n ) , g( n))
2

max ⁡(f ( n ) , g(n))≤ f ( n )+ g (n)

From the last two inequalities, we get:


0 ≤ 12(f ( n ) + g ( n ) )≤ min( f ( n ) , g ( n )) for n> n0
Which is the definition of Θ(f (n)+ g(n)) with c 1=1/2 , c 2=1

Q. 4 Use Strassen's algorithm to compute the following matrix product and show your work:
1 3 6 8
( )( )
7 5 4 2

Sol. Let, (17 35)(64 82)=( CA DB )


Using Strassen’s Algorithm compute the following –

M 1 :=( 1+7 ) × ( 6+ 8 )=8 × 14=112


M 2 :=( 3+5 ) × ( 4+2 ) =8 ×6=48
M 3 :=( 1−5 ) × ( 6+2 )=−4 × 8=−32
M 4 :=1× ( 8−2 ) =6
M 5 :=( 7+5 ) × 6=72
M 6 :=( 1+3 ) ×2=8
M 7 :=5 × ( 4−6 ) =−10
Then,
I ≔ M 2 + M 3−M 6−M 7=18
J ≔ M 4 + M 6=14
K ≔ M 5+ M 7 =62
L ≔ M 1 −M 3 −M 4−M 5=66

( CA DB )=( 1862 1466)


Q5 How many people must there be in a room before the probability that someone has
the birthday as you do is at least ½? How many people must there be before the
probability that at least two people have a birthday on July 4 is greater than ½ ?

Sol. Part 1:

p(at least 1 out of n people has your birthday )


¿ 1− p ¿ of the n people has your birthday ¿

Therefore, we can calculate the least n so that:

Observe that,
p¿
and plug this into (1) while taking the logarithm:
364
n ln <ln ( 0.5) Because 364/365<1 , thelast equation transform ¿ :
365
ln ( 0.5 )
n> =252.65 2
364
ln( )365
The least such n is therefore n = 253.
The final answer depends upon whether you include yourself or not, it is either 253 or
254.

Part 2:
Let us denote with X the random variable of number of people having the 4 th July s their
birthday. X is binomial random variable with the parameter p = 1/365, and therefore:
n n−k
()
P(X=k) = p k (1− p)
k
with the integer n representing the total number of people in the room.
The goal is to determine the least n for which:
P( X =0)+ P(X =1)< 0.5
And we are done.
Calculate:
364 n−1 1
P( X =0)+ P(X =1)=
n−1
365( ) 365
364 n
¿( )
365
364 +
365
Now you can make a program in your favorite language that starts at n = 1 and goes up
until the above expression becomes smaller than 0.5.
The answer is
n = 613
As we get
612−1
364 612
¿ ( )
365
613 −1
364+
365
=0.5002212992272963>0. 5

364 61 3
¿ ( )
365
364+
365
=0.4993619475679456<0. 5

Result:
1) 254
2) 613

You might also like