Pt1420 Unit 2 Math Paper

1545 Words4 Pages

Homework-1

Problem-1:
Produce a simple formula for

∑_(i=a)^n▒〖i 〗
where a, n € Z and 1 ≤a≤n.
ANS:
Given Equation we have to find out the summation of natural numbers starting from ‘a’ to ‘n’.
Which can be written as below,
(1) ∑_(i=a)^n▒〖i 〗 = (∑_(i=1)^n▒〖i 〗) – (∑_(i=1)^(a-1)▒〖i 〗)

As we generally know the equation for sum of ‘N’ natural numbers is

(2) ∑_(i=1)^n▒〖i 〗 = n(n+1)/2
From above equations we can able to apply formula -2 in …show more content…

We have to show,
C1.g(n)≤f(n) ≤C2.g(n) for all n≥n0
C1(n2) ≤ n ≤ C2(n2) for all n≥n0 ….(1)

To satisfy this inequality (1) simultaneously, we have to find the value of C1,C2 and ,n0 using the following inequality
C1(n2) ≤ n ………(2)
n ≤ C2(n2) ………(3)
Inequality (2) is not satisfied for any values of C1,n0 for n≥n0
Inequality (3) is satisfied for a value of C2=1 and n0=1.
So both inequalities (2) and (3) are not satisfied simul-taneously, So it is clear that f(n) ≠ Θ(g(n)).Which clearly implies that,
=>f(n) ∈ Θ(g(n)) is Incorrect.
=>f(n) Θ(g(n))

∑_( i=1)^( n)▒i0 Θ(n2).

Problem-5:
Write pseudo-code for each of the following two algorithms to raise an
integer to an integer power. In both cases, assume n = 2m. Analyze
the run-time complexity of each algorithm in therms of the number of
multiplications performed (determine _(n)).

(a) Na¨ıve:
xn = x × xn−1
x0 = 1

(b) Repeated Squaring:

xn = (xn/2)2
x0 = 1
ANS:
Here firstly generating pseudo code for both algorithms, …show more content…

Thus total number of operations needed to execute the function for any given n, can be expressed as sum of 2 operations and the total number of operations needed to execute the function for n-1. Also when n=1, it just needs one operation to execute the function
In other words T(n) can be expressed as sum of T(n-1) and two operations using the following recurrence relation:

T(n) = T(n – 1 ) + 2

T(1) = 1

We need to solve this to express T(n) in terms of n. The solution to the recurrence relation proceeds as follows. Given the relation

T(n) = T(n – 1 ) + 2 ..(1)

we try to reduce the right hand side till we get to T(1) , whose solution is known to us. We do this in steps. First of all we note (1) will hold for any value of n. Let us rewrite (1) by replacing n by n-1 on both sides to yield

T(n – 1 ) = T(n – 2 ) + 2 …(2)

Substituting for T(n – 1 ) from relation (2) in relation (1)

Open Document