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…
formula-1 we can get, ∑_(i=a)^n▒〖i 〗 = (∑_(i=1)^n▒〖i 〗) – (∑_(i=1)^(a-1)▒〖i 〗) = ( n(n+1)/2 ) – ( (a-1)(a-1+1)/2 ) = ( (n2 +n)/2 ) – ( (a2 –a)/2 ) = ( (n2 +n–a2 +a)/2 ) = ( (n2 –a2)+(n+a) )/2 = (n+a)(n–a+1)/2 So finally the deducted formula is as below, ∑_(i=a)^n▒〖i 〗= (n+a)(n–a+1)/2 Problem-2 Given that Algorithm 1 will perform f1(n) = n2+4n steps and Algorithm 2 will perform f2(n) = 39n + 4 steps for a problem of size n, for what values of n is Algorithm 1 faster than Algorithm 2? ANS: Given , Algorithm-1 => f1(n)=n2+4n Algorithm-2 => f2(n)=39n+4 In order for Algorithm-1 to be faster than Algorithm2, The number of steps in Algorithm-1 are less than the no of steps in Algoithm-2 So it deducts as, Speed of Algorithm-1 > Speed of Algorithm-2 No. of steps of Algorithm-1 < No.of steps of Algorithm-2 i.e. f1(n) < f2(n) => n2+4n < 39n+4 => n2+4n-39n-4 n2-35n-4n0. 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)▒i2 Θ(n2). Problem-4: Prove or disprove ∑_( i=1)^( n)▒i0 ∈ Θ(n2). ANS: Let f(n) = ∑_( i=1)^( n)▒i0 = n So f(n) = n And assume g(n) = n2 Inorder to show that ∑_( i=1)^( n)▒i0 ∈ Θ(n2).
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…
Algorithm-(1) void Naive(int x, int n) if n > 1 then value = x×Naive(x,n-1); endif if n = 1 then return x endif if n=0 then return 1 endif return value In the above case the Algorithm-1 The problem size reduces from n to n – 1 at every stage, and at every stage two arithmetic operations are involved (one multiplication and one subtraction).
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)
yields T(n ) = T(n – 2 ) + 2 (2) …(3) Also we note that T(n – 2 ) = T(n – 3 ) + 2 …(4) Substituting for T(n – 2 ) from relation(4) in relation (3) yields T(n ) = T(n – 3 ) + 2 (3) … (5) Following the pattern in relations (1) , (3) and (5), we can write a generalized relation T(n ) = T(n – k ) + 2(k) …(6) To solve the generalized relation (6), we have to find the value of k. We note that T(1) , that is the number of operations needed to raise a number x to power 1 needs just one operation. In other words T(1) = 1 ...(7) We can reduce T(n-k) to T(1) by setting n – k = 1 and solve for k to yield k = n – 1 Substituting this value of k in relation (6), we get T(n) = T(1) + 2(n – 1 ) Now substitute the value of T(1) from relation (7) to yield the solution T(n) = 2n– 1 ..(8) When the right hand side of the relation does not have any terms involving T(..), we say that the recurrence relation has been solved. We see that the algorithm is linear in n. Algorithm-(2) void RepeatedSquaring(int x,int n) if n > 1 then value = RepeatedSquaring (x,n/2)× RepeatedSquaring (x,n/2); endif if n = 1 then return x endif if n=0 then return 1 endif return value In the above Algorithm-2, At every step the problem size reduces to half the size. When the power is an odd number, an additional multiplication is involved. To work out time complexity, let us consider the worst case, that is we assume that at every step an additional multiplication is needed. Thus total number of operations T(n) will reduce to number of operations for n/2, that is T(n/2) with three additional arithmetic operations (the odd power case). We are now in a position to write the recurrence relation for this algorithm as T(n) = T(n/2) + 3 ..(1) T(1) = 1 ..(1) To solve this recurrence relation, we note that T(n/2) can be expressed as T(n/2) = T(n/4) + 3 ..(2) Substituting for T(n/2) from (2) in relation (1) , we get T(n) = T(n/4) + 3(2) By repeated substitution process explained above, we can solve for T(n) as follows T(n) = T(n/2) + 3 = [ T(n/4) + 3 ] + 3 = T(n/4) + 3(2) = [ T(n/8) + 3 ] + 3(2) = T(n/8) + 3(3) Now we know that there is a relationship between 3 and 8, and we can rewrite the recurrence relation as T(n) = T( n/ 23 ) + 3(3) We can continue the process one step further, and rewrite the relation as T(n) = T( n/ 24 ) + 3(4) Now we can see a pattern running through the various relations and we can write the generalized relation as T(n) = T( n/ 2k) + 3(k) Since we know that T(1) = 1, we find a substitution such that the first term on the right hand side reduces to 1. The following choice will make this possible 2k= n We can get the value of k by taking log of both sides to base 2, which yields k = log n Now substituting this value in the above relation, we get T(n) = 1 + 3 log n Thus we can say that this algorithm runs in LOGARITHMIC TIME, and obviously is much more efficient than the previous algorithm. Problem-6: For the following pseudo-code: 1 for i = 1 to n 2 for j = 1 to i 3 for k = 1 to j 4 print ”Hel lo , world ” (a) Exactly how many times is the print statement on line ?? executed? Your answer should be a function of n. (b) What is the run-time complexity of the code? ANS: for i = 1 to n for j = 1 to i for k = 1 to j print ”Hello , world” In the above pseudo code the there are 3 forloops nested so the possible no of iterations are occuring can be determined in the function of ‘n’ as below, The innermost loop will execute k=1,..,j means the no of inner loop iterations are, ∑_( k=1)^( j)▒〖(1〗) = j The inner 2nd loop will execute as follows, ∑_( j=1)^( i)▒〖( j〗 ) = i(i+1)/2=(i2+i)/2 The outer loop will execute as follows, ∑_( i=1)^( n)▒ ((i2+i)/2) ( ∑_( i=1)^( n)▒i2 + ∑_( i=1)^( n)▒i)/2 ( ( (n(n+1)(2n+1))/6 ) + ( n(n+1)/2 ) ) / 2 (2n3+6n2+4n+3) / 12 So finally it is a function of ‘n’ gives the no of times the print statement will be executed. F(n)= (2n3+6n2+4n+3) / 12 The run time complexity of above code is O(n3). Since it is a function of degree ‘3’.
4. An engine performs 5000 Joules of work in 20 seconds. What is its power output in kilowatts and in
Input : ( 3 x 412 ) + ( 463 ) + ( 360 ) + ( 496 x 1.5 ) = 2803
Then, to work out the total no. I added up all the numbers in the
where n is the number of half-lives that elapsed, T is the amount of time the radioisotope has decayed and (t)1/2 is the half-life of the nuclei, this is to determine the half-life of the radioisotope.
E.g. 5! = 5 x 4 x 3 x 2 x 1 5! = 120.
Step-Stair Investigation For my GCSE Maths coursework I was asked to investigate the relationship between the stair total and the position of the stair shape on the grid. Secondly I was asked to investigate the relationship further between the stair totals and the other step stairs on other number grids. The number grid below has two examples of 3-step stairs. I will use Algebra as a way to find the relationship between the stair total and the position of the stair on the grid.
...ter may use several words that can be grouped together into one word. An example of this would be :
Digits, add a previous carry and place the product to the left of the previous step's answer.
Processing time, which is sum of all cycle times, and lead time, which is sum of all processing time and queues times, are calculated. The maximum value added percentage is calculated as
Stiff, L. V. (2001, April). Making calculator use add up. NCTM News Bulletin. Retrieved from http://www.nctm.org/about/content.aspx?id=1242
1; :::; n. The denition of Vn(y) is the value obtained at the last time n, in state
3 + 5 + 4 + 4 + 5 + 3 + 4 + 5 + 4 + 4 + 5 + 4 + 5 + 5 + 4 + 4 + 4 + 2
Step 6: Next term is 1; we cannot divide 1 by 3 so take next term. Presently we have 13; we know that 4 times 3 = 12. Then we require to minus 12 from 13 = 1.
Fibonacci sequences are set of numbers based on the rule that each number is equal to the sum of the preceding two numbers; it can be also evaluated by the general formula where F(n) represents the n-th Fibonacci number (n is called an index), the sum of values in pascal`s triangle diagonal also demonstrates Fibonacci sequences. The presentation and report are designed to discover the application of Fibonacci sequences in daily life. The famous Fibonacci sequence has captivated mathematicians, artists, designers, and scientists for centuries therefore it is suggested as an important fundamental characteristic in real life.
Therefore, a number like 356 has a 3 in the hundreds place, a 5 in the tens place, and a 6 in the ones place. The digit 3, in the hundreds place, does not represent 3 as it represents 300. This idea is generally introduced in the lower elementary grades in order to help students manipulate numbers and solve problems. If a child understands that number 356 is actually 300+50+6, the student can play around with this number more easily. Understanding this concept might make it easier to add or subtract numbers, as well as use multiplication in the future grades – 365 x 3 = (300 x 3) + (50 x 3) + (6 x 3). The concept that numbers can be broken apart and put back together gives the student a more solid understanding of how different operations work. Not only that, but the student can also figure out how to solve problems independently by playing with the numbers (Rumack,