algo test 2007

22
ALGORITHM TEST 3 12’ TH NOV’ 07 DURATION: 2 HOURS MAXIMUM MARKS:130 NAME: ROLL NO: PROBABILITY SECTION 1. In Delhi the mean before-tax personal income is Rs10, 000 and the standard deviation of the personal income is Rs4, 000. The minimum wage in Delhi is Rs 2000. The first Rs2000 of a person’s income is tax free but income tax is levied at the rate of 30 paisa on a Rupee on all personal income above Rs 2000. What is the mean and the standard deviation of after tax personal income (2 Marks) 2. An insurance company examines its pool of auto insurance customers and gathers the following information: (i) All customers insure at least one car. (ii) 70% of the customers insure more than one car. (iii) 20% of the customers insure a sports car. (iv) Of those customers who insure more than one car, 15% insure a sports car. 1

Upload: sumit-anand

Post on 07-Apr-2015

127 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: algo test 2007

ALGORITHM TEST 312’TH NOV’ 07

DURATION: 2 HOURSMAXIMUM MARKS:130

NAME: ROLL NO:

PROBABILITY SECTION

1. In Delhi the mean before-tax personal income is Rs10, 000 and the standard deviation of the personal income is Rs4, 000. The minimum wage in Delhi is Rs 2000. The first Rs2000 of a person’s income is tax free but income tax is levied at the rate of 30 paisa on a Rupee on all personal income above Rs 2000. What is the mean and the standard deviation of after tax personal income (2 Marks)

2. An insurance company examines its pool of auto insurance customers and gathers the following information:

(i) All customers insure at least one car.(ii) 70% of the customers insure more than one car.(iii) 20% of the customers insure a sports car.(iv) Of those customers who insure more than one car, 15% insure a sports car.Calculate the probability that a randomly selected customer insures exactly one car and that car is not a sports car.(A) 0.13(B) 0.21(C) 0.24(D) 0.25(E) 0.30 (2 marks)

1

Page 2: algo test 2007

3. Two instruments are used to measure the height, h, of a tower. The error made by the less accurate instrument is normally distributed with mean 0 and standard deviation 0.0056h. The error made by the more accurate instrument is normally distributed with mean 0 and standard deviation 0.0044h.

Assuming the two measurements are independent random variables, what is the probability that their average value is within 0.005h of the height of the tower?(A) 0.38(B) 0.47(C) 0.68(D) 0.84(E) 0.90 (2 Marks)

4.

(4 marks)

2

Page 3: algo test 2007

QUEUING THEORY SECTION

1) A repair man fixes broken televisions. The repair time is exponentially distributed with a mean of 30 minutes. Broken televisions arrive at his repair shop according to a Poisson stream, on average 10 broken televisions per day (8 hours).(i) What is the fraction of time that the repair man has no work to do?(ii) How many televisions are, on average, at his repair shop?(iii) What is the mean throughput time (waiting time plus repair time) of a television? (3 Marks)

Solution: (i) 3/8(ii) 5/3(iii) 80 minutes

2) In a gas station there is one gas pump. Cars arrive at the gas station according to a Poisson process. The arrival rate is 20 cars per hour. Cars are served in order of arrival. The service time (i.e. the time needed for pumping and paying) is exponentially distributed. The mean service time is 2 minutes.(i) Determine the distribution, mean and variance of the number of cars at the gas station.(ii) Determine the distribution of the sojourn time and the waiting time.(iii) What is the fraction of cars that has to wait longer than 2 minutes? (3 Marks)

Solution:

(i) P(L = n) = 1/3*(2/3)^n; n = 0; 1; 2….and hence E(L) = 2 and (L) = 6.

(ii) P(S <= t) = 1 – e-t/6; t >= 0; P(W<=t) = 1-2/3e-t/6 ;t >= 0;

(iii) 2/3e-1/3=0.48

(iv) p0 = 9/19; p1=6/19; p2=4/19; hence E(L) = 14/19 =0.737 and (L)= 22/19-

(14/19)2 =0.615.

(v) E(S) = 42/19 =2.21 minutes and E(W) = 12/19 = 0.63 minutes.

3

Page 4: algo test 2007

3) Given the average arrival and service rates as 6 per hour and 8 per hour respectively, what is the server utilization and probabilities of queue occupancy for zero, one, two, three and four or more jobs waiting at the server.(2 Marks)

