## Question

# explain (a) Describe how mutual-exclusion locks provided by the synchronized keyword can be used to control access to shared data structures. In particular you should

explain

(a) Describe how mutual-exclusion locks provided by the synchronized keyword can be used to control access to shared data structures. In particular you should be clear about the behaviour of concurrent invocations of different synchronized methods on the same object, or of the same synchronized method on different objects. [6 marks] (b) Consider the following class definition: class Example implements Runnable { public static Object o = new Object(); int count = 0; public void run() { while (true) { synchronized (o) { count ++; } } } } Show how to start two threads, each executing this run method. [2 marks] (c) When this program is executed, only one of the count fields is found to increment, even though threads are scheduled preemptively. Why might this be? [2 marks] (d) Define a new class FairLock. Each instance should support two methods, lock and unlock, which acquire and release a mutual exclusion lock such that calls to unlock never block the caller, but will allow the longest-waiting blocked thread to acquire the lock. The lock should be recursive, meaning that the thread holding the lock may make multiple calls to lock without blocking. The lock is released only when a matched number of unlock operations have been made. You may wish to make use of the fact the Thread.currentThread() returns the instance of Thread that is currently executing.

it is okay (a) Describe a mechanism that operating systems use to reduce the opportunity for a user process to prevent another user's process from making progress. In your description include any particular hardware features that are relied upon. (b) Describe two alternative mechanisms that operating systems could use to reduce the opportunity for a user process to access or corrupt the information being used by another user's process. In your descriptions include any particular hardware features that are relied upon. (c) Describe how an operating system might attempt to ensure that long-term user information (that is, information which exists beyond process execution) is not interfered with or misused by other users. Your description should be clear about when actions are performed and the resources they consume. [5 marks] (d) To what extent are the mechanisms described above useful in single user systems? [3 marks] (e) How do operating systems ensure that they are not themselves overly-restricted by these mechanisms?

ensure to answer all questions

Consider display technologies for hand-held devices. (a) Explain the principles of operation of each of the following. Note: You may illustrate your answers with a diagram. (i) Liquid crystal displays [5 marks] (ii) Electrophoretic (electronic paper) displays [5 marks] (b) Compare and contrast their characteristics. [6 marks] (c) Explain how liquid crystal and electrophoretic displays can show coloured images.

Consider rendering a triangular mesh using OpenGL. A uniform material is used for the entire mesh and the reflection model of the material consists of ambient, diffuse and specular components. There are two point light sources in the scene. Given these assumptions, answer the following questions: (a) Gourand and Phong shading are two different methods of interpolating colours between vertices. Explain how each method interpolates colours. [5 marks] (b) Discuss the trade-offs in terms of quality and computational costs for Phong and Gourand shading. Assume that the number of rendered pixels is much larger than the number of vertices. What kind of artefacts can one of the methods produce and what is the reason for those artefacts?

(a) Describe the difference between blocking and nonblocking input/output operations. How can an operating system improve the performance (as seen by a process) of blocking operations? [4 marks] (b) A privileged process is given raw access to a slow disk device. It reads a page from the disk (using a blocking operation), processes the information and repeats. Suppose a read takes 3 units of time and the processing 2 units of time, so that reading a block and processing takes 5 units of elapsed time. Assuming the machine is otherwise idle, how can this elasped time be reduced? State any assumptions about hardware features you are making. [5 marks] (c) Describe how polled I/O works and state its disadvantages. Under what conditions is polling a sensible approach? Describe an alternative approach. (You may find it helpful to provide a few lines of psuedo code.) [4 marks] (d) What advantages does direct memory access (DMA) provide? Describe its operation as seen by a device driver in the operating system. (You may find it helpful to write a few lines of psuedo code.) [5 marks] (e) To what extent does heterogeneity in I/O systems add complexity to an operating system?

n (a) Define briefly, for each of the following techniques, what its purpose is and how it is conducted. (i) Regression testing (ii) A/B testing (b) Although each of these techniques can provide new information of value to a software project, costs can be reduced if information is available earlier in the design cycle. For each of the four techniques in part (a), suggest a method by which some of the resulting information could be obtained earlier in the project.

