WL A simple implementation uses two iterations. In the first…
Question Answered step-by-step WL A simple implementation uses two iterations. In the first… WLA simple implementation uses two iterations. In the first iteration, we add each element’s value as a key and its index as a value to the hash table. Then, in the second iteration, we check if each element’s complement (target – nums[i]target−nums[i]) exists in the hash table. If it does exist, we return current element’s index and its complement’s index. Beware that the complement must not be nums[i]nums[i] itself!They open only after the correct decimal code has been entered. The VS100 – a low-cost civilian model – expects a 6-digit code. After all six digits have been entered, it will either open or will signal that the code was wrong and ask for another try. The VS110 – a far more expensive government version – expects a 40-digit code. Users of a beta-test version of the VS110 complained about the difficulty of entering such a long code correctly. The manufacturer therefore made a last-minute modification. After every five digits, the VS110 now either confirms that the code has been entered correctly so far, or it asks for the previous five digits again. Compare the security of the VS100 and VS110?. [4 marks]b. A program is being developed to assist with the processing of examination marks. A test program begins as follows?public class Exam { private static Mark[] question = {new Mark(8), new Mark(), new Mark(6), …The program makes use of a class Mark which begins?class Mark { public boolean attempted; public int score; …The Mark array question has one entry for each candidate so the length of the array indicates the total number of candidates.?An entry such as new Mark(8) sets up a Mark object whose data field attempted is set to true and whose data field score is set to 8, indicating that the candidate attempted the question and was awarded 8 marks. It may be assumed that every score is an integer in the range 0 to 10 inclusive.An entry such as new Mark() sets up a Mark object whose data field attempted is set to false (and whose data field score is arbitrary) indicating that the candidate did not attempt the question.(a) Supply suitable constructors for class Mark [4 marks](b) Write two methods int getCount() and double getMean() which, when handed the actual argument question, return the number of candidates who attempted the question and the mean mark achieved by those candidates respectively. If no candidates attempted the question? getMean() should return -1d. [9 marks](c) Write method int[] getRank() which begins:private static int[] getRank(Mark[] q) { int[] rank = {0,0,0,0,0,0,0,0,0,0,0};This method should return the int array rank with each element rank[i] set to the number of candidates who scored more than i marks. Note that if the maximum score is 9 then both rank[9] and rank[10] will be zero and rank[8] will be the number of candidates who scored 9. [7 marks](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 65, 66, 67 and 68, 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]5 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 60 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 20 years. [6 marks](a) Describe a scheduling algorithm with the following properties:• favours I/O-intensive processes • responds dynamically when processes change their behaviour: e.g. enter a compute-bound or I/O-intensive phase• has acceptable context switching overhead • avoids indefinite overlook (starvation) of a process[7 marks](b) In order to carry out its functions, a filing system holds metadata on each stored object.(i) What is this metadata likely to comprise? [6 marks](ii) Describe the directory service functions of a filing system, including how the metadata is used. [7 marks](a) For Single Precision in the IEEE binary floating-point standard (IEEE 754) the precision is defined as 24, and the exponent requires 8 bits of storage. With reference to IEEE Single Precision, explain the terms exponent, significand, precision, sign bit, normalised number, denormal number. [6 marks](b) Explain the term hidden bit. What are the values of the hidden bit for normalised and denormal numbers? How is the exponent stored and why? How are the exponent, significand and sign bit arranged in memory? [4 marks](c) Let x∗ denote the floating-point representation of a number x. Define the terms absolute error (εx) and relative error (δx) in representing x. How are εx and δx related? Define machine epsilon (εm). [3 marks](d) Assume δx = δy = δz = εm. Using worst-case analysis, estimate δxy, εxy. Find an expression for δw where w = z−xy. [4 marks] (e) Working to 4 significant decimal digits only, compute w∗ when x∗ = 2.018, y∗ = 2.008,z∗ = 4.058. Given εm ‘ 0.5×10−3, how many significant decimal digits of w∗ can be relied on? [3 marks]8 Mathematics for Computation TheoryLet A,B,C be sets. Define the Cartesian product (A×B) and the disjoint union (A + B). [3 marks]Let f ⊆ (A×B),g ⊆ (B×C) be relations between A and B, B and C respectively. Define the inverse relation f−1 between B and A and the product relation (f ◦g) between A and C. [3 marks]What conditions must be satisfied for the relation f to be a function f : A → B? [2 marks]Write that (A → B) for the set of all functions from A to B. If A,B are both finite, |A| = a,|B| = b, how many elements are there in (A×B), (A + B)t turns out we can do it in one-pass. While we are iterating and inserting elements into the hash table, we also look back to check if current element’s complement already exists in the hash table. If it exists, we have found a solution and return the indices immediately?”A”, “B”, “C” and “D” are 65, sixty six, 67 and sixty eight, respectively. [12 marks](b) Estimate what number of bits the algorithm would use to encode a string such as one thousand repetitions of the man or woman “A”. [8 marks]five Comparative Programming Languages(a) Discuss to what volume a programmer can expect a software that conforms to a wellknown to generate identical effects whilst run underneath different conforming compilers on different machines. [6 marks](b) ALGOL 60 supplied call via fee and make contact with via name, Pascal supplied name with the aid of price and speak to with the aid of reference, and ALGOL-W furnished a diffusion of calling techniques consisting of name by result and speak to via value-end result. Briefly describe the calling mechanisms just cited and talk why most modern-day programming languages offer most effective name by using price. [8 marks](c) Discuss the motives why languages which include Fortran, Algol and PL/I designed in Nineteen Fifties and Nineteen Sixties are less extensively used than languages designed within the final two decades. [6 marks](a) Describe a scheduling set of rules with the following houses:• favours I/O-in depth approaches • responds dynamically whilst approaches exchange their behaviour: e.G. Enter a compute-sure or I/O-in depth section• has appropriate context switching overhead • avoids indefinite forget (hunger) of a method[7 marks](b) In order to carry out its capabilities, a filing system holds metadata on each stored object.(i) What is that this metadata probably to contain? [6 marks](ii) Describe the listing carrier capabilities of a filing machine, which include how the metadata is used. [7 marks](a) For Single Precision within the IEEE binary floating-point standard (IEEE 754) the precision is defined as 24, and the exponent calls for 8 bits of garage. With reference to IEEE Single Precision, give an explanation for the terms exponent, significand, precision, sign bit, normalised quantity, denormal number. [6 marks](b) Explain the term hidden bit. What are the values of the hidden bit for normalised and denormal numbers? How is the exponent saved and why? How are the exponent, significand and signal bit organized in reminiscence? [4 marks](c) Let x∗ denote the floating-factor representation of a variety of x. Define the phrases absolute error (εx) and relative error (δx) in representing x. How are εx and δx related? Define system epsilon (εm). [3 marks]?(d) Assume δx = δy = δz = εm. Using worst-case analysis, estimate δxy, εxy. Find an expression for δw where w = z−xy. [4 marks] (e) Working to four significant decimal digits handiest, compute w∗ while x∗ = 2.018, y∗ = 2.008,z∗ = four.058. Given εm ‘ zero.Five×10−3, what number of significant decimal digits of w∗ can be depended on? [3 marks]eight Mathematics for Computation TheoryLet A,B,C be sets. Define the Cartesian product (A×B) and the disjoint union (A + B). [3 marks]Let f ⊆ (A×B),g ⊆ (B×C) be members of the family between A and B, B and C respectively. Define the inverse relation f−1 among B and A and the product relation (f ◦g) between A and C. [3 marks]What situations must be satisfied for the relation f to be a function f : A → B? [2 marks]Write that (A → B) for the set of all capabilities from A to B. If A,B are bothAwhat number of elements are there in (A×B), (A + B), (A → B)? [2 marks] If f and f−1 are both features, we are saying that f is a bijection, and we write A ∼ = B. If A,B are both finite and f : A → B is a bijection, show that a = b. (?) [2 marks] Establish express bijections between the subsequent pairs of units:(a) A → (B×C), (A → B)×(A → C); [3 marks] (b) (A + B) → C, (A → C)×(B → C). [4 marks] If A, B, C are all finite, affirm that the cardinality condition (?) above is satisfied in every case. [1 mark]nine Computation Theory(a) What is Turing’s Thesis? [2 marks](b) Explain the movement of a Turing gadget that is specified through a quintuplet description. [4 marks](c) Define the configuration of a Turing gadget at step t, and set up equations that specify the configuration of a okay-image Turing device at step (t +1) in terms of the configuration at the previous step t. [6 marks]?(d) Explain how you’ll use your equations to simulate a specific Turing system with the aid of a check in device whose software encodes the quintuplet description. To what volume does this help Turing’s Thesis? [Explicit program for a register machine is not required.] [8 marks]Describe an set of rules for appearing scan conversion of a fixed of 3-d polygons, together with info of clipping, projection, and the underlying .RKthe stack arising from a top-down parse of the two sentences. [4 marks] (e) How might the sentence in Part (a)(ii) be altered so that it has the same meaning but is easier to process? Explain your reasoning. [4 marks] 5 (TURN OVER) CST1.2018.7.6 4 Further Graphics (a) Here are two methods for implementing a cube using signed distance fields: float methodOne(vec3 p) { return max(max(abs(p.x), abs(p.y)), abs(p.z)) – 1; } float methodTwo(vec3 p) { vec3 d = abs(p) – vec3(1); return min(max(d.x, max(d.y, d.z)), 0.0) + length(max(d, 0.0)); } One is preferable to the other for producing better images faster. Which one, and why? [4 marks] (b) Complete the code below to implement the signed distance field function for a finite line segment with hemispherical end-caps (Figure 1) of arbitrary start point, end point, and radius. [4 marks] float lineSegment(vec3 p, vec3 start, vec3 end, float radius) { // [YOUR CODE HERE] } float getSdf(vec3 p) { return lineSegment( p, vec3(-PI, 0, 0), vec3(PI, 0, 0), 0.5); } (c) Implement a version of getSdf() that doubles the height of your line segment and translates it by −0.5 along the Z axis, to be centred at (0, 0, −0.5) (Figure 2). [4 marks] (d) Implement a version of getSdf() that warps the original line segment into a sine wave sin(X) (Figure 3). [4 marks] (e) Modify getSdf() to render the sine wave model subtracted from the taller model (Figure 4). (a) Write a GLSL function dartboard() which takes as input a texture co-ordinate texCoord which ranges from (0, 0) → (1, 1), and returns the colours of the procedural texture for a black-and-white dartboard pattern of 16 squares around and 8 squares in radius (see figure below). The background behind the dartboard is gray. vec3 dartboard(vec2 texCoord) { // [YOUR CODE HERE] } [6 marks] (b) What is . . . (i) the formula for the face angle α(F, vi) of face F at vertex vi of a closed manifold? [2 marks] (ii) the formula for the angle deficit AD(v) of vertex v and its surrounding set of faces {F}? [2 marks] (iii) the formula for the Poincar´e Formula of a surface with genus g and Euler characteristic χ? [2 marks] (iv) the formula for Descartes’ Theorem of Total Angle Deficit? [2 marks] (c) Consider a closed manifold surface with total angle deficit −4π. (i) If your hypothetical surface has 20 vertices and 20 faces then how many edges must it have? [2 marks] (ii) Sketch a picture of your surface. [4 marks] 8 CST1.2018.7.9 6 Further HCI (a) Explain in general how the actions that a user takes are related to the user’s goals. Your answer should make reference to the function of perception, and to the nature of the cognitive processing that must occur. [8 marks] (b) Describe a class of problems for which it is not possible to formulate goals. Give a specific example of a problem in this class, and with reference to that example, explain how it illustrates two significant attributes of the class. [6 marks] (c) If an interactive system has several alternative models to describe the user’s goal, how can Bayes’ theorem be used to improve the system usability? [6 marks] 9 (TURN OVER) CST1.2018.7.10 7 Further HCI Imagine that you have been asked to implement a radical new design of your college website. The Senior Tutor has decided that, to make the college seem friendlier, the home page and navigation should be implemented using a group photograph of all members of the college that was taken last summer. Your task is to design graphical content that will be overlaid onto the photograph to provide all necessary information and navigation. (a) Draw a sketch showing the main graphical features of your proposed design. (A few stick figures will be adequate to represent the original photograph. No additional marks will be given for realistic depictions of members of your college.) [4 marks] (b) Explain how the display plane of the photograph has been segmented in your proposed design, including explanation of any visual marks that were used to achieve this segmentation. [6 marks] (c) Choose five specific visual aspects of your proposed design, and for each of these five: (i) Describe the graphical property used to implement this aspect (by reference to your sketch); and (ii) Explain the mode of correspondence between this graphical property and the meaning that is intended in this aspect of your design. [10 marks] 10 CST1.2018.7.11 8 Prolog In this question you should ensure that your predicates behave appropriately with backtracking. You may not make use of extra-logical built-in predicates such as findAll. Use of the cut operator is permitted unless specified otherwise. You may ignore the possibility of overflow or division by zero. (a) A term can either be an atom, variable or a compound term. Define each of these. [3 marks] (b) Euclid’s algorithm for computing the greatest common divisor of two integers can be implemented in ML as: fun gcd(a,0) = a | gcd(a,b) = gcd(b, a mod b); Provide an implementation in Prolog without using the cut operator. [4 marks] (c) We can represent fractions using the compound term div/2. For example div(1,3) represents 1 3 . Implement a predicate simplify which transforms a fraction into its smallest exact representation. For example, simplify(div(8,4),B) should unify B with 2, and simplify(div(4,8),A) should unify A with div(1,2). Your predicate should avoid unnecessary computation. [5 marks] (d) We can also represent arithmetic expressions involving addition, subtraction, multiplication and division. For example, the expression 3 5 2−1 + 4 is represented as add(mul(3,div(5,sub(2,1))),4). Implement a predicate reduce which reduces an arithmetic expression to its smallest exact representation e.g. reduce(add(div(1,2),div(1,4)),A) should unify A with div(3,4)RK Computer Science Engineering & Technology C++ Programming CS MISC Share QuestionEmailCopy link Comments (0)