Solution:

=4/7

P(0)=1- =3/7

P(1)= =3/7*4/7=12/49

P(2)= =3/7*16/49=48/343

P(2)= =3/7*(4/7)^3=192/2301

P(4 or more)=1-(p0+p1+p2+p3)=0.10315

SAMPLING

1. We wish to find the average price of fruits (orange, apples, and mango) in a city. For this, we adopt one of two schemes:

a. Randomly pick a fruit seller, and pick a fruit at random, check its price. We take the average of a large number of these observations.

b. Do (a) separately for oranges, apples and mangoes (i.e. in the first step, consider only oranges, in the second only apples, in the third only mangoes, etc), and finally take the average of all the individual averages. The total number of fruit prices sampled in both schemes is the same.

Are both schemes equally good, else which is better? Why? (2+3 Marks)

Solution: The first technique is Monte-Carlo sampling. The second one is stratified sampling. Both the techniques are NOT equally good. The second technique is better.

Stratified sampling gives a variance that is never larger than the variance in Monte-Carlo, but it gives smaller variance if the means of the stratified samples are different.

In this case, we will get more accurate answers with stratified sampling if the means of oranges, apples and mangoes are different, which they are most likely to be.

4

Page 5: algo test 2007

OPTIMIZATION SECTION

1. The technique/techniques used to handle uncertainty in optimization problems is/are: (1 mark)

a. Stochastic programmingb. Robust optimizationc. Bothd. None

Solution: c

2. Solve the following linear program using the tableau method (simplex algorithm).(5 marks) (4 marks if solved using graphical method)

Maximize 10 X1 + 5 X2

Subject to: X1 <= 2 X2 <= 3 X1 + X2 <= 4

Solution:

Standard form LP:Z – 10 X1 – 5 X2 = 0X1 + S1 = 2X2 + S2 = 3X1 + X2 + S3 = 4

X1 is the entering basic variable since it has the most –ve coefficient.MRT = RHS / coeff of entering basic variable.Winner of MRT test is the equation no 2.So S1 becomes leaving basic variable.

Basic variable

Equation no.

Z X1 X2 S1 S2 S3 RHS MRT

Z 1 1 -10 -5 0 0 0 0 -S1 2 0 1 0 1 0 0 2 2S2 3 0 0 1 0 1 0 3 InfiniteS3 4 0 1 1 0 0 1 4 4

5

Page 6: algo test 2007

Now doing the following row operations on the tableauR1 = R1 + 10 R2R4 = R4 – R2, we get the new tableau as follows:Here the entering basic variable is X2, since it has the most –ve coefficient.MRT = RHS / coeff of entering basic variable.Winner of MRT test is the equation no 4.So S3 becomes leaving basic variable.

Basic variable

Equation no.

Z X1 X2 S1 S2 S3 RHS MRT

Z 1 1 0 -5 10 0 0 20 -X1 2 0 1 0 1 0 0 2 Infinite S2 3 0 0 1 0 1 0 3 3S3 4 0 0 1 -1 0 1 2 2

Doing the row operations as follows, we get:R1 = R1 +5 R4R3 = R3 – R4

Basic variable

Equation no.

Z X1 X2 S1 S2 S3 RHS MRT

Z 1 1 0 0 5 0 5 30 -X1 2 0 1 0 1 0 0 2S2 3 0 0 0 1 1 -1 1X2 4 0 0 1 -1 0 1 2

Since now there is no –ve coefficient in the objective function row, the RHS of row 1 is the answer, that is 30.

3. Answer the following questions in context of linear programming: (6 marks)a. Name at least two techniques used to solve ILPs.(2 marks)

Branch and bound methodsCutting plane methods

b. For a multi-commodity flow problem, the flow equations when written in matrix form have what property (2 marks)

Block diagonal matrix

c. For a single commodity, the flow equations when written in matrix form have the property that …. (2 marks)

Uni-modular matrix. The elements are only 1’s and 0’s.

6

Page 7: algo test 2007

4. State TRUE or FALSE: (10 marks)a. Shortest Path problems can be reduced to flow problems. TRUEb. Flow problem with piecewise linear cost functions are a special case of

linear programming FALSEc. LP relaxation solution of an Integer linear program is obtained by solving

the same optimization, by ignoring all integer constraints. TRUEd. The LP relaxation solution is always different from the ILP solution.

FALSEe. The objective for the LP relaxation solution for an ILP minimization

problem is no more than the objective for the un-relaxed ILP. TRUEf. The integer solution for an integer linear programming problem can be

found just by rounding off the real solution. FALSEg. Branch and bound techniques are used to solve quadratic programming

problems. FALSEh. An optimization problem is specified as follows. Max cT x, subject to all

the constraints in A1x <= b1, and any one of the constraints in A2x <= b2 being true. This is a standard linear programming problem. FALSE

i. An optimization problem is specified as follows. Max cT x, subject to all the constraints in A1 x <= b1, and all of the constraints in CTx <= b2 being true. This is a standard linear programming problem. TRUE

j. To solve non-convex optimization problems, we require advanced AI techniques like simulated annealing and genetic algorithms, statistical learning theory, etc. TRUE

5. On a 1 GHz laptop with 1Gb of main memory, estimate the time taken to check if a given 100 element vector x is in the feasible region of Ax <= b, where A is a 100x 100 matrix. You should state your assumptions. What is the time if x is 1000 dimensional and A is 1000 x 1000. What is likely to happen in the latter case? Assume IEEE-754 double precision computation (64 bits per value) (3 + 3 + 4 = 10 marks).

Solution:1 instruction takes – 1 nanosecond.Number of instructions to compare Ax <= bA * x = 2 (100 * 100 * 100) = 2 *106 instructionsA * x <= b 100 instructionsTotal instructions: 2 * 106 + 100Total time 2 milliseconds

If x is 1000, A is 1000 * 1000, then:Total instructions: 2 * 109 + 1000Total time 2 secondsIn this case, memory will overflow.

7

Page 8: algo test 2007

6. For each of the following five (5) regions, specify if it is a. Describable by linear constraints, possibly with ANDs and ORsb. Convexc. Easy to Optimize over the region (no local optima which are not global

optima) (15 marks)Use the convention [(a), (c)] to mean that (a) and (c) are TRUE for the region, while (b) is FALSE. Please write your answer on each region itself. (1 mark for each answer, for each region – totally 3 marks for each region)

Solution: Figure 1: [b, c]Figure 2: [a, b, c]Figure 3: [none]Figure 4: [none]Figure 5: [a]

NUMERICAL ALGORITHMS SECTION

2. An N’th order polynomial is evaluated efficiently using: (1 mark)a. Singular value decompositionb. Jacobi transformationc. Horner’s ruled. None of the above

Some Pieces of Boundary Not Included in Set

8

Page 9: algo test 2007

Solution: c

3. Write the steps to find the singular value decomposition of the matrix

(2 marks)

I Find the eigenvalues of the matrix ATA and arrange them in descending order.II Find the number of nonzero eigenvalues of the matrix ATA.III Find the orthogonal eigenvectors of the matrix ATA corresponding to the obtained eigenvalues, and arrange them in the same order to form the column-

vectors of the matrix .

IV Form a diagonal matrix placing on the leading diagonal of it the

square roots of first eigenvalues of the matrix ATA got in I in descending order.

V Find the first column-vectors of the matrix :

 

VI Add to the matrix U the rest of m-r vectors using the Gram-Schmidt orthogonalization process.

4. Write an algorithm to evaluate a polynomial using the Horner’s method and compute the time and space complexity required for the same. (2 marks)

compute A[n–1]compute A[n–1]x + A[n–2]compute (A[n–1]x + A[n–2])x + A[n–3]compute ((A[n–1]x + A[n–2])x + A[n–3])x + A[n–4]and so on ...

Horner's algorithm:input xvalue := 0for i := (n–1) downto 0 do value := value ∗x + A[i]output valueTime: O(n).Space: O(1) space in addition to the O(n) space used by A.

9

Page 10: algo test 2007

5. While adding N terms by a computer, we add all small terms together and the large terms together and then add the two results. Why? (2 marks)

Solution:While adding N terms by a computer, if we add them all together, the small

terms will be swamped out by the large terms, leading to more errors. Thus, a better way is to add all small terms together, all large terms together and then add the two results. This will lead to smaller errors.

6. What is the problem in the following way of calculating the modulus of a complex number:

│a + ib│= √(a2 + b2)Can you suggest a better way to do this? (3 marks)

Solution:If a and b are large, then the term (a2 + b2) may over flow at the intermediate

step even though √(a2 + b2) does not overflow.