The following is an extract from a design brief written by the client for one of the 2014 Cambridge group design projects. What I'd like is some sort of database of recipes to which I can send queries such as "Find me something that doesn't contain cabbage or tomatoes that takes less than 30 minutes to prepare", or "I've got kohlrabi in the veg box AGAIN, are there any recipes I haven't tried that might make something edible out of it?", or "I've actually got a couple of hours free to cook this weekend, what was that complicated Ottolenghi recipe I flagged two weeks ago to try later?". The database needs to cope with the fact that ingredients can have different names but mean the same thing: e.g. "flour" and "plain flour", and that "1/4 lb" and "4oz" are the same thing and equal to "100g" (and not 113g). It would be great if once I've chosen this week's menu, it could produce a shopping list I can plug into www.myfavouritesupermarket.com, and it needs to be usable by non-engineers. (a) For each of the following software project phases, suggest a design model or representation that would be a helpful aid in the design process. For each of these, sketch an example to show what this model looks like, based on some part of the above design brief. (i) Inception phase (ii) Elaboration phase (iii) Construction phase (iv) Transition phase [12 marks] (b) For each of the sketched examples in part (a), describe how the design work so far could be evaluated before proceeding to the next phase. [4 marks] (c) Choose two of the above design models, representations or evaluation methods, and explain how they would be done differently if the design project was following an agile rather than spiral project management approach.

(a) Let m be a fixed positive integer. (i) For an integer c, let Kc = { k N | k c (mod m) }. Show that, for all c Z, the set Kc is non-empty. [2 marks] (ii) For an integer c, let c be the least element of Kc. Prove that for all a, b Z, a b (mod m) iff a = b. [4 marks] (b) (i) State Fermat's Little Theorem. [2 marks] (ii) Prove that for all natural numbers m and n, and for all prime numbers p, if m n

mod (p 1) then k N. km k n (mod p). [6 marks] (c) (i) Use Euclid's Algorithm to express the number 1 as an integer linear combination of the numbers 34 and 21. [3 marks] (ii) Find a solution x N to 34 x 3 (mod 21). [3 marks]

(a) Show how two NOR gates may be connected to form an RS latch. Describe its operation and give a table relating its inputs to its outputs. How could you use this circuit to eliminate the effect of contact bounce in a single pole double throw switch supplying an input to a digital logic circuit?

(a) Write brief notes on programming with lazy lists in ML. Your answer should include the definition of a polymorphic type of infinite lazy lists, a function to return the tail of a lazy list, a function to create the infinite list of all positive integers, and an apply-to-all functional analogous to the list functional map. [6 marks] (b) Write a function diag that takes a lazy list of lazy lists, [ [z11, z12, z13, . . .], [z21, z22, z23, . . .], () [z31, z32, z33, . . .], . . . ] and returns the diagonal, namely the lazy list [z11, z22, z33, . . .]. [3 marks] (c) Write a function that takes two lazy lists [x1, x2, x3, . . .] and [y1, y2, y3, . . .] and a function f of two arguments; it should return a lazy list of lazy lists like () above, with zij = f xi yj . [3 marks] (d) Write a function that converts a lazy list of lazy lists like () above to a lazy list whose elements are all of the zij , enumerated in some order.

Envision you have been appointed to plan a framework that will assist understudies with learning step by step instructions to test and troubleshoot programming in an average homeroom circumstance. (a) Explain the contrast among testing and investigating. [2 marks] (b) Name four distinct ways to deal with testing, giving a concise meaning of each. [8 marks] (c) Prepare starter plan, as fit to the beginning period of a task, that could be introduced to the client who has authorized this instructive testing application. You ought to incorporate two various types of graph, so the client gets the general construction of the proposed client connection, and furthermore the sorts of information that will be handled and put away when the framework is functional.

You might utilize standard outcomes given that you notice them plainly. (a) (I) State an adequate condition on a couple of positive numbers an and b so that the following holds: x, y Z.

x y (mod a) x y (mod b)

x y (mod abdominal muscle) [2 marks] (ii) Recall that, for a positive number m, we let Zm = {n N | 0 n < m} what's more, that, for a number k, we compose [k]m for the interesting component of Zm such that k [k]m (mod m). Let an and b be positive numbers and let k and l be numbers to such an extent that k a+l b = 1. Think about the capacities f : Zab ZaZb and g : ZaZb Zab given byf(n) = [n]a , [n]b

