Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ol (a) This question concerns the data structure of queues. (i) Describe the primitive queue operations. [3 marks] (ii) Describe an efficient implementation of queues,

ol

(a) This question concerns the data structure of queues. (i) Describe the primitive queue operations. [3 marks] (ii) Describe an efficient implementation of queues, presenting code fragments as appropriate (a complete program listing is not required). [3 marks] (iii) Carefully discuss the efficiency of your implementation, using the concept of amortised time. [4 marks] (b) Write an ML function to compute all permutations of its argument, a list. (You may assume that the elements of this list are distinct.) For example, given the in any order. For full credit, your code must be well structured and clearly explained. [10 marks] 6 Foundations of Computer Science (a) Contrast ordinary lists, lazy lists and mutable lists by (i) presenting the ML datatype declaration of each type of list, and [3 marks] (ii) implementing a filter functional for each type of list. [7 marks] (The mutable version should remove the elements that do not satisfy the given predicate, rather than constructing a new list.) (b) The intersection of two dictionaries is the largest dictionary that agrees with them both. For example, if one dictionary is cat=3, dog=2, rabbit=9 while the other is cat=4, dog=2, hamster=9, then their intersection is dog=2. Code an ML function to compute the intersection of two dictionaries, where dictionaries are represented by binary search trees. You may assume that the dictionary lookup and update operations are provided. For full credit, your solution must be simple and clear.

(a) FIFO, LRU, and CLOCK are three page replacement algorithms. (i) Briefly describe the operation of each algorithm. [6 marks] (ii) The CLOCK strategy assumes some hardware support. What could you do to allow the use of CLOCK if this hardware support were not present? [2 marks] (iii) Assuming good temporal locality of reference, which of the above three algorithms would you choose to use within an operating system? Why would you not use the other schemes? [2 marks] (b) What is a buffer cache? Explain why one is used, and how it works. [6 marks] (c) Which buffer-cache replacement strategy would you choose to use within an operating syste

Devices are ultimately connected to the CPU via a bus. (i) What are the main components of a bus? (ii) Describe how the CPU uses a bus to communicate with a device. (iii) How does the situation become more difficult when we have DMA-capable devices? (iv) Why does a typical computer have more than one bus? (b) A programmer at MegaCorp is given the task of optimising a program for which no source code exists; all that is available is an executable file. (i) How could the programmer modify the operating system to work out which parts of the program are executed frequently, and thus might be candidates for optimisation? (ii) The programmer determines that the slowest parts of the program involve loops which perform repeated integer multiplications, and where the multiplicand is always either 8 or 15. How could the program be modified to use faster ALU operations instead?

address all For each of the following Java language features, give an example of a place in a large Java library where you might expect it to be used. Explain exactly what the feature achieves, why that is a benefit in the context you describe, and what risk or inconvenience might arise if the feature were not deployed. (a) Methods that have been declared as protected. (b) Classes that are labelled as final. [4 marks] (c) Generic methods - that is, ones where the types of their arguments and results involve other types enclosed in angle brackets, as in ClassName. [4 marks] (d) Fields within a class that are marked as private. [4 marks] (e) Parts of the library defined as an interface rather than as a class. [4 marks] In some cases you may refer to a concrete example present in the existing Java libraries. You may also propose uses that current libraries do not exploit. Marking will pay attention to the extent to which you cover the topics you have been explicitly asked to explain: ill-structured general discussions of the Java features concerned will attract little credit. 7 (TURN OVER) CST.2006.1.8 10 Programming in Java The "Game of Life" is played on a board of square cells. Each cell is either "live" or "dead". Initially most cells are dead, but a seeding pattern of live ones is set up. Each square cell has eight immediate neighbours (North, South, East, West, and four diagonal ones). At each time step all cells transform simultaneously. If a cell is dead, it becomes alive if it had (just before this time step) exactly three live neighbours. If it is alive, it becomes dead unless it has two or three live neighbours. In this question, locations beyond a 1000 1000 board are to be treated as permanently dead. (a) Show how to set up a simple Java 2-dimensional array of boolean values to represent a Life Board, with all cells initially "dead". [2 marks] (b) For a location (i, j) on the board, give code that will decide whether the next state of that cell should be alive or dead. Make it clear how your code copes if the cell is at the boundary of the board. [4 marks] (c) Referring to part (b), write code that takes one board representing the current state of the game and fills in a second board-array with the state arrived at after one time step. What would happen if instead of using two arrays you wrote the new cell state directly back, using just a single copy of the board? [3 marks] (d) Re-work your solution to part (c) so that you can perform a time step using just one board. You may need to use a 1000-element vector to store information in a way that makes the update safe. [7 marks] (e) All the code you have written so far uses an array of boolean values. Some programmers would instead use an array of int values and treat each of the 32 bits in each int as giving the status of a cell. Suppose you have a 2-dimensional array of integers of size 1024 by 32 (that size is chosen so the array of integers may be viewed as a 1024 by 1024 array of bits): give code to retrieve a bit from a given position (i, j). [4 marks]

