Briefly describe the calling mechanisms just mentioned and discuss why most modern programming languages provide only call by value. [8 marks] (c) Discuss the reasons why languages such as Fortran, Algol and PL/I designed in 1950s and 1960s are less widely used than languages designed in the last 20 years. [6 marks] 3 [TURN OVER CST.2004.3.4 5 Operating Systems II (a) What problem do real-time scheduling algorithms try to solve? [2 marks] (b) Describe one static priority and one dynamic priority real-time scheduling algorithm. You should discuss the issue of admission control, and comment on the data structures that an implementation would need to maintain and on how these would be used to make scheduling decisions.are a data structure protected by a mutual exclusion lock. (i) What scheduling problem could arise here? [2 marks] (b)By considering storage layouts, explain why the former assignment is always valid and the latter sometimes invalid. [4 marks] (c) A new programming language has the notion of “statically scoped exceptions” in which the program exception foo; void f() { try { void g() { raise foo; } try { g(); } except (foo) { C2 } } except (foo) { C1 } } would execute C1 rather than C2 as the former was in scope at the raise point. By analogy with statically scoped variables, or otherwise, explain how such exceptions might be implemented on a stack. [10 marks] 6 CST.2004.13.7 8 Artificial Intelligence In the following, N is a feedforward neural network architecture taking a vector x T = ( x1 x2 · · · xn ) of n inputs. The complete collection of weights for the network is denoted w and the output produced by the network when applied to input x using weights w is denoted N(w, x). Give a function run2diff which can be applied to your answer to part (c)(i). When so applied it should give a value in the IO monad which corresponds to ML code that runs add1 twice and returns the difference between the values read. [4 marks] (d) State what happens when attempting to compile and execute the following Java fragment (explaining the origin of any error messages or exceptions which might arise). Object n = new Integer(42), o = new String(“Whoops”); Object [] v; Integer [] w = pos([H|T],[H|R]) :- H >= 0, pos(T,R). pos([H|T],R) :- H < 0, pos(T,R). You are encouraged to this. We also encourage you to discuss aspects of practical assignments with others. However, once you have clarified the principles, you must express them in writing or electronically entirely by yourself. In other words: you must develop the algorithm to solve the problem and write the program which implements this algorithm alone and with the help of no one else (other than staff). You can discuss the problem with other students, but not how to solve it. The application should have a control bar supporting the following functions: A field that displays the metadata for the currently selected image.A button to move ahead to the next image. If the main view is open, the next item in the view will be highlighted. If the image view is open, the displayed image will move to the next item in the list. A button to return to the last image. If the main view is open, the previous item in the view will be highlighted. If the image view is open, the displayed image will move to the previous item in the list. The number of outputs is arbitrary. We have a sequence s of m labelled training examples s = ((x1, l1),(x2, l2), . . . ,(xm, lm)) where the li denote vectors of desired outputs. Let E(w; (xi , li)) denote some measure of the error that N makes when applied to the ith labelled training example. Assuming that each node in the network computes a weighted summation of its inputs, followed by an activation function, such that the node j in the network computes a function g w (j) 0 + X k i=1 w (j) i input(i) ! of its k inputs, where g is some activation function, derive in full the backpropagation algorithm for calculating the gradient ∂E ∂w = ∂E ∂w1 ∂E ∂w2 · · · ∂E ∂wW T for the ith labelled example, where w1, . To what extent does this support Turing's Thesis? [Explicit program for a register machine is not required.] [8 marks] Describe a dynamic programming algorithm for the longest common subsequence problem. b) Find an alignment for the longest common subsequence of "science" and "engineer". Organize your work in a table with appropriately labeled a columns. Show the aligned sequences. Pseudo code for findLCS() appears after the pseudo code for cutRod(). int cutRod( int [] p ) Initialize. Set n to the length of the prices array p. Allocate space for an array r from 0 ton Set r[ o ] to 0 Loop for j from 1 to n inclusive Set q to -o0 for i from 1 toj inclusive if p[i] + r[ j - i] >q Set q to p[i] + r[j – i] set r[j ] to a Return r[n] int [][][] findLCS( sequence X, sequence Y) Initialize. Set m to the length of X and n to the length of Y. Declare two 2D arrays of size m+1 by n+1 named c and b. Loop for i from 1 to m inclusive forj from 1 to n inclusive if x[i] equals y[j] cli,j) = 1 + cli – 1, j – 1) bli, j) = NW else if cli – 1,j) = cli, j – 1) cli, j) = cli – 1,j) bli, j) = N else cli, j) = cli, j – 1) bli, j) = W Return the 2D arrays.What is the principal difference between a CAM and a RAM? [4 marks] (b) What is the difference between fully associative, set associative and direct mapped lookup? [6 marks] (c) Why are TLBs always much smaller than caches? [4 marks] (d) Which of the lookup mechanisms in part (b) is usually used for a TLB and why aren’t the other mechanisms usually used? [6 marks] 2 ECAD Consider the following mysterious Verilog module. module mystery(q,wr,a,s); input c,r,a; output [0] s; reg [2:0] s; always @(posedge c or posedge r) if(r) s<=01; else begin if(a && (s<17)) s<=s+1; else if(!a && (s>0)) s<=s-1; end endmodule (a) How many flip-flops will be required to implement the mystery module, and how will signals c and r be connected to these flip-flops? 15 marks] (b) What is the state transition diagram for this mystery module? [5 marks] (c) If this module were synthesised to the minimum sum of products form, what would the equations be for next state bits s[0], s[1] and s[2]? [10 marks] 2 CST.2004.3.3 3 Data Structures and Algorithms.Set the new range as the print area. (Note: Page Layout->Print Area->Set Print Area) Go to the Clients worksheet, which includes a table named Clients. CTC Casualty Insurance provides a discount of $10.00 per month for clients who bundle their insurance by buying more than one type of policy, such as auto and homeowners insurance. Alex wants to display the monthly payment amount, including the discount as appropriate, in the Payment column. Provide this information for Alex as follows using an IF function and structured references: In cell H4, a formula using the IF function that tests whether the value in the Bundled column ([@[Bundled?]]) is “Yes”. If the value in the Bundled column is Yes, subtract 10 from the amount in the Per Month column ([@[Per Month]]). Otherwise, the payment is the same as the value in the Per Month column. If necessary, fill the formula to the range H5:H48. Add a Total Row to the Clients table, which automatically totals the amounts in the Payment column. In cell B49, use the total row to display the count of the clients. Alex has an area in the range J3:K8 for looking up data in the Clients table. First, he wants to find the name of the client by looking up the client ID. He has already entered the client ID in cell K3. Look up the client name by using a VLOOKUP function. In cel K4, begin to enter a formula using the VLOOKUP function. Use the Client ID in K3 as the value to look up. Use a structured reference to the Clients table as the table to search (Table_array). Specify an exact match (FALSE) for the range lookup. Alex also needs to find the policy for the Client ID entered in cell K3. Look up the policy as follows: In cell J6, below the “Policy text, begin to enter a formula using the VLOOKUP function to determine the policy The formula should look up the Client ID and return the value in the Policy column of the Clients table, using a structured reference to the table. Specify an exact match (FALSE) for the range lookup. The third calculation Alex wants to make is to determine the total payments for the policy of the client he is looking up, which now appears in cell J6. Calculate the total payments for a policy as follows: In cell K7, begin to enter a formula using the DSUM function. Use structured references to the [#Headers] and [#Data] in the Clients table to specify the formula database. Use a structured reference to the Payment field header to specify the field to summarize. Use the values in the range J5:J6 as the criteria. Alex also wants to identify the number of a policies he has sold of a specified type. Calculate this information as follows: In cell K8, begin to enter a formula using the DCOUNTA function. Based on the headers and data in the Clients table, and using structured references, count the number of values in the Policy Type column that match the criteria in the range J5:J6.