, g(x, y) = [k a (y x) + x]ab Demonstrate either that g f = idZab or that f g = idZaZb

: Compose Java program to peruse 2D framework of type number, with size 6*6, and show the slanting grid. : Compose java program to peruse two number and trade the qualities utilizing third factor. : Compose Java program to peruse a complete names (first and last together) from a text record and print the name in the' last, first'

. Compose program that prompts the client to enter three whole numbers and show the numbers in non-diminishing request. You can accept that all numbers are legitimate.

(a) A combinational logic circuit takes a 4-bit unsigned binary integer number at its inputs labelled D3 , D2 , D1 and D0 , where D3 is the most significant bit. For decimal input 1, 2, 3, 5, 7, 11 and 13, the output S is to be at logic 1, and it is to be at logic 0 otherwise. (i) Write down the truth table for the required combinational logic function. (ii) Using a Karnaugh map, determine the simplified Boolean expression for the output S in terms of the inputs D3 to D0 in a minimum sum-of-products form. (iii) Describe what is meant by an essential term in a Karnaugh map. Write down the essential terms for the Karnaugh map in (ii). (iv) Using a Karnaugh map, this time determine the required simplified Boolean expression for the output S in a minimum product-of-sums form.

: Write program to read any Month Number in integer and display Month name in the word Write program to input a lowercase alphabet character then display it as uppercase character. Also do vice-versa. Q2. Write program to read a string and display its length (number of characters). ALGORITHM Write program to read a string and display its length.

This question is about hash tables. (a) Briefly explain hash functions, hash tables and collisions. [3 marks] (b) Explain the open addressing strategy of collision resolution and the term probing sequence used in that context. [3 marks] (c) Explain quadratic probing and its advantages and disadvantages. [Hint: refer to primary and secondary clustering.] [3 marks] (d) Give a general mathematical expression for the probing function p(k, i) used in quadratic probing. The expression should yield a 0-based index into the table, referencing the key k, the probe number i, the hash function h, the table size m and the constants c1 and c2. [3 marks] (e) Does the following pseudocode implement a form of quadratic probing? If so, derive values for c1 and c2 in the equation you produced for part (d). If not, prove it doesn't. In either case, clearly justify your reasoning. [8 marks] def get(k): j = h(k) i = 0 while true: if T[j].key == null: raise NotFound if T[j].key == k: return T[j].payload i = i+1 if i == m: raise NotFound j = (i+j) mod m

We wish to store a dynamic collection of records, each of the form {timestamp, value}, where value is a real number. The collection should support the operations append_newer(t,v) to add a new record (which we can assume has a larger timestamp than any existing record), pop_oldest() to remove the oldest record, and get_oldest() to inspect the oldest without removing it. (a) Define the Queue abstract data type. Describe an implementation using a linked list. Explain how to use it for this dynamic collection of records. [3 marks] The collection should also support get_max(), which returns a pointer to the record with the highest value in the collection. Ties may be broken arbitrarily. (b) A simple implementation of get_max() simply scans through the entire list. What is the worst-case cost, given the number n of items in the collection? [1 mark] (c) An engineer friend suggests keeping a pointer maxrecord to the record with the largest value so that the entire list only need be rescanned when the item pointed to by maxrecord is removed. Give an example to show that n operations could take (n 2 ) time. [3 marks] (d) Explain the terms amortized cost and potential method. Explain the relationship between aggregate true costs and aggregate amortized costs. [4 marks] (e) Devise an implementation in which all operations have O(1) amortized cost, and use the potential method to justify your answer. Illustrate what happens when we start with a list of values [5, 8, 3, 6, 2] where 5 is oldest and 2 is newest, and then append a newer record with value 7. [Hint: Where is the largest item newer than maxrecord, and the largest item newer than this, and so on?]

(a) Consider a directed acyclic graph with V vertices and E edges. (i) What is meant by a total order on the vertices consistent with the edges? [2 marks] (ii) Describe an O(E + V ) algorithm to compute such a total order. [3 marks] (b) Consider a directed graph with non-negative edge costs and with a given start vertex s. (i) Dijkstra's algorithm computes distances from s to every other vertex. Give psuedocode for Dijkstra's algorithm

## 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