A better way to solve this is as follows:

│a + ib│= if b > a

= if a > b

7. Given the following system of linear equations, determine the value of each of the variables using the LU decomposition method. (4 marks)

6x1 - 2x2 = 149x1 - x2 + x3= 213x1 - 7x2 + 5x3= 9

Solution:

=

8. In context of continued fractions, answer the following questions: (4 marks)

10

Page 11: algo test 2007

a. Continued fractions are infinite representation of functions, which frequently converge where the power series does not. This statement is TRUE or FALSE? (1 mark) TRUE

b. For the continued fraction:

The value can be calculated from the double recursion (fill in the blanks) An = an * An-2 + bn * __An-1_____Bn = an * __Bn-2___ + bn * Bn-1 n = 1, 2, 3 ….

Where, A0 = b0, A-1 = 1, B0= 1, B-1=0

Write the recursion for the following continued fraction – you have to specify the recursion for arbitrary n.

9. State TRUE or FALSE: (6 marks)a. It is very difficult to find the inverse of a matrix with a large condition

number. TRUEb. Gauss-Jordan elimination technique is useful only in case of dense

matrices. TRUEc. LU factorization works very well with singular matrices. FALSEd. Centered technique for finding a derivative is less accurate than the

backward or the forward techniques. FALSEe. Multi-grid techniques have a better speed of convergence and give a

global view of the system. TRUEf. FTCS is always stable for a first order PDE ∂u/∂t = -v ∂u/∂x FALSE

11

Page 12: algo test 2007

10. Chebyshev polynomial of degree n is denoted by , and is given by the explicit formula (clearly it is always between -1 and 1):

(5+5 Marks)a. Prove the following expression for :

b. What happens if we directly calculate for x = 1000 (Hint: what is the leading power of x?)

Solution:a. We know that

Taking the equation , we get

cos((n+1) cos-1 x) + cos((n-1) cos-1 x)

= [cos(n cos-1 x) cos cos-1 x – sin(n cos-1 x) sin cos-1 x] + [cos(n cos-1 x) cos cos-1 x + sin(n cos-1 x) sin cos-1 x]

= [cos(n cos-1 x) cos cos-1 x] + [cos(n cos-1 x) cos cos-1 x]

= [cos(n cos-1 x) . x] + [cos(n cos-1 x) . x]

= 2 . cos(n cos-1 x) . x

= Tn(x)

Hence proved.

b.

12

Page 13: algo test 2007

If we directly calculate Tn(x) for x = 1000, then the leading term, that is 2n-1xn might overflow for a large n.

11. Name each of the following finite differencing diagrams. Briefly explain each one of them – you should write the equations – assume that the unknown in u(x,t), which is discretized to uj

n., the PDE is ∂u/∂t = -v ∂u/∂x (6 marks)

Specify the Courant-Frederich-Lax stability condition (3 marks)

If a 1 meter long section is being solved, with a velocity of propagation of 10 meters/second, and we use 1 mm resolution, what is the longest time step we can use? How many iterations are required to solve the system for 1 minute? What is the total data size (all u(x,t) calculated)? (2 + 2 + 2)

13

t (time)

X (space dimension)

Page 14: algo test 2007

Solution:

The finite differencing diagrams are:1. FTCS – LAX (Forward Time Centered Space with Lax correction)

2. FTCS (Forward Time Centered Space)

3. Staggered Leapfrog

Courant-Frederich-Lax stability condition:

12. In the SVD decomposition of a matrix A=UWVT, for two different matrices A1 and A2, we observe that

1. For A1, W is a identity matrix2. For A2, W is a identity matrix, except for one or two very small diagonal

elements of the order of 10-15. (1+2 Marks)a. For solving the equation Ax=b, where A is either A1 or A2, in which case

are we likely to get more accurate results?

Solution:We are likely to get more accurate results in the case of matrix A1 as the condition number for A1 is small. Condition number for A2 is large, resulting in larger errors for A2.

b. For solving the equations using A-1 = V W-1 UT, what step has to be taken to ensure accurate answers in each case (to the extent possible)

Solution:We can change the terms of the order of 10-15 to 0 in the matrix A2.

14

Page 15: algo test 2007

A.I . QUESTIONS

13. Write an algorithm to solve the sudoku problem. (4)

14. In a 2 player game like chess/ ichess what kind of algorithms will you use to achieve a winning position? (5)

15