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