A splay tree is a binary search tree with amortised complexity O(log(n)) per operation. (i) What is meant by amortised complexity? [1 mark] (ii) Draw the three different splay rotations that may be applied when the target node is the left child of its parent. Take care to include the location of subtrees before and after each rotation. [9 marks] (iii) Why is a red-black tree a better general-purpose search structure than a splay tree? Under what circumstances would you choose to implement a splay tree in preference to a red-black tree, and why? [4 marks] (b) Heapsort is an O(n log(n)) sorting algorithm based on the heap data structure. (i) What is the heap property? [1 mark] (ii) Briefly describe how heapsort is related to the classic quadratic-time selection sort algorithm, explaining how heapsort manages to sort more efficiently.

(a) What is the time complexity of binary search on a list of N items? [1 mark] (b) Binary search requires list items to be in sorted order. What is the best possible worst-case time complexity achievable by a comparison-based sorting algorithm? Credit will be given for a clear explanation of your answer, but there is no need to provide a formal mathematical analysis or proof. [7 marks] (c) A researcher proposes a ternary search algorithm which repeatedly compares the search key with the two list items that most accurately trisect the remaining sorted search space. (i) Derive asymptotic expressions for the number of list items queried by binary search and by ternary search in the worst case. Explain your derivations in terms of worst-case executions of the search algorithms. [6 marks]

Write java program to read two integer and swap the values using third variable. Java program to read a full names (first and last together) from a text file and print the name in the' last, first

For each of the following, indicate whether the statement is true or false, and explain why this is the case (no marks will be awarded for an answer with no explanation). (a) The Windows XP Executive is mostly implemented in user mode. (b) Floating-point hardware can be used to invert the access matrix. (c) Polled-mode I/O is sometimes preferable to interrupt-driven I/O. (d) Microkernel operating systems are faster than monolithic systems. (e) Windows XP is architecturally more secure than Unix.

Suppose that you are forbidden from using printf or Integer.toHexString, or indeed any other existing library way of doing it, but you still need to display a Java integer in hexadecimal as one to eight digits. For instance, you are to display the number 19 (decimal) as the string "13", and 1 must come out as "ffffffff". Write a Java method called toHex that takes an integer as its argument and returns the string form of the hexadecimal representation of that number. Explain clearly how your code works, commenting on how it avoids displaying unnecessary leading zeros and how negative numbers are handled. [10 marks] 4 Algorithms (a) Using big-O notation, state the average time and space complexity of quicksort. [2 marks] (b) What is the worst-case time and space complexity of quicksort? Briefly explain how this worst-case behaviour can occur. [3 marks] (c) A programmer implements a two-phase sorting algorithm comprising a partial quicksort, which does not recurse on list partitions of 10 items or fewer, followed by an ordinary insertion sort. What is the worst-case time complexity of the second phase? Explain your answer with the aid of a diagram.

(a) This question concerns the data structure of queues. (i) Describe the primitive queue operations. [3 marks] (ii) Describe an efficient implementation of queues, presenting code fragments as appropriate (a complete program listing is not required). [3 marks] (iii) Carefully discuss the efficiency of your implementation, using the concept of amortised time. [4 marks] (b) Write an ML function to compute all permutations of its argument, a list. (You may assume that the elements of this list are distinct.) For example, given the argument [1, 2, 3], the result should be a list consisting of the elements [1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2] and [3, 2, 1] in any order. For full credit, your code must be well structured and clearly explained. [10 marks] 6 Foundations of Computer Science (a) Contrast ordinary lists, lazy lists and mutable lists by (i) presenting the ML datatype declaration of each type of list, and [3 marks] (ii) implementing a filter functional for each type of list. [7 marks] (The mutable version should remove the elements that do not satisfy the given predicate, rather than constructing a new list.) (b) The intersection of two dictionaries is the largest dictionary that agrees with them both. For example, if one dictionary is cat=3, dog=2, rabbit=9 while the other is cat=4, dog=2, hamster=9, then their intersection is dog=2. Code an ML function to compute the intersection of two dictionaries, where dictionaries are represented by binary search trees. You may assume that the dictionary lookup and update operations are provided. For full credit, your solution must be simple and clear.

(a) FIFO, LRU, and CLOCK are three page replacement algorithms. (i) Briefly describe the operation of each algorithm. [6 marks] (ii) The CLOCK strategy assumes some hardware support. What could you do to allow the use of CLOCK if this hardware support were not present? [2 marks] (iii) Assuming good temporal locality of reference, which of the above three algorithms would you choose to use within an operating system? Why would you not use the other schemes? [2 marks] (b) What is a buffer cache? Explain why one is used, and how it works. [6 marks] (c) Which buffer-cache replacement strategy would you choose to use within an operating system?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Describe how you might deal with each.

Answered: 1 week ago