rr5 provide comprehensive answers cp E wW T for the ith labelled…
Question Answered step-by-step rr5 provide comprehensive answers cp E wW T for the ith labelled… rr5 provide comprehensive answers cp ∂E ∂wW T for the ith labelled example, where w1,…,wW denotes the complete collection of W weights in the network.[20 marks]30940919(a) Dene the operators of the core relational algebra. [5 marks](b) Let R be a relation with schema (A1,…,An,B1,…,Bm) and S be a relation with schema (B1,…,Bm). The quotient of R and S, written R÷S, is the set of tuples t over attributes (A1,…,An) such that for every tuple s in S, the tuple ts (i.e. the concatenation of tuples t and s) is a member of R. Dene the quotient operator using the operators of the core relational algebra. [8 marks](c) The core relational algebra can be extended with a duplicate elimination operator, and a grouping operator.(i) Dene carefully these two operators. [3 marks](ii) Assuming the grouping operator, show how the duplicate elimination operator is, in fact, unnecessary. [2 marks](iii) Can the grouping operator be used to dene the projection operator? Justify your answer. [2 marks]Review Questions1. Define analog transmission.2. Define carrier signal and its role in analog transmission.3. Describe digital-to-analog conversion.4. Which characteristics of an analog signal are changed to represent the digital signal in each of the following digital-to-analog conversion?a. ASKb. FSKc. PSKd. QAM5. Which of the four digital-to-analog conversion techniques (ASK, FSK, PSK or QAM) is the most susceptible to noise? Juxtapose your answer.6. Define constellation diagram and its role in analog transmission.7. What are the two components of a signal when the signal is represented on a constellation diagram? Which component is shown on the horizontal axis? Which is shown on the vertical axis?(a) Let xt be the number of new COVID infections on date t. We anticipateapproximately exponential growth or decay, xt+1 ≈ (1 + λ)xt, and we wouldlike to estimate λ from a dataset (x1, . . . , xT ).(i) Find the maximum likelihood estimator for λ for the modelXt+1 ∼ Poisson13 Complexity Theory(a) Show that the problem 3-SAT is at least as hard to solve as n-SAT. [5 marks](b) Show that the task of finding a minimum cost closed circuit in a weighted directed graph (a Travelling Salesman Problem of the minimization variety) is at least as hard as the Hamiltonian Circuit Problem. [5 marks](c) Show that the class NP-complete is contained in the class P-space. [5 marks](d) Show that the class P-space is contained in the class EXP-time. [5 marks]In each case ensure that your answer makes it clear what the problems and classes involved are. Standard results do not need to be proved provided they are clearly stated.14 Numerical Analysis IIIn Peano’s theorem, if a quadrature rule integrates polynomials of degree N exactly over an interval [a,b], then the error in integrating f ∈ CN+1[a,b] is conventionally expressed aswhere Explain the notation ( and Ex. [3 marks]It follows directly from Taylor’s theorem that.Explain clearly, in simple stages, how to complete the proof of Peano’s theorem.[8 marks]For the mid-point rule, what is N?If K(t) does not change sign in [a,b] then [1 mark]b) Explain how distributed inter-process communication (IPC) is supported in the distributed systems (10 marks) c) Give any five examples of IPC modes in distributed systems and explain how they work (10 marks) QUESTION TWO (20 MARKS) a) Explain the importance of ensuring the timeliness of messages in cryptographic protocols (8 marks) b) Give a careful account of the main techniques used for ensuring timeliness, including any environmental assumptions (6 marks) c) Under what circumstances is it proper to use time values when there is no clock synchronisation (6 marks) QUESTION THREE (20 MARKS) a) Define a distributed system and give examples in modern society (7 marks) b) Using examples explain how distributed systems work (7 marks) c) A distributed computation may involve related operations n a number of objects which reside at different nodes of a distributed system. Explain why the concept of transaction is suitable for modeling such a computation (6 marks) QUESTION FOUR (20 MARKS) a) What are the problems of passing data values between different machines with different operating systems (8 marks) b) Explain how these problems can be solved (6 marks) c) Explain what is involved in committing a transaction in a distributed system(6 marks) QUESTION FIVE (20 MARKS) A distributed software system follows the client-server model. The microkernel on which it is based supports multi-threaded processes. A remote procedure call (RPC) package is used for client-server interactions. The RPC system runs above an unreliable, datagrambased communications service a) Explain how timers may be used in the RPC protocol to achieve client-server synchronization (8 marks) b) Discuss how the RPC system may support the location of remote procedures (6 marks) c) Discuss the requirements on the RPC system that follow from the use of multithreaded processes Hans Schmidt is a 3rd generation dairyman who started a modest cheese store in 1960. He was an early adopter of organic farming techniques and has benefited from interest in organic products, farm-to-table restaurants/catering, green technologies, and agri-tourism.The company farm, processing plant, distribution center, office, and main store are located in Green Valley, WI between Madison and Milwaukee. They also have 2 stores each in Milwaukee and Madison.GPC’s primary objective is to increase revenue 7% and net income 6% in each of the next 4 years prior to a planned initial public offering (in year 5).The company produces 40% of the milk that they use in their products. The remainder is purchased from local organic farms. Hans refuses to purchase from large corporate farms.The company cannot expand at its present location without purchasing additional acreage. The cost of farm land has been increasing 5% per year.Their product has earned numerous awards which has provided strong name recognition in Wisconsin. They sell to grocery stores, restaurants, organic food outlets, and online customers. They also sell to a wholesale distributor with access to Illinois, Iowa, Michigan and Ohio. The company is seeking store locations and distributors in other states.The business is wholly-owned by the Schmidt family, but they are considering doing an initial public offering (“going public”) in 5 years. Hans owns 60% and is the CEO. His four children each own 10%. The board is composed of the 5 owners and a family friend who is a lawyer. Hans is chairman of the board. The board does not have a separate audit committee. GPC does not have an internal auditor. An annual audit is required by their bank, The Lake Country Bank.Han’s daughter, Leah Scott, CPA, was recently hired as CFO. She replaced her brother Joe who left abruptly after 10 years. Other family members are employed as department heads. Hans encouraged his family to earn advanced degrees and work for other companies before joining the family business.The company’s sales have been increasing rapidly. The company has reinvested in its operations.GPC’s former auditor is Wilks and Company. When Leah became the new CFO, she suggested a change of firms. She explained that it would be easier working with her former colleagues. She was a Wallace and Brace staff auditor for 4 years, and “knows how they operate.” The Organic Cheese IndustryThe organic cheese industry is expected to grow 5-8% per year compared to the non-organic segment which are not expected to grow. New competitors are entering the industry because of the higher profit margins. They may use predatory pricing in order to gain market share. GPC is responding by aggressively marketing new products.GPC’s competitive advantage is that they are the first US cheesemaker to win a world-class award. Since Hans is nearing retirement, they are seeking a highly-skilled cheesemaker from France.The primary business objective is to increase revenue by 7% and net income by 6% per year for the next 4 years. They will do this through developing new products, aggressive marketing, new stores, and adding new markets. They plan to open a new retail store in each of the next 4 years, assuming they are able locate desirable locations. This year GPC hired a new marketing firm and has increased their advertising.This year, they implemented 2 new policies in which they offer credit to grocery stores with higher credit risk. They feel that their past policies were too restrictive and limited their sales. They are also offering their sales staff bonuses based on a percentage of sales to grocery stores. They believe that this will lead to higher sales and ultimately to greater profits.Higher income families consume 70% of organic dairy products, and consumption is highest among adults between ages 25 and 65. Most economists predict modest wage growth in the next 5 years. A few economist predict a recession around year 4.The industry has seen some merger activity in an attempt to benefit from economies of scale. Large cheese manufacturers are launching organic product lines. This will lead to greater price competition.In the most recent year, 2.56 billion pounds of organic milk products were sold. That amount represented 5 percent of all milk products. More than 2,500 farms in the United States produced organic milk. Nearly 280,000 dairy cows were certified organic, up from 241,112 dairy cows in the previous year. California produces 20% of the annual organic milk produced. Wisconsin, Texas, and New York produce about 10% each.Some dairy operations manufacture and sell locally. For national distribution, products tend to move from the farm to a cooperative processor and then to a private distributor before reaching retail outlets.Organic products sell at a price approximately double the price of non-organic products, but they cost more to produce. Organic feed costs more than standard feed, and organic production uses more labor and capital. Grass-fed cows produce less milk.USDA standards for organic food were implemented in 2002. Organic dairy is raised in a production system that promotes and enhances biodiversity and biological cycles and uses only organic feedstuffs and health protocol. It is based on minimal use of off-farm inputs. Dairy cattle producing organic milk are not given antibiotics and growth hormone stimulants. In general, organic foods are minimally processed with artificial ingredients or preservatives.Recent mergers in the organic milk industry could result in lower organic milk prices which reduce the price paid to milk producers. There is also concern that the industry is being dominated by mega-farms. The small producers accuse these large operations of not complying with all the organic regulations. The mega-farms have also created excess supply which suppresses milk prices. The imbalance of power could put small family farms out of the industry. The number of family-farms is expected to decrease. This would allow the larger producers to control the market (and price) of milk.The company subscribes to industry research in order to monitor economic and industry conditions which may affect future sales. They also monitor competitors’ prices and products.Information from Predecessor Auditor, Wilks and CompanyThe previous auditor replied that they were comfortable working with the staff and management of GPC. The people have integrity, and are open to recommendations.Consider a noiseless analog communication channel whose bandwidth is 10,000 Hz.A signal of duration 1 second is received over such a channel. We wish to representthis continuous signal exactly, at all points in its one-second duration, using just afinite list of real numbers obtained by sampling the values of the signal at discrete,periodic points in time. What is the length of the shortest list of such discretesamples required in order to guarantee that we capture all of the information in thesignal and can recover it exactly from this list of samples? [5 marks]Name, define algebraically, and sketch a plot of the function you would need to usein order to recover completely the continuous signal transmitted, using just such a Computational Neuroscience It has been remarked that “neural networks are the second best way of computing just about anything.” Discuss this, touching on the following issues: expressiveness; computational efficiency; generalization; sensitivity to noise; transparency (the ability to explain why a given output value is justified); the use of prior knowledge; whether neural networks fulfill our needs for a comprehensive computational theory of learning. [20 marks] 9 Security Shamir’s three-pass protocol enables Alice to send a message m to Bob in the following way: A → B : mka (mod p) B → A : mka kb (mod p) A → B : mkb (mod p) Explain this protocol, stating the constraint on m and the principal vulnerability. [10 marks] It is suggested that the encryption operation m → mkx be replaced with a provably secure encryption operation, namely a one-time pad. How would this affect the protocol’s security? [10 marks] 10 Natural Language Processing Describe three significant differences between programming languages and natural languages. [8 marks] What problems do these differences pose for attempts to construct programs that “understand” a natural language?Consider a noisy analog communication channel of bandwidth Ω, which is perturbedby additive white Gaussian noise whose power spectral density is N0. Continuoussignals are transmitted across such a channel, with average transmitted power P(defined by their expected variance). What is the channel capacity, in bits persecond, of such a channel? [10 marks]12 Computer VisionUsing appropriate mathematical expressions, define the following operationscommonly used in computer vision and briefly explain their function andapplications:(a) convolution [4 marks](b) correlation [4 marks](c) bandpass filtering [4 marks](d) edge detection by second-derivative zero-crossings [4 marks](e) invariant transform [4 marks]6 Computer System Modelling A telephone exchange multiplexes 64 Kb/s voice calls onto a 256 Kb/s trunk line (therefore the line will hold at most four calls). New calls have an exponentially distributed inter-arrival process, with a mean of 20 seconds, and the call holding time is exponentially distributed with a mean of 60 seconds. (a) Draw a diagram of a Markov Chain which models the system, labelling the state transitions with their rates where appropriate. What is the necessary condition for stability of this system? [5 marks] (b) Derive an expression for the probability that an arriving call finds k calls in progress, for k > 0, and thence calculate the probability that a caller finds the exchange engaged, given the parameters above. [15 marks] 4 Comparative Architectures Discuss implementing the ANSI C routine memcpy() in hardware and software. Why might a C compiler place a string literal on a word boundary when it only needs to be byte aligned? [10 marks] The DEC ALPHA is a RISC-inspired instruction set designed to last around 25 years with multiple implementations as hardware. Discuss to what extent the epithet RISC can be applied and to what extent its main architectural features follow the familiar RISC mould.State the compositionality, soundness and adequacy properties of the denotational semantics of PCF1 (a) (i) Many correct answers, they must be meaningful. This is an example only. StudentNames[1:30] [1] (ii) Many correct answers, they must be meaningful. This is an example only. StudentMarksTest1[1:30] StudentMarksTest2[1:30] StudentMarksTest3[1:30] (1 mark) StudentTotalScore[1:30] (1 mark) [2] (b) (i) – outside loop zeroing total for loop (sum in example below) – loop for all students – input name and all test scores – in loop adding a student’s total – storing the total – inside loop printing student’s name and total – outside loop calculating class average – printing class average sample algorithm: Sum Å 0 FOR Count Å 1 TO 30 INPUT Name StudentName[Count] Å Name INPUT Mark1, Mark2, Mark3 StudentMarksTest1[Count] Å Mark1 StudentMarksTest2[Count] Å Mark2 StudentMarksTest3[Count] Å Mark3 Total Å Mark1 + Mark2 + Mark3 StudentTotalScore[Count] Å Total Sum Å Sum + Total PRINT StudentName[Count], StudentTotalScore[Count] NEXT Count ClassAverage = Sum/30 PRINT ClassAverage [8] (ii) any relevant comment with regards to efficient code (e.g. single loop) [1] (c) Many correct answers, these are examples only. 1 mark per data set and reason Set 1: 20, 25, 35 Reason: valid data to check that data on the upper bound of each range check is accepted Set 2: 21, 26, 36 Reason: invalid data to check that data above the upper bound of each range check is rejected [2] 3 © UCLES 2019 0478/02/SM/20 [Turn over (d) (i) Maximum 5 marks in total for question part Maximum 3 marks for algorithm Description (max 3) – set variable called HighestScore to zero and variable called BestName to dummy value – loop 30 times to check each student’s total score in turn – check student’s score against HighestScore – if student’s score > HighestScore then – « replace value in HighestScore by student’s score and store student’s name in BestName – output BestName and HighestScore outside the loop Sample algorithm (max 3): HighestScore Å 0 BestName Å “xxxx” (1 mark) FOR Count Å 1 TO 30 IF StudentTotalScore[Count] > HighestScore (1 mark) THEN HighestScore Å StudentTotalScore[Count] BestName Å StudentName[Count] (1 mark) ENDIF NEXT Count (1 mark) PRINT BestName, HighestScore (1 mark) If algorithm or program code only, then maximum 3 marks [5] (ii) comment on which student(s)’ name will be output e.g. The first student with the highest score will be output [1] 4 © UCLES 2019 0478/02/SM/20 Section B 2 (a) 1 mark for value of c and message 51020: value of c: 5 message: PIN OK (1 mark) 5120: value of c: 4 message: error in PIN entered (1 mark) [2] (b) length check [1] 3 Engine Count Number Size Average OUTPUT 0 0 0 1.8 1.8 1 1 2.0 3.8 2 2 1.0 4.8 3 1.3 6.1 4 1.0 7.1 5 2.5 9.6 3 6 2.0 11.6 4 7 1.3 12.9 8 1.8 14.7 5 9 1.3 16.0 10 -1 1.6 1.6, 5 (1 mark) (1 mark) (1 mark) (1 mark) (1 mark) (1 mark) [6] 4 1 mark for each error identified + suggested correction line 5: this should read IF x > h THEN h = x line 7: PRINT h should come after the end of the repeat loop line 8: this should read UNTIL c = 20 or UNTIL c >= 20 or UNTIL c > 19 [3] 5 © UCLES 2019 0478/02/SM/20 [Turn over 5 (a) 5 [1] (b) Field: At Risk Age in Years Type Map Position Table: TREES TREES TREES TREES Sort: Show: 9 9 Criteria: True >100 or: One mark per correct column. [4] 6 (a) marking points: the way to find and print the largest value a 1 mark the way to find and print the largest value b 1 mark the way to find and print the largest value c 1 mark sample algorithm: INPUT a, b, c IF a > b AND a > c THEN PRINT a (1 mark) ELSE IF b > c THEN PRINT b (1 mark) ELSE PRINT c (1 mark) [3] (b) marking points: loop construct 1 mark check if number is an integer 1 mark counting the number of integers input 1 mark output count value (outside the loop) 1 mark sample algorithm: FOR x ← 1 TO 1000 (1 mark) INPUT Number Difference ← INT(number) – Number (1 mark) IF Difference = 0 THEN Total ← Total + 1 (1 mark) NEXT x PRINT total (1 mark) (NOTE: alternative to lines 3 and 4: IF INT(Number) = Number THEN Total ← Total + 1 (2 marks) ) [4] (c) Description of any two sets of test data. Many correct answers, these are examples only. 1000 whole numbers to ensure that loop works properly 900 whole numbers and 100 numbers with decimal places to ensure that the routine distinguishes correctly [2] 6 © UCLES 2019 0478/02/SM/20 7 (a) 7 [1] (b) Hg, Cs [2] (c) Element symbol1 Foundations of Computer Science Three alternative representations for non-negative integers, n, are: • Peano: values have the form S(… S(Z) …), applying S n times to Z where S and Z are constructors or constants of some data type. • Binary: values are of type bool list with 0 being represented as the empty list, and the least-significant bit being stored in the head of the list. • Church: values have the form fn f => fn x => f(… f(x) …), applying f n times to x (a) Write ML functions for each of these data types which take the representation of an integer n as argument and return n as an ML int. [6 marks] (b) Write ML functions for each of these data types which take representations of integers m and n and return the representation of m + n. Your answers must not use any value or operation on type int or real. [Hint: you might it useful to write a function majority: bool*bool*bool -> bool (which returns true when two or more of its arguments are true) and to note that the ML inequality operator ‘<>‘ acts as exclusive-or on bool.] [10 marks] (c) Letting two and three respectively be the Church representations of integers 2 and 3, indicate whether each of the following ML expressions give a Church representation of some integer and, if so what integer is represented, and if not giving a one-line reason. (i) two three (ii) three two (iii) two ◦ three (iv) three ◦ two [4 marks] 2 CST0.2019.1.3 2 Foundations of Computer Science (a) We are interested in performing operations on nested lists of integers in ML. A nested list is a list that can contain further nested lists, or integers. For example: [[3, 4], 5, [6, [7], 8], []] We will use the datatype: datatype nested_list = Atom of int | Nest of nested_list list; Write the code that creates a value of the type nested list above. [1 mark] (b) Write the function flatten that flattens a nested list to return a list of integers. [3 marks] (c) Write the function nested map f n that applies a function f to every Atom in n. [4 marks] (d) What is the type of f in Part (c)? [1 mark] (e) Write a function pack as xs n that takes a list of integers and a nested list; the function should return a new nested list with the same structure as n, with integers that correspond to the integers in list xs. Note: It is acceptable for the function to fail when the number of elements differ. Example: > pack_as [1, 2, 3] (Nest [Atom 9, Nest [Atom 8, Atom 7]]); val it = Nest [Atom 1, Nest [Atom 2, Atom 3]]: nested_list [6 marks] (f ) What does the data type nested zlist correspond to? [2 marks] datatype nested_zlist = ZAtom of int | ZNest of (unit -> nested_zlist list); (g) Write the function that converts a nested zlist to a nested list. [3 marks] 3 (TURN OVER) CST0.2019.1.4 SECTION B 3 Object-Oriented Programming (a) You are given the following implementation for an element of a list: class Element { int item; Element next; Element(int item, Element next) { super(); this.item = item; this.next = next; } @Override public String toString() { return item + ” ” + (next == null ? “” : next); } } (i) What does the statement super() mean? [1 mark] (ii) What is the meaning of this in the line this.item = item? [1 mark] (iii) What is the purpose of the annotation @Override? [2 marks] (iv) Rewrite the class to be immutable. You may assume that there are no sub-classes of Element. [2 marks] (b) Use the immutable Element class to provide an implementation of an immutable class FuncList which behaves like an int list in ML. Your class should include a constructor for an empty list and methods head, tail and cons based on the following functions in ML. Ensure that your class behaves appropriately when the list is empty. [6 marks] fun head x::_ = x; fun cons (x,xs) = x::xs; fun tail _::xs = xs; (c) Another developer changes your implementation to a generic class FuncList that can hold values of any type T. (i) This means that FuncList is no longer immutable. Explain why and what could be done to remedy this. [2 marks] (ii) Java prohibits covariance of generic types. Is this restriction necessary in this case? Explain why with an example. [6 marks] 4 CST0.2019.1.5 4 Object-Oriented Programming (a) What is an object? [2 marks] (b) Give four examples of how object-oriented programming helps with the development of large software projects and explain why each one is helpful. [8 marks] (c) Explain the meaning of the Open-Closed principle. [2 marks] (d) Draw a UML diagram for a design satisfying the Open-Closed principle and explain why it satisfies it. [8 marks] 5 (TURN OVER) CST0.2019.1.6 SECTION C 5 Numerical Analysis (a) Let f be a single variable real function that has at least one root α, and that admits a Taylor expansion everywhere. (i) Starting from the truncated form of the Taylor expansion of f(x) about xn, derive the recursive expression for the Newton-Raphson (NR) estimate xn of the root at the (n + 1)th step. [1 mark] (ii) Consider the general Taylor expansion of f(α) about xn. Using big O notation for an appropriate Taylor remainder and denoting the NR error at the nth step by en, prove that the NR method has quadratic convergence rate. That is, show that en+1 is proportional to e 2 n plus a bounded remainder. State the required conditions for this to hold, paying attention to the interval spanned during convergence. [6 marks] (iii) Briefly explain two of the known problems of the NR method from an implementation standpoint or otherwise. [2 marks] (b) Let f(x) = x 2 − 1. Suppose we wish to find the positive root of f using the Newton-Raphson (NR) method starting from an initial guess x0 ≥ 1. (i) Show that if x0 ≥ 1 then xn ≥ 1 for all n ≥ 1. [3 marks] (ii) Thus find an upper bound for NR’s xn+1 estimate in terms of xn and in turn find an upper bound for xn in terms of x0. [5 marks] (iii) Using the above, estimate the number of NR iterations to obtain the root with accuracy 10−9 for a wild initial guess x0 = 109 . [Hint: You may wish to approximate 103 by 210.] [3 marks] 6 CST0.2019.1.7 6 Numerical Analysis (a) You are given a system of real equations in matrix form Ax = b where A is non-singular. Give three factorization techniques to solve this system, depending on the shape and structure of A: tall, square, symmetric. For each technique, give the relevant matrix equations to obtain the solution x, and point out the properties of the matrices involved. Highlight one potential problem from an implementation (computer representation) standpoint. [Note: You do not need to detail the factorization steps that give the matrix entries.] [5 marks] (b) We want to estimate travel times between stops in a bus network, using ticketing data. The network is represented as a directed graph, with a vertex for each bus stop, and edges between adjacent stops along a route. For each edge j ∈ {1, . . . , p} let the travel time be dj . The following ticketing data is available: for each trip i ∈ {1, . . . , n}, we know its start time si , its end time fi , and also the list of edges it traverses. The total trip duration is the sum of travel times along its edges. We shall estimate the dj using linear least squares estimation, i.e. solve arg minβ ky − Xβk 2 for a suitable matrix X and vectors β and y. (i) Give an example of ticket data for a trip traversing 5 edges, and write the corresponding equation of its residual. [1 mark] (ii) Give the dimensions and contents of X, β, and y for this problem. State a condition on X that ensures we can solve for β. [3 marks] (iii) Give an example with p = 2 and n = 3 for which it is not possible to estimate the dj . Compute XT X for your example. [2 marks] (c) Let A be an n × n matrix with real entries. (i) We say that A is diagonalisable if there exists an invertible n × n matrix P such that the matrix D = P −1AP is diagonal. Show that if A is diagonalisable and has only one eigenvalue then A is a constant multiple of the identity matrix. [3 marks] (ii) Let A be such that when acting on vectors x = [x1, x2, . . . , xn] T it gives Ax = [x1, x1 −x2, x2 −x3, . . . , xn−1 −xn] T . Write out the contents of A and find its eigenvalues and eigenvectors. Scale the eigenvectors so they have unit length (i.e. so their magnitude is equal to 1). [6 marks] 7 (TURN OVER) CST0.2019.1.8 SECTION D 7 Algorithms (a) The Post Office of Maldonia issued a new series of stamps, whose denominations in cents are a finite set D ⊂ N{0}, with 1 ∈ D. Given an arbitrary value n ∈ N{0} in cents, the problem is to find a minimum-cardinality multiset of stamps from D whose denominations add up to exactly n. In the context of solving the problem with a bottom-up dynamic programming algorithm. . . (i) Give and clearly explain a formula that expresses the optimal solution in terms of optimal solutions to subproblems. [Note: If your formula gives only a scalar metric (e.g. the number of stamps) rather than the actual solution (e.g. which stamps), please also explain how to obtain the actual optimal solution.] [4 marks] (ii) Draw and explain the data structure your algorithm would use to accumulate the intermediate solutions. [2 marks] (iii) Derive the big-Theta space and time complexity of your algorithm. [1 mark] (b) Repeat (a)(i)-(a)(iii) for the following problem: A car must race from point A to point B along a straight path, starting with a full tank and stopping as few times as possible. A full tank lets the car travel a given distance l. There are n refuelling stations so ≡ A, s1, s2, . . . , sn ≡ B along the way, at given distances d0 = 0, d1, d2, . . . , dn from A. The distance between adjacent stations is always less than l. The problem is to find a minimum-cardinality set of stations where the car ought to refill in order to reach B from A. [7 marks] (c) Which of the two previous problems might be solved more efficiently with a greedy algorithm? Indicate the problem and describe the greedy algorithm. Then give a clear and rigorous proof, with a drawing if it helps clarity, that your greedy algorithm always reaches the optimal solution. Derive the big-Theta time complexity. [6 marks] 8 CST0.2019.1.9 8 Algorithms (a) Consider a Binary Search Tree. Imagine inserting the keys 0, 1, 2, . . . , n (in that order) into the data structure, assumed initially empty. (i) Draw a picture of the data structure after the insertion of keys up to n = 9 included. [2 marks] (ii) Clearly explain, with a picture if helpful, how the data structure will evolve for arbitrary n, and derive the worst-case time complexity for the whole operation of inserting the n + 1 keys. [2 marks] (b) Repeat (a)(i) and (a)(ii) for a 2-3-4 tree, with some scratch work showing the crucial intermediate stages. [2+2 marks] (c) . . . and for a B-tree with t = 3, again showing the crucial intermediate stages. [2+2 marks] (d) . . . and for a hash table of size 7 that resolves collisions by chaining. [2+2 marks] (e) . . . and for a binary min-heap. [2+2 marks] 9 (TURN OVER) CST0.2019.1.10 9 Algorithms A Random Access Queue supports the operations pushright(x) to add a new item x to the tail, popleft() to remove the item at the head, and element at(i) to retrieve the item at position i without removing it: i = 0 gives the item at the head, i = 1 the following element, and so on. (a) We can implement this data structure using a simple linked list, where element at(i) iterates from the head of the list until it reaches position i. (i) State the complexity of each of the three operations. [1 mark] (ii) A colleague suggests that, by defining a clever potential function, it might be possible to show that all operations have amortized cost O(1). Show carefully that your colleague is mistaken. [6 marks] (b) We can also implement this data structure using an array. The picture below shows a queue holding 4 items, stored within an array of size 8. When new items are pushed, it may be necessary to create a new array and copy the queue into it. The cost of creating an array of size n is Θ(n). head item item item tail item 0 1 2 3 4 5 6 7 (i) Give pseudocode for the three operations. Each operation should have amortized cost O(1). [6 marks] (ii) Prove that the amortized costs of your operations are Computer Science Engineering & Technology C++ Programming MKT 2002S Share QuestionEmailCopy link Comments (0)


