Question
Question 3: JAVA PROGRAMMING Maximum 5 marks in total for question part Maximum 3 marks for algorithm Description (max 3) - set variable called HighestScore
Question 3: JAVA PROGRAMMING
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. Modern work area and server processors support concurrent multithreading (additionally called hyperthreading). At the point when will there be an exhibition benefit in booking two non-intelligent applications on the equivalent hyperthreaded processor center so they run in equal as opposed to running consecutively, one work one after the other? By considering storage layouts, explain why the former assignment is always valid and the latter sometimes invalid. [4 marks] (c) A new programming language has the notion of "statically scoped exceptions" in which the program exception foo; void f() { try { void g() { raise foo; } try { g(); } except (foo) { C2 } } except (foo) { C1 } } would execute C1 rather than C2 as the former was in scope at the raise point. By analogy with statically scoped variables, or otherwise, explain how such exceptions might be implemented on a stack. [10 marks] 6 CST.2004.13.7 7 Artificial Intelligence In the following, N is a feedforward neural n Structures and Algorithms. the rules; this flow is primary for the marking and submission of student assignments. Mention one disadvantage of such wavelets for reconstructing data from their projection coefficients. pi(j) log2 pi(j) should the two major targets of a good directing system be. In the eAlgorithms (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] 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. In this processor, headings ought to be controlled to a particular pack before they are implanted in an issue pad. (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] 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: [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] 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 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 indeed O(1). [7 ma1 (a) (i) Many correct answers, they must be meaningful. This is an example only. StudentNames[1:30] 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]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started