QUESTION 1: JAVA PROGRAMMING Company XYZ has 243 blocks of building for its business operation, where each
Question:
QUESTION 1: JAVA PROGRAMMING Company XYZ has 243 blocks of building for its business operation, where each block has 7 floors. The distance between each floor is 7 meters.
The blocks are connected with each through an underground tunnel. The distance between blocks is 30 meters. Each block has its own server room for housing servers and network devices. Each floor has its own telecommunication closet and the floor can be occupied up to a maximum of 20 staffs. Company XYZ has 243 different departments as follow: A foyer at the entrance where the reception is 12 labs hosting sensitive measuring and analysis equipment, 12 office spaces with cubicles for the technicians and doctors, a board and meeting room, a mail room and a sample storage room Smart Builders must deploy their HVAC devices so that the temperature is always controlled. It turns out that their clients had very specific requirements which they presented in detail below. Compiler Construction Programming answers should be written in some notation approximating SML or OCaml. (a) Describe what is meant by tail recursion. [44 marks] (b) Eliminate tail recursion from foldl given below. Explain your answer. (* foldl : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a *) let rec foldl f accu l = match l with [] -> accu | a::l -> foldl f (f accu a) l [8 marks] (c) Eliminate tail recursion from the following mutually tail-recursive functions. Explain your answer. let rec is_even n = if n = 0 then true else is_odd (n - 1) and is_odd n = if n = 0 then false else is_even(n - 1) [8 marks] 4 CST.2016.3.5 4 Compiler Construction Consider writing a compiler for a simple language of expressions given by the following grammar, e ::= n (integer) | ? (read integer input from user) | e + e (addition) | e e (subtraction) | e e (multiplication) | (e, e) (pair) | fst e (first projection) | snd e (second projection) (a) Describe the tasks that should be carried in implementing a front end for this language and any difficulties that might be encountered. [45 marks] (b) Suppose that the target virtual machine is stack-oriented and that the stack elements are integer values, and addresses can be stored as integers. Explain which other features are required in such a virtual machine. Invent a simple language of instructions for such a machine and show how it would be used to implement each of the expressions. [10 marks] (c) Suppose that the following rules are proposed as possible optimizations to be implemented in your compiler. expression simplifies to expression (fst e, snd e) e fst (e1, e2) e1 snd (e1, e2) e2 Describe how you could implement these rules so that the simplifications are made only when the program's semantics is correctly preserved. [5 marks] 5 (TURN OVER) CST.2016.3.6 5 Concepts in Programming Languages (a) Explain what is meant by a monad in a programming language, giving the two fundamental operations of a monad along with their types. [3 marks] (b) Consider the use of a monad for input-output. For the purposes of this question, take the IO monad as including two operations readint and writeint which respectively read integers from stdin and write integers to stdout. Give the types of these operators. [2 marks] (c) Assume MLreadint and MLwriteint are primitives with side effects for inputoutput and consider the ML expression add1 of type int: let val x = MLreadint() in MLwriteint(x+1); x end (i) Give an equivalent expression which uses the IO monad instead of side-effects, and state its type. [3 marks] (ii) 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 = new Integer[11]; v = w; v[8] = n; v[7] = o;Suppose R is a rule that integrates constants exactly over [1, 1], and that f(x) is bounded and Riemann-integrable over [a, b]. Write down a formula for the composite rule (n R)f and prove that limn (n R)f = Z b a f(x) dx [6 marks] (d) What is the formula for (n Q)f over [a, b]? [4 marks] (e) Which polynomials are integrated exactly by Qf? Which monomials are integrated exactly by the product rule (Q Q)F when applied to a function of x and y? [3 marks] 9 [TURN OVER CST.2004.13.10 10 Introduction to Functional Programming (a) Define a polymorphic datatype 'a tree to represent binary trees. [1 mark] (b) A breadth-first traversal of a tree walks over all the nodes at each level before proceeding to the next level. For example the breadth-first traversal of the tree: 1 2 3 4 5 6 7 visits the nodes in the order 1, 2, 3, 4, 5, 6, 7. Define a function breadth: 'a tree -> 'a list such that breadth(t) returns the nodes of tree t in breadth-first order. [10 marks] (c) Define a polymorphic datatype 'a seq to represent lazy lists. [1 mark] (d) Define a polymorphic datatype 'a ltree to represent lazy binary trees. The token stream as information (by means of calls to work lex()) and giving as result an theoretical language structure tree relating to part (d). Notice both transcribed also, consequently created grammar analysers TLBs and caches are examples of content-addressable memories (CAMs). (a) 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(c,r,a,s); input c,r,a; output [2:0] s; reg [2:0] s; always @(posedge c or posedge r) if(r) s<=0; else begin if(a && (s<7)) 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? [5 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]? [12 marks] 2 CST.2011107.3.4 3 Data Structures and Algorithms (a) Describe how the Lempel Ziv text compression algorithm works, illustrating your answer by deriving the sequence of numbers and corresponding bit patterns it would generate when applied to a string starting with the following 24 characters: ABCDABCDABCDABCDABCDABCD ... You may assume that the initial table is of size 256 (containing bytes 0 to 255) and that the codes for "A", "B", "C" and "D" are 15, 16, 17 and 10, respectively. [12 marks] (b) Estimate how many bits the algorithm would use to encode a string consisting of 1000 repetitions of the character "A". [8 marks] 4 Comparative Programming Languages (a) Discuss to what extent a programmer can expect a program that conforms to a standard to generate identical results when run under different conforming compilers on different machines. [6 marks] (b) ALGOL 6110 provided call by value and call by name, Pascal provided call by value and call by reference, and ALGOL-W provided a variety of calling methods including call by result and call by value-result. 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 80 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] (ii) How could this problem be overcome? [2 marks] (d) The designer also wishes the real-time system.
The rudimentary clarification of the standards of how the language coming about because of part (b) may be utilized to make a sentence structure analyser taking a token stream as information (by means of calls to work lex()) and giving as result an theoretical language structure tree relating to.
Engineering Department, CEO/Vice Presidents office (Block C) Marketing and Sales Department (Block A) Finance and Human Resource Department (Block B)
Introduction to Management Science A Modeling and Cases Studies Approach with Spreadsheets
ISBN: 978-0078024061
5th edition
Authors: Frederick S. Hillier, Mark S. Hillier