What values do sep[1,2,3,4,5,6,7,8] and sep[1,2,3,4,5,6,7] yield?…
Question Answered step-by-step What values do sep[1,2,3,4,5,6,7,8] and sep[1,2,3,4,5,6,7] yield?… What values do sep[1,2,3,4,5,6,7,8] and sep[1,2,3,4,5,6,7] yield? [4 marks] Deduce the ML type of merge and explain why the omission of ‘: int list’ would lead to an error [2 marks] Give an ML definition of the standard library function map. [2 marks] Describe what the function s does and explain why it works. [8 marks] 3 [TURN OVER CST.94.1.4 6 The following ML declaration introduces a data type that can be used to represent a potentially infinite arrangement of cells at positions with integer coordinates in the first quadrant of the x ? y plane: datatype A = Z | Cell of int ref * A ref * A ref; Each cell contains an integer value and pointers to the cells immediately to its right and above itself. These three components are all mutable so that the arrangement of the cells and the integers they contain can change during use. The codnstructor Z can be used in an A ref to allow a cluster to have a boundary rather than continuing through unbounded chains of cells. Define a function mkrow(n) of type int->A that will return a row of length n + 1 cells initialised with zeros. For instance: mkrow(1) = Cell(ref 0, ref(Cell(ref 0, ref Z, ref Z)), ref Z) [5 marks] Define a function zip(row1, row2) of type A*A->A that will return row1 with row2 joined above it. This function is entitled to change some of the ref A pointers in row1. For example val root = zip(mkrow(3), mkrow(2)); would give root a value representing the following arrangement. 0 ? 0 ? 0 ? ? ? root : 0 ? 0 ? 0 ? 0 [5 marks] Next define a function mkarr(m,n) of type (int*int)->A that will return a value representing a rectangular array of n + 1 rows each of which are of length m + 1 in which each cell is initialised to zero [5 marks] Paths originating from the bottom leftmost cell (which will be referred to by the variable root) are represented by values of the type dir list where dir is declared as follows: datatype dir = Right | Up; Finally define a function inc path cells of type A->A list->unit that will increment the integers in all the cells that lie on a specified path within a given collection of cells. For instance after root had been set up as above, the two calls 4 CST.94.1.5 inc path cells root [Right, Up, Right]; inc path cells root [Right, Right, Right]; would leave root representing the following arrangememay assume that the path does not try to reach cells outside the given arrangement. [5 marks] 7 Show, by defining suitable selector and constructor functions, how the ML type defined as follows: datatype L = N of int * unit->L; can be used in the representation of lazy integer lists. [5 marks] Define a function makeseq(f) that will yield a lazy list representing the following infinite sequence: 0, f(0), f(f(0)), … where the integer at position i has the value f i (0). Concepts in Programming Languages (a) Give an overview of the execution models (abstract machines) associated with Fortran, Lisp, Algol-60, Pascal, C, ML and Java. (These are not necessarily distinct.) Mention how storage allocation and deallocation is performed. [4 marks] (b) Explain to what extent the above languages: (i) provide static scoping [2 marks] (ii) provide static type checking [2 marks] (iii) are type-safefor each language either state it to be type-safe or sketch a type-unsafe program [4 marks] (c) In Algol, functions can be passed as arguments to functions but the type only mentions the result type of such a function formal parameter, whereas in ML more detail is given. Which is better, and why? [2 marks] (d) Array types in object-oriented languages can be seen as generic classes having read and write operations. Java arrays are described as covariant. Contrast th The following is a quotation from an Internet forum on cryptography.Cracking RSA is NP-complete so nothing better than brute force ispossible.Your task is to evaluate to what extent (if any) this statement is true. For fullmarks, you will consider the following questions. What would it mean, precisely, for “cracking RSA” to be NP-complete? Inparticular, what is the decision problem involved and what is meant by sayingit is NP-complete? Is the problem, in fact, NP-complete? Why or why not? What is meant, precisely, by the conclusion, “nothing better than brute forceis possible”? Assuming the premise is correct, i.e. “cracking RSA is NP-complete”, does theconclusion follow? Why or why not? What is the relationship, more generally, between encryption systems andNP-completeness? You work at a social media company, and your task is to detect cyberbullyingmessages based on the text they contain. You have access to a large number ofmessages, N, which have been manually labelled as “OK” and “bullying”.(a) How can you apply a Naive Bayes classifier to the task and evaluate it? Describethe approach, including how you would estimate the parameters. [3 marks](b) You decide to use precision and recall instead of accuracy as the evaluationmetric for this task. Why does this decision make sense, and how are the metricscalculated? [1 mark](c) Your colleague wants to hire two more human annotators to re-label yourtraining data. Why might this be a good idea, how would you measure agreementin this task, and do you think this would improve your classifier in any way?[3 marks](d) Due to repeated media coverage of cyberbullying, your company introduces anew policy stating that as many cyberbullying messages as possible are to befound and deleted, while still making sure the number of non-filtered messagesremains high. Some additional manual labour is made available for this change.How does this affect your evaluation strategy, and how can you adapt theclassifier to comply better with the new strategy? (Tip: a development corpuscould be of use.) [4 marks](e) You realise that in this particular application, language change might cause theperformance of your trained classifier to drop considerably over time. You havesome manual labour available to address the problem, but not enough to relabellarge amounts of text.(i) Why is language change relevant here, and how might you notice it?[2 marks](ii) How could you efficiently build a “cyberbullying lexicon” containing wordsthat have been found in recent cyberbully incidents? [3 marks](iii) How can you use lexicon-based information to make your classifier morerobust towards language change?(a) Recall that a Boolean formula is in 3-CNF if it is the conjunction of clauses,each of which is the disjunction of at most three literals. A literal is either avariable or a negated variable.Consider the following two decision problems:3-SAT: given a Boolean formula in 3-CNF, decide whether or not it issatisfiable.3-VAL: given a Boolean formula in 3-CNF, decide whether or not it isvalid.(i) One of the two problems above is known to be in the complexity class P.Which one, and why? [2 marks](ii) Describe a polynomial time algorithm for the problem you identified inpart (i). [6 marks](iii) What can you say about the complexity of the other problem? Stateprecisely any standard results you use in your answer. [4 marks](b) Say that a Boolean formula is in 3-DNF if it is the disjunction of terms, eachof which is the conjunction of at most three literals.We now consider the following two decision problems:3-DNF-SAT: given a Boolean formula in 3-DNF, decide whether or not itis satisfiable.3-DNF-VAL: given a Boolean formula in 3-DNF, decide whether or notit is valid.What can you conclude about the complexity of these two problems?[8 ma (a) Briefly describe what is meant by synchronous logic. Show how a Master-SlaveD-type Flip-Flop may be constructed from two transparent D-latches anddescribe its operation with the help of a timing diagram. [7 marks](b) With the use of appropriate diagrams, briefly explain the operation of Mooreand Mealy finite state machines, paying particular regard to their differences.[4 marks](c) A two-bit synchronous binary Up/Down (U/D) counter is capable of eitherup-counting (e.g., 0, 1, 2, 3, 0, . . .) or down-counting (e.g., 3, 2, 1, 0, 3, . . .) andrandomly changes between these two modes of operation. It has outputs Xand Y , where X is the Most Significant Bit (MSB).The U/D counter is connected to a count Direction Detection System (DDS)that has two outputs, namely CU and CD, where CU is required to give a binary1 pulse when the U/D counter up-counts and CD is required to give a binary 1pulse when the U/D counter down-counts, otherwise the two outputs are bothto remain at binary 0.Assume that the count DDS has two state registers, each implemented as aD-type Flip-Flop (FF). The next state outputs of each FF, namely QX and QYare given by the current inputs to the DDS, i.e., the U/D counter output bitsX and Y respectively. Also assume that the FFs in the count DDS are clockedat a much higher rate than the U/D counter.(i) Draw a state diagram for the count DDS, where the arcs connecting thestates show the bits X and Y input to the count DDS, and also the outputsignals CU and CD. Define a resource in a digital communication system as anything whose use by oneinstance of communication prevents simultaneous use by another. Channel capacityis one example.(a) Give two more examples of resource in digital communication systems.[4 marks](b) For the three resources, indicate how the amount of total resource can beincreased. [6 marks](c) How are allocations of each of these resources to instances of communicationperformed? [10 marks]4 Concurrent Systems and ApplicationsA system is to support abortable transactions that operate on a data structure heldonly in main memory.(a) Define and distinguish the properties of isolation and strict isolation. Nowadays, timepieces (such as clocks, wristwatches, etc.) have a variety of functions. They not only tell the time and date but they can speak to you, remind you when it’s time to do something, and provide a light in the dark, among other things. Mostly, the interface for these devices, however, shows the time in one of two basic ways: as a digital number such as 23:40 or through an analog display with two or three hands – one to represent the hour, one for the minutes, and one for the seconds. In this question, we ask you to design a new timepiece for your own use. This could be in the form of a wristwatch, a mantelpiece clock, an electronic clock, or any other kind of timepiece you fancy. (a) Think about the interactive product you are designing: describe what you want it to do for you. Write a list of functional and non-functional requirements. [4 marks] (b) Sketch out an initial low-fidelity prototype for the timepiece and develop at least two distinct alternatives that both meet your set of requirements listed above. [8 marks] (c) Nielsen’s heuristics used for Heuristic Evaluation are: (1) visibility of system status, (2) match between system and real world, Computer Science Engineering & Technology Object-Oriented Programming MATHS 24 Share QuestionEmailCopy link Comments (0)


