WL Question: Algorithms (a) Explain the greedy strategy in…
Question Answered step-by-step WL Question: Algorithms (a) Explain the greedy strategy in… WLQuestion:Algorithms (a) Explain the greedy strategy in algorithm design. To what problems does it apply? [3 marks] (b) If a problem can be solved with both dynamic programming and a greedy algorithm, what are the adv of up to a given amount of p pence. Its goal is to minimize the number of postage stamps issued, and the machine always has as many stamps as needed. (i) Let the set of available denominations for the stamps be D = {1p, 5p, 25p, 50p, £1, £2}. Can this problem be solved using bottom-up dynamic programming? If so, clearly describe your algorithm and determine its? complexity. If not, prove that it cannot be done. [5 marks] (ii) Let c1 < c2 < · · · < cn be n stamp denominations. Prove that if each ci (a positive integer) is a multiple of ci−1 for every i = 2, . . . , n then the greedy strategy applied to the set D = {c1, c2, · · · , cn} finds the optimal solution for any amount p that is a multiple of c1. [7 marks] (iii) Provide a set of denominations for stamps D and an amount of pence p for which the greedy strategy fails to give an optimal solution, p being a multiple of the smallest denomination in D. Show what solution the greedy strategy would find and what the optimal solutiony-list representation and the adjacency-matrix representation. Find a problem that can be solved more efficiently in the adjacency-list representation than in the adjacency-matrix representation, and another problem that can be solved more efficiently in the adjacency-matrix? representation than in the adjacency-list representation. [4 marks] (b) Prove or disprove (by giving a counter-example) the following claim: If a directed graph G contains a path from a vertex u to a vertex v, then any depth-first search must result in v.d ≤ u.f, where .d is the discovery time and .f the finishing time. [4 marks] (c) We are given an undirected, connected graph G = (V, E) with edge-weights w : E → R + and a minimum spanning tree T of G. How would you update your minimum spanning tree T in each of the following three cases? Specify the runtime of your algorithm and give a proof that the returned tree is indeed a minimum spanning tree. (i) We increase the weight of an edge e which is not in T. [3 marks] (ii) We decrease the weight of an edge e which is in T. [3 marks] (iii) We add a new edge e with weight w(e) to G. The weight w(e) is arbitrary, but for simplicity you may assume that after adding the edge e no two edges in G have the same weight. Assuming both operands are normalised and nonzero, what is the maximumdegree (number of shifts) of normalisation required in the result of a floatingpoint multiplication? Ignore zero and denormal results. [5 marks](b) A watertight capsule containing scientific instruments is dropped from ahigh-altitude plane into the ocean where it must approach close to the sea bottombefore floating up for retrieval by a boat. You are provided with subroutinesthat compute water and air resistance from velocity. Collision with the oceanbottom is a mission failure.(i) Set up a state vector and sketch code for a finite-difference, time-domainsimulation of the trajectory in one dimension. Include a check for missionfailure. [5 marks](ii) What three issues will affect your choice of simulation timestep?[3 marks](iii) Your simulation is now re-coded using interval arithmetic. New subroutinesfor resistance are provided with interval domain and range giving a pair withthe maximum and minimum resistance likely to be encountered. All inputparameters are likewise coded as pairs. Summarise how this will affect thestate vector and your code The Java class below defines a queue data structure with a fixed capacity. public class FixedCapacityQueue { int[] mData = null; int mHead=0; // index of first full cell int mTail=0; // index of next empty cell public FixedCapacityQueue(int capacity) { mData = new int[capacity]; } public boolean enqueue(int x) { if (mTail==mData.length) return false; mData[mTail]=x; mTail++; return true; } public int dequeue() { if (mTail==mHead) return -1; int v=mData[mHead]; mHead++; return v; } } (a) Explain the risks posed by the lack of access modifiers specified on the state. Which access modifier is appropriate for these entities? [3 marks] (b) Discuss the choice to signal enqueue and dequeue errors using return values of false and -1, respectively. Suggest a better alternative and modify enqueue and dequeue to use it. [5 marks] (c) Explain how an enqueue operation on a FixedCapacityQueue object could fail with an error even when there are fewer items in the queue than the assigned capacity of the object. Show how to fix this. [3 marks] (d) Rewrite the class to use Java's Generics so that it can be used to represent queues of arbitrary objects (Integers, Strings, etc). Use the java.util.ArrayList class instead of int[] for the type of mData. [4 marks] (e) Explain why it was necessary to replace the int[] type of mData in part (d), and why ArrayList does not suffer from the same issue. [5 marks] 3 (TURN OVER) CST.2015.1.4 4 Object-Oriented Programming A developer wishes to create a photo library application that can auto-detect faces in images to assist labelling. They wish to use some commercially available Java face detection software. The source to this software is unavailable—only the Java bytecode and documentation are supplied. The two key classes are as follows: Class name Method prototype Image // Constructor public Image(byte[] imageData, int w, int h) // Get the image value at pixel (x,y) public byte getPixel(int x, int y) // Set the image pixel at (x,y) to value val public void setPixel(int x, int y, byte val) // Get the image width public int getWidth() // Get the image height public int getHeight() Algorithm // Search for and mark the faces in Image im public static void markFaces(Image im) (a) Explain what is meant by source code, machine code and Java bytecode. Give two advantages of distributing Java software as bytecode rather than source code. [5 marks] (b) Explain why markFaces() is declared static. [1 mark] (c) The developer wishes to add filename information in the form of a String to all of the Image instances. Show how to achieve this efficiently using inheritance. [4 marks] (d) The developer wishes to know whether the markFaces() method visits every pixel in the image or uses a more intelligent search strategy. Provide a new class definition that can be used to determine the search sequence. Your class should be able to temporarily augment an Image object with logging capabilities while it is being processed by markFaces(). [Hint: Explain how shared data can be protected through the use of objects. [8 marks] The built-in facilities for restricting concurrency in Java allow only one thread at a time to be executing within the critical region.readers may share access at the same time, but only one writer may acquire exclusive access (excluding any readers while it does so). Specify a MultiSync class in Java with methods to acquire and release both read and write access, and sketch its implementation. [6 marks] Derive a MultiBuffer class that extends MultiSync with methods to store and read a data field, ensuring that any locks are released when a waiting thread is interrupted. Your example may use a simple data field such as an integer but you should explain why such an elaborate scheme of concurrency control is unnecessary in this case. [6 marks] 2 CST.99.4.3 4 Compiler Construction It is commonly suggested that Algol-60 call-by-name can be modelled by passing a function as a call-by-value parameter. Show how a program containing a definition int f(int x:name) { ... x ... x ... } of f (where x occurs only in Rvalue context) and a call f(e) to f can be replaced by an equivalent definition and call using only call-by-value. [6 marks] Most such explanations assume that the uses of x within f occur only in Rvalue context. However, Algol-60 also permits the equivalent of int g(int x:name) { if (p) { ... x := x+1; x := -x; ... } return x; } and calls like g(a[k()]) which, when p is true, would have the effect of calling k() five times and consequent access to five (possibly different) subscripts of array a[]. Develop your explanation for the first part of this question to cover also the case of a call-by-name parameter being used in both Lvalue and Rvalue contexts. [Hint: note that when p is false then the actual parameter to g need not be an Lvalue, so you may need two parameterless procedure arguments ("thunks").] [8 marks] Using the previous part or otherwise, give a translation of a definition and call h(e) using call-by-value-result (Ada in out mode) with no uses of the address-of (&) operator other than those involved in call-by-name. Your explanation is allowed to deviate from call-by-value-result by allowing side-effects in e to take place twice. [6 marks] 5 Data Structures and Algorithms Outline the mechanism used in the Burrows-Wheeler block compression algorithm, illustrating your description by applying it to the string ALFALFA. [14 marks] Briefly discuss the advantages and disadvantages of the Burrows-Wheeler algorithm compared with other commonly used compression methods. [6 marks] 3 [TURN OVER CST.99.4.4 6 Computer Design A modern processor's memory is constructed from a hierarchy of memories. Explain what the levels of the hierarchy are. [5 marks] Why do modern processors have several registers rather than an accumulator plus one or two index registers? [5 marks] Hand compile the following pseudo-code for both a register machine and an accumulator machine of your choice. You may invent an instruction set. Make the semantics of the code clear via comments. a=0; b=1; for(i=0; i<5; i++) { a=a+b; b=a-b; } [10 marks] 7 Operating System Functions The following are three ways which a file system may use to determine which disk blocks make up a given file. (a) chaining in a map (b) tables of pointers (c) extent lists Briefly describe how each scheme works Additional hint on notation: s u = path from s to u consisting of 0 or moreedges (0 when s ≡ u); u → v = path from u to v consisting of precisely oneedge; d[u] = weight of the shortest path found so far from source s to vertexu; δ(s, v) = weight of shortest existing path from s to v.](c) Why does the algorithm require non-negative edge weights? [2 marks](d) Would the algorithm work if the only negative weights were on edges leavingthe source? Justify your answer with a proof or counterexample. [5 marks](e) Consider the following approach for finding shortest paths in the presence ofnegative edges. "Make all the edge weights positive by adding a sufficientlylarge biasing constant to each; then find the shortest paths using Dijkstra'salgorithm and recompute their weights on the original graph." Will this work?Justify your answer with a proof or counterexample. [3 marks]2CST.2006.5.32 Computer Design(a) Why do pipelines exhibit branch and load delays? [6 marks](b) What impact does pipeline length have on clock frequency? [4 marks](c) Why might a shorter pipeline result in a more power-efficient design?[4 marks](d) Recently we have seen microprocessor manufacturers release dual-processorchips where each processor has a shorter pipeline than the earlier singleprocessor per chip designs. What sort of applications might run better onthe older chips and vice versa? [6 marks]3 Digital Communication I(a) Describe the concepts of circuit switching and packet switching. [5 marks](b) What are the fundamental advantages of each over the other? [5 marks](c) What is the role of buffering and buffering policy in each approach? [5 marks](d) There is an expectation that in the near future telephony will move from circuitswitching to packet switching. Why is this so in light of the advantages of eachapproach? [5 marks]3 (TURN OVER)CST.2006.5.44 Concurrent Systems and Applications(a) The following Java interface describes the API for a first-come, first-served(FCFS) mutual exclusion system, designed to work even if threads areinterrupted in the enter and exit routines.interface FCFS {public void enter();public void exit();}Sketch a concrete class, FCFSImpl, implementing this interface, which does notneed to be re-entrant, ensuring that you satisfy the following requirements:(i) if a thread is interrupted while executing the entry protocol, it shouldabort its attempt to gain entry and cleanly terminate the call; you mayassume that the calling code will not then enter the critical region;[6 marks]>(ii) the exit protocol should notify a particular thread and not simply callnotifyAll(). [6 marks](b) Object allocation graphs can be used to detect deadlock in a concurrentapplication.(i) Give an example of an object allocation graph and explain the meaningsof the different components. [2 marks]?(ii) Describe an algorithm which can use an object allocation graph and anobject request matrix to determine whether or not deadlock exists.[5 marks](iii) Describe how to distinguish between cases in which deadlock has occurredand those in which deadlock is inevitable but is yet to occur. [1 mark]4CST.2006.5.5SECTION B5 Computer Graphics and Image Processing(a) Give the definition of the cubic Be0zier curve. [4 marks](b) Derive the conditions necessary to ensure that two cubic Be0zier curves joinwith C1-continuity. [6 marks](c) Describe, in detail, an algorithm for drawing a cubic Be0zier curve to a giventolerance using straight lines. You may assume that you already have analgorithm for drawing a straight line. [6 marks](d) Explain why and how homogeneous co-ordinates are used in computergraphics. [4 marks]6 Compiler Construction(a) Consider the grammarS ::= (L) | aL ::= L, S | S(i) Present a right-most derivation for the string (a, ((a, a), (a, a))).[3 marks](ii) Present a left-most derivation for the same string (a, ((a, a), (a, a))).[3 marks](b) Automatic garbage collection is an important technique for the implementationof many programming languages. Define each of the following variations:(i) Mark and Sweep; [3 marks](ii) Copy Collection; [3 marks](iii) Generational Collection. [3 marks](c) Write a small program that will produce different values depending on whichkind of variable scoping mechanism is used, static or dynamic. Explain youranswer. [5 marks]5 (TURN OVER)You may find it useful to apply a common design pattern.] [10 marks] 4 CST.2015.1.5 SECTION C 5 Numerical Methods (a) Consider the iteration: xn+1 = (2xn + N/x2 n )/3 (i) The iteration converges to give what useful property of the constant argument N? [2 marks] (ii) Examine whether the above iteration should work for all possible values of N and x0? [6 marks] (iii) Find the order of convergence for the above iteration. You may use standard results but do not simply state an order without justification. [3 marks] (b) Cholesky provides an approach to solving certain systems of simultaneous equations. His method (and similar methods) perform upper/lower triangle decomposition of the equation coefficient matrix A such that A = LU and U T = L. (i) Under what circumstances can Cholesky’s method be used? Can it be used if A is already a triangular matrix and, if not, what should be done instead? [3 marks] (ii) Give expressions for two of the four values in the upper-left 2×2 sub-matrix of L in terms of the elements of A coarse estimate of the total run-time for the factoriser in circumstances when the input number has exactly two large prime factors, and an equally crude estimate of the size that N would need to be before the factorisation process took a whole day of CPU time on a modern desktop workstation. You may suppose that around 1013 basic operations are available in that amount of time. [5 marks] 5 [TURN OVER CST.98.8.6 7 Optimising Compilers (a) Define the notion of an expression being available at a node in a flowgraph in terms of possible execution flows of control; explain carefully the form which available expressions might take in your framework. [4 marks] (b) Demonstrate that calculating exactly which expressions are available at a given node is uncomputable (you may assume that it is uncomputable to determine whether two given boolean expressions involving arithmetic always yield the same result value). [4 marks] (c) Give an algorithm to calculate available expressions and state carefully how the algorithmic result is related to the set of expressions which are available according to your definition in part (a). [4 marks] (d) Justify any discrepancy in (c) by reference to safety of the approximation with respect to the usual use of available expressions in optimisation. [4 marks] (e) On a machine with four registers available for register allocation (by colouring), give a program for which common sub-expression elimination (CSE) results in worse code being generated than if CSE had not been performed, noting any assumptions of timing factors for the target machine which justify the code being worse. Problem Space (or Search Space) (o) Non-Monotonic Reasoning [2 marks each] 7 [TURN OVER CST.98.8.8 9 Database Topics What are the aims of the Object Database Standard ODMG 2.0? [3 marks] Describe the ways in which the Standard contributes to Object-Orientated Distributed Programming, making particular reference to distribution and heterogeneity. [5 marks] What benefits does conformance to the Standard bring to the application developer? It may be helpful to consider (a) schema definition and maintenance (b) transaction management (c) object interchange format (d) interoperation with relational data storage [12 marks] 10 Information Retrieval You work for a company that takes news stories from all over the world and provides reports on specified topics to customers, for example on political developments in the new Republic of Rumbaza during 1997. Your company’s staff use a retrieval system to extract the material on which they base their reports from the company’s very extensive archive of stories. The retrieval system is a 20-year-old makeshift and is to be scrapped. You are asked to design the new retrieval system. (a) Give a detailed description of the retrieval devices the new system will offer, explaining why they are available and how they will work. What facilities will the user have for modifying his or her search specification in response to system output? [15 marks] (b) What do you regard as the most difficult problem to be tackled, and why? [5 marks] [Assume that the stories in the file are texts ng, with date and source headers in a standardised form.] 8 CST.98.8.9 11 Information Theory and Coding Consider a binary symmetric communication channel, having source alphabet X = {0, 1} with probabilities {0.5, 0.5}. Its output alphabet is Y = {0, 1} and its channel matrix is 1 − 1 − where is the probability of transmission error. (a) What is the entropy of the source, H(X)? [1 mark] (b) What is the probability distribution of the outputs, p(Y ), and the entropy of this output distribution, H(Y )? [3 marks] (c) What is the joint probability distribution for the source and the output, p(X, Y ), and what is the joint entropy, H(X, Y )? [4 marks] (d) What is the mutual information of this channel, I(X; Y )? [2 marks] (e) How many values are there for for which the mutual information of this channel is maximal? What are those values, and what then is the capacity of such a channel in bits? [3 marks] (f ) For what value of is the capacity of this channel minimal? What is the channel capacity in that case? [2 marks] The Fourier transform (whether continuous or discrete) is defined in the general case for complex-valued data, which gets mapped into a set of complex-valued Fourier coefficients. However, we are often concerned with purely real-valued data, such as sound waves or images, whose Fourier transforms we would like to compute. What simplification occurs in the Fourier domain as a consequence of having real-valued, rather than complex-valued, data? The original MIPS architecture (as implemented in the R2000) relied on software interlocking of pipeline stages, thus exposing load and branch delays to the compiler which is then responsible for scheduling instructions to avoid conflicts. Assess the pros and cons of software interlocking at the time of the introduction of the R2000. How has the situation changed for modern high-performance MIPS implementations? [6 marks] 4 ECAD Topics Explain the purpose and principles of fault simulation in electronic CAD. Why is it difficult to implement efficiently? [4 marks] Describe the following three techniques for fault simulation: (a) parallel fault simulation [4 marks] (b) concurrent fault simulation [4 marks] (c) deductive fault simulation [4 marks] Which of these schemes would be suitable for higher-level functional units rather than gates? In particular, how would they handle logic blocks with internal state? [4 marks] 3 [TURN OVER CST.98.7.4 5 Denotational Semantics Suppose that D is a domain and that lam : (D → D) → D and app : D → (D → D) are continuous functions. Using D, lam and app, you are required to give a denotational semantics to the terms of the untyped lambda calculus: M ::= x | λ x (M) | M M, where x ranges over some fixed, infinite set of variables and where terms are identified up to alpha-conversion. For each term M and list ~x = x1, . . . , xn of distinct variables containing the free variables of M, define a continuous function ρ 7→ [[~x ` M]](ρ) mapping elements ρ of the product domain Dn (regarded as functions from {x1, . . . , xn} to D) to elements of D. The definition should proceed by induction on the structure of M and you should state clearly, but without proof, any properties of continuous functions between domains which are needed for the definition to make sense. [10 marks] Show, by induction on the structure of M, that the following substitution property holds: [[~x ` M[M0 /x]]](ρ) = [[~x, x ` M]](ρ[x 7→ [[~x ` M0 ]](ρ)]). (You may assume without proof that [[~x, x ` M]](ρ[x 7→ d]) = [[~x ` M]](ρ) when x does not occur free in M.) [5 marks] Show that if the composition app ◦ lam is the identity function on the function domain D → D, then the denotational semantics respects beta-reduction, in the sense that [[~x ` (λ x (M)) M0 ]](ρ) = [[~x ` M[M0 /x]]](ρ). [3 marks] What condition on lam and app will ensure that eta-reduction, λ x (Mx) → M (where x is not free in M), is respected? [2 marks] 6 Artificial Intelligence Describe, with examples, four problems that might be encountered when attempting to use automatic planning techniques. [5 marks per problem] 4 CST.98.7.5 7 Neural Computing In Computer Science, a fundamental distinction has classically been erected between computing and communications. The former creates, requires, or manipulates data, and the latter moves it around. But in living neural systems, this distinction is less easy to establish; a given neurone performs both functions by generating nerve impulses, and it is not clear where to draw the distinction between processing and communication. The problem is even more obvious in artificial neural networks, where the entire essence of computing is modelled solely as changes in connectivity. Flesh out and discuss this issue. Would you argue that some of the limitations of efforts in artificial intelligence have been the result of such a spurious dichotomy? [20 marks] 8 Database Topics Describe the main features of the Data Language DAPLEX, paying particular attention to the following points: (a) schema definition and maintenance (b) primitive and derived data (c) entity specialisation (d) consistency constraints [9 marks] Explain how aggregates are handled in DAPLEX, paying particular attention to the following: (e) composition of many-valued functions (f ) calculation of averages (g) inverse functions (h) multiple inheritance Computer Science Engineering & Technology C++ Programming COMPUTER S 1359 Share QuestionEmailCopy link Comments (0)


