SEE ALL program which is supplied with data arranged as one…
Question Answered step-by-step SEE ALL program which is supplied with data arranged as one… SEE ALLprogram which is supplied with data arranged as one left-adjusted integer per line. The integers (which may be assumed to be all different) are read one at a time and the procedure Put assembles a simple binary tree by arranging for each integer in turn to be in a new node of the tree. The assembly process sorts the integers into numerical order. VAR tree : PtrToNode := NIL; BEGIN TRY LOOP TRY Put (Scan.Int (Rd.GetLine (Stdio.stdin)), tree) EXCEPT Scan.BadFormat => Wr.PutText (Stdio.stdout, “Bad datumn”) END END EXCEPT Rd.EndOfFile => END; PrintTree (tree); Wr.Close (Stdio.stdout) Explain the operation of the two TRY-EXCEPT clauses. [5 marks] Provide a suitable TYPE statement to define the type PtrToNode. [5 marks] Write a procedure Put and explain its operation. [5 marks] The procedure PrintTree is intended to write out the values in the tree in ascending order. Write this procedure and explain its operation. [5 marks] 2 CST.94.10.3 3 Further Modula-3 The thread system in Modula-3 uses mutexes and condition variables to control concurrency. An alternative scheme would be to provide eventcounts and sequencers. An eventcount is an integer, initially zero, equipped with the three atomic operations: advance increments the count and returns its new value, read returns the current value of the count, and await (value) suspends the calling thread until the count is at least as large as the value given as an argument. A sequencer is an integer, initially zero, equipped with a single atomic operation: ticket increments the count and returns its previous value. Given an eventcount, guard, and a sequencer, turn, a critical region can then be codedinterface, ECS, defining opaque object types EventCount and Sequencer. EventCount should have methods advance, read and await, with appropriate signatures, and Sequencer should have a ticket method. [8 marks] Sketch an implementation of the ECS module giving concrete revelations of the types and providing appropriate default methods Two approaches are considered: (A) the doctor interviews the patient at the start of the initial consultation, and enters the details as they are elicited; (B) upon application, the patient or parent sits down at a computer and enters the details. Write one-sentence problem statements for each design problem. Then, drawing on your knowledge of the work of the doctor, discuss the pros and cons of the two approaches. [12 marks] Suppose two practices, P1 and P2, adopt approaches A and B respectively. Each is dissatisfied with the results. Practice P1 therefore decides to switch to approach B, installing a computer in a booth adjoining its waiting room, running the system designed for the doctor (modified only to prevent access to existing records), so that patients and parents can enter their details. Meanwhile practice P2 decides to change to approach A, loading the patient data entry program, unchanged, onto the doctor’s PC so that he or she can enter the details during consultations. If you were asked to advise practices P1 and P2 on these moves, what outcomes would you predict? What analytical method would you use, in each case, to back up your predictions, and why? Assume a simple paging system with 232 bytes of physical memory, 248 bytes of logical address space and pages that are 220 bytes in size. Further assume that each page table entry contains 4 bits indicating protection and validity of the entry. (i) How many bits are used for the frame number and how many for the frame offset? (ii) What is the total size of the page table in number of bits? (iii) Assume that the working set of a typical process is fixed throughout the process lifetime How many entries would you suggest for the Translation Lookaside Buffer (TLB) for this system? What would its total size be in number of bits? Explain your answer. [4 marks] (iv) Further assume that TLB search time is 20ns, TLB hit ratio is 80% and memory access time is 100ns. How many page table levels would you need to achieve an effective access time of 160ns, and why? [3 marks] (b) (i) A Unix i-node has 12 disk addresses for direct disk blocks and three addresses for single, double, and triple indirect blocks. If each indirect block contains 256 disk addresses, what is the maximum file size supported by this system? Assume disk blocks of 4KB. [3 marks] (ii) Assume that you are user1 in a Unix file system and that you need to read the file /home/user1/test/test1.html which is stored in 4 disk blocks. Further assume that the / directory i-node is kept memory and each i-node and directory file fits in one disk block. How many disk accesses are required to read test1.html? Explain your answer. [4 marks] (iii) Assume that user1 wants to read /home/user1/test/test2.html immediately after reading /home/user1/test/test1.html. Further assume that file test2.html is stored in 4 disk blocks. How many disk accesses are required to read test2.html? Explain your answer. [3 marks]) Assume a 32-bit architecture with hardware support for paging, in the form of a translation lookaside buffer (TLB), but no hardware support for segmentation. Assume that the TLB is shared rather than flushed on process switching and that the operating system designers are supporting “soft” segments. (i) In addition to page number and page base, what fields would you expect to find in each TLB register? How would each of these be used? [4 marks] (ii) What fields would you expect to find in a process page table? How would each of these fields be used? [6 marks] (b) (i) Outline the function of a timing device. [2 marks] (ii) Why are timers essential in multiprogramming operating systems? [2 marks] (iii) Explain the operation of a multi-level feedback queue in process scheduling. [6 marThe Java class below defines a queue data structure with a fixed capacity. public class F boolean enqueue(int x) 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](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] Give a brief summary of the main syntactic constructs found in the programming language Smalltalk. Other languages often have the conditional constructs if-then-else and while. Show how these two constructs can be defined in Smalltalk. [8 marks] Illustrate the use of Smalltalk by showing how you would define a method to compute the factorial of an integer. [8 marks] Although Smalltalk was originally designed to be an interpretive language, modern implementations are dramatically more efficient. Briefly outline what techniques might have been used to make this improvement. (a) Brieflfly explain the difffferences between combinational and sequential logic. Computer Science Engineering & Technology C++ Programming CSCI 333 Share QuestionEmailCopy link Comments (0)


