Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here are definitions of sequences and trees with integer elements: type iseq = Nil | Cons of int * (unit -> iseq) type itree =

Here are definitions of sequences and trees with integer elements: type iseq = Nil | Cons of int * (unit -> iseq) type itree = Leaf of int | Branch of itree * itree (a) In an ascending sequence such as 1, 3, 3, 7, . . . each element is at least as large as the previous elements. Given two ascending sequences, write  function merge2 that produces a sequence of the elements of both in ascending order. For example, passing 1, 3, 3, 7, . . . and 2, 4, 5, 9, . . . to merge2 should produce the sequence 1, 2, 3, 3, 4, 5, 7, 9, . .  (i) Define a function equal_seq that compares two sequences for equality. [5 marks] (ii) Define sequences s1 and s2 for which equal_seq s1 s2 does not terminate. [3 marks] (c) The fringe of a tree is the left-to-right sequence of the values at the leaves. For example, the fringe of Branch (Leaf 3, Branch (Leaf 10, Leaf 4)) is the sequence 3, 10, 4. (i) Define a function fringe that computes the fringe of a tree. Your function should have the following type: val fringe : itree -> iseq [5 marks] (ii) Using the functions you have defined above or otherwise, write  function equal_fringes that determines whether two trees have equal fringes. [2 mark

A W × H matrix can be represented in OCaml by a flat list: a list that concatenates the rows in order. For each of the following alternative ways to represent a 2D matrix in OCaml: State the type T of the representation; Give a function create w m: int -> float list -> T that constructs the matrix of type T equivalent to the input flat list m with row width w; Give a function get r c m: int -> int -> T -> float that gets the element of the matrix m at row r and column c. State the asymptotic complexity of the get function in terms of W and H (a) A list of lists. [5 marks] (b) An array of arrays. [6 marks] (c) A functional array of functional arrays. [9 marks] Your answers may use the List module and assume this functional array code: type 'a tree = Lf | Br of 'a * 'a tree * 'a tree;; exception Subscript;; let rec update = function | Lf, k, w -> if k = 1 then Br (w, Lf, Lf) else raise Subscript | Br (v, t1, t2), k, w -> if k = 1 then Br (w, t1, t2) else if k mod 2 = 0 then Br (v, update (t1, k / 2, w), t2) else Br (v, t1, update (t2, k / 2, w));; let rec sub = function | Lf, _ -> raise Subscript | Br (v, t1, t2), 1 -> v | Br (v, t1, t2), k when k mod 2 = 0 -> sub (t1, k / 2) | Br (v, t1, t2), k -> sub (t2, k / 2);; 

 

You need to write OCaml code to help a local park ranger count the different types of trees present in a region of Cambridgeshire woodland. (a) Define an OCaml type tree that can distinguish between an oak, birch or maple tree, and also any other species with an arbitrary string name. [1 mark] (b) Define two OCaml values with the following signatures: (i) val describe : tree -> string that accepts a tree parameter and returns a human-readable string. (ii) val identify : string -> tree that accepts a lowercase string parameter and returns a tree. Explain briefly how the OCaml compiler can statically check if you have handled all the input possibilities for the input parameters to describe and identify. [4 marks] (c) Define a type stree that only distinguishes between three species oak, birch or maple and no others. Implement functions for the following signatures with similar functionality to the earlier identify function: val identify exn : string -> stree val identify opt : string -> stree option Briefly discuss the tradeoffs between your two approaches. [5 marks] (d) You now need to implement a simple simulator before starting real surveys. Trees will occur in the following fixed infinite sequence: oak, birch, oak, maple, maple, and then repeat from the beginning. (i) Define a function val spotter : unit -> stree that will return the sequence of trees when called multiple times. [5 marks] (ii) Define a purely functional alternative spotter that calculates the next stree in sequence, using only the input arguments to the function to calculate the return value. Write down an example application of this function with the input arguments and the expected output result.(Hint: you may need to pass in the complete sequence as one of the arguments.) [5 mark

In this exercise, we will develop a game engine to play a simplified version of the game of Mastermind. In simplified Mastermind, player A selects a list of n colours among 3 possible colours: Red, Green and Blue (e.g., [Red; Red; Green; Blue] if n = 4). Player B has to guess player A's list of colours by proposing lists of colours in sequence until she finds the list proposed by player A. Every time player B proposes a list of colours, she gets feedback in the form of a number x. (x is the number of colours that are in the correct position). For example, if player A's list is [Red; Red; Green; Blue] and player B guessed [Red; Green; Green; Red], then x = 2 (the first Red and second Green are at the right positions). Note that x ≤ n. (a) Define a type colour to represent a colour. [2 marks] (b) Given two colour lists, write  function feedback that returns x. The first argument a is the list of player A, and the second argument b is a list of player B. Raise a SizeMismatch exception if the lengths of both lists do not match. You may need to introduce a helper function. [4 marks] (c) Using currying, define a test function that takes a list proposed by player B and returns x. This function should assume that player A's list is [Blue; Green; Red]. [2 marks] (d) What is the type of test in Part (c)? [2 marks] (e) Write  function generate lists that generates all possible colour lists of a given length n. The function takes a single argument n. You may use the concatenation operation @ and List.map function. Tip: generate 2 should output 32 = 9 lists. [6 marks] (f ) Given a colour list of player B and a feedback x, write  function valid lists that takes two arguments b and x and returns all possible lists that player A could have chosen (such that they match the feedback given to player B).

 

Three alternative representations for non-negative integers, n, are: • Peano: values have the form S(... S(Z) ...), applying S n times to Z where S and Z are constructors or constants of some data type. • Binary: values are of type bool list with 0 being represented as the empty list, and the least-significant bit being stored in the head of the list. • Church: values have the form fn f => fn x => f(... f(x) ...), applying f n times to x (a) Write ML functions for each of these data types which take the representation of an integer n as argument and return n as an ML int. [6 marks] (b) Write ML functions for each of these data types which take representations of integers m and n and return the representation of m + n. Your answers must not use any value or operation on type int or real. [Hint: you might it useful to write  function majority: bool*bool*bool -> bool (which returns true when two or more of its arguments are true) and to note that the ML inequality operator '<>' acts as exclusive-or on bool.] [10 marks] (c) Letting two and three respectively be the Church representations of integers 2 and 3, indicate whether each of the following ML expressions give a Church representation of some integer and, if so what integer is represented, and if not giving a one-line reason. (i) two three (ii) three two (iii) two ◦ three (iv) three ◦ two

(a) We are interested in performing operations on nested lists of integers in ML. A nested list is a list that can contain further nested lists, or integers. For example: [[3, 4], 5, [6, [7], 8], []] We will use the datatype: datatype nested_list = Atom of int | Nest of nested_list list; Write the code that creates  value of the type nested list above. [1 mark] (b) Write the function flatten that flattens a nested list to return a list of integers. [3 marks] (c) Write the function nested map f n that applies a function f to every Atom in n. [4 marks] (d) What is the type of f in Part (c)? [1 mark] (e) Write a function pack as xs n that takes a list of integers and a nested list; the function should return a new nested list with the same structure as n, with integers that correspond to the integers in list xs. Note: It is acceptable for the function to fail when the number of elements differ. Example: > pack_as [1, 2, 3] (Nest [Atom 9, Nest [Atom 8, Atom 7]]); val it = Nest [Atom 1, Nest [Atom 2, Atom 3]]: nested_list [6 marks] (f ) What does the data type nested zlist correspond to? [2 marks] datatype nested_zlist = ZAtom of int | ZNest of (unit -> nested_zlist list); (g) Write the function that converts a nested zlist to a nested list. [3 marks

 

Write brief notes on four of the following aspects of the language C++. In some of the cases it may be appropriate to compare what C++ does with the situation in other programming languages such as C, ML or Modula-3. (a) Overloaded functions and operators. (b) Templates as a way of achieving operations on lists where the types of the items in the lists must be kept flexible. (c) Consistency checks when a program is kept in several files and these are compiled at different times. (d) Inheritance and virtual functions. (e) The problems of writing code that is portable from one host machine to

(a) A classical bit-flip channel has probability of error p, and a n-bit repetition code is used to suppress the error. If n is even, find the probability that a 'majority vote' decoding returns no answer. [2 marks] (b) A qubit is encoded using a 3-bit repetition code. If it is known that the qubits will only ever encounter noise that can be modelled as independent, identically distributed bit-flips, with the probability of a bit flipping equal to p, then give the threshold of this code. State any assumptions made. [3 marks] (c) A certain error-correction code suppresses the physical qubit error, p, to O(p 2 ) and has a threshold of 1%. For a quantum circuit with 20 gates, find the number of layers of concatenation required to achieve an overall error probability of at most 10% when: (i) The gate error-rate is 0.99%. (ii) The gate error-rate is 0.9%. [5 marks] (d) For a certain implementation of a 3-qubit phase-flip code the principle of deferred measurement is invoked to allow the recovery operations to be enacted conditional on qubit states rather than measurement outcomes. Let |mi be the two-qubit state of the parity check qubits, then the recovery circuit must perform the following operations on the three code qubits: |mi Recovery Operations |00i I ⊗ I ⊗ I |10i Z ⊗ I ⊗ I |11i I ⊗ Z ⊗ I |01i I ⊗ I ⊗ Z Design the recovery circuit using only gates from the set: {H, T, CNOT, Toffoli}. [6 marks] (e) How many more gates would be required if only gates from the set {H, T, CNOT} can be used in the recovery circuit for Part (d)? [4 marks]

(a) Find the eigenvectors, eigenvalues and spectral decomposition of the observable A = 0 1 1 0 and give the outcome of measuring the expectation of the observable on the states: (i) |0i (ii) √ 1 2 (|0i − |1i) (iii) 1 2 |0i + √ 3 2 |1i [8 marks] (b) A quantum mechanical system has Hamiltonian H = H1 + 2H2 It is desired to use a quantum computer to approximately simulate the operator e −iHt for some t. It is possible to build quantum circuits U1 and U2 to perform the operations U1 = e −iH1t U2 = e −iH2t Give a circuit, U, consisting of one of more instances of U1 and U2 that approximates e −iHt such that e −iHt − U = O(t 3 ). Show your calculations to verify that the circuit does indeed achieve this. [8 marks] (c) Quantum Phase Estimation can be used to estimate the ground state energy of quantum mechanical systems. The Inverse Quantum Fourier Transform is a key component of Quantum Phase Estimation. Give the circuit for the 2-qubit Inverse Quantum Fourier Transform using only gates from the s(a) In the superdense coding protocol, Alice and Bob each have one qubit from the entangled pair √ 1 2 (|00i + |11i), which enables Alice to send two bits of classical information to Bob, using a single qubit. Explain the superdense coding protocol in detail, and show that it does indeed enable the transmission of two bits using a single qubit. [10 marks] (b) This question concerns entangled states. (i) Suppose Alice transmits the two-bit string '00' using the superdense coding protocol and an evesdropper, Eve, intercepts the qubit transmitted by Alice, measures it in the computational basis and then re-transmits to Bob. Find the probability that Bob correctly receives '00'. [5 marks] (ii) Suppose further that prior to Eve's interception there is a 50% probability that the qubit experiences a bit-flip. What is the probability that Bob correctly receives 00? (Note that after Eve's retransmission no errors occur) [5 marks]et {H, CT, CNOT}, where CT is a controlled T gate. [4 mark

 

 ???? ???? H H ???? 2 First register Second register inverse QFT ????1 (a) Show that U = √ 1 5 1 2 2 −1 is unitary. [1 mark] (b) Show that 1 + √ 5 2 and 1 − √ 5 2 are (un-normalised) eigenvectors of U, and give the eigenvalues. [2 marks] (c) The figure shows the quantum circuit for quantum phase estimation to two bits of precision for a single-qubit unitary. Quantum phase estimation is performed to two bits of precision with U = √ 1 5 1 2 2 −1 and |ui = 1 0 , find the quantum state, |ψ1i, before the inverse quantum Fourier transform is executed. [7 marks] (d) What possible measurement outcomes can occur (i.e., after the inverse quantum Fourier transform, with measurement in the computational basis)? Give probabilities for each possible outcome. [6 marks] (e) Give two applications of quantum phase estimation, and for each give the state, |ui, in which the second register should be prepared, and briefly outline how these can be prepared in practise. [4 marks]

 Boolean formula φ with n variables in it can be seen as defining a function f : {0, 1} n → {0, 1}, and we say that φ is satisfiable if there is some x ∈ {0, 1} n such that f(x) = 1. (a) Explain how f can be suitably represented as a unitary operation Uf on a complex space of dimension 2n+1. [3 marks] (b) Suppose that we are given a blackbox implementing Uf . Describe how this would be used to form the Grover iterate which can be repeated to find a value x such that f(x) = 1. [5 marks] (c) If there is exactly one value x such that f(x) = 1, how many iterations of the Grover iterate would you use to find this value? What is the probability of finding it? [3 marks] (d) If there are M distinct values such that f(x) = 1, how many iterations of the Grover iterate would you use to find one of these values? What is the probability of finding one of them? [3 marks] (e) If you are able to turn an arbitrary formula φ into an implementation of the corresponding unitary operator Uf , how would you use this to give an algorithm for determining whether φ is satisfiable or not? Give an estimate of the running time of your algorithm in terms of n. [6 marks]

i need help for this project  (if You are expected to investigate a case study (either drawn from your work site, or alternatively being secured through formal access) to analysis only two business processes from commencement to completion, with a focus on the more important or interesting tasks within the process. Be careful to select business processes of appropriate size. If you choose the processes which are too simple, you will find it hard to demonstrate your mastery of MIS concepts. Conversely, if you choose processes that are too complex, you may find it difficult to complete the assignment within the specified time. Consider discussing your choice with me before you begin work. The central premise of this project is that you are able to develop familiarity with describing the functional activities of the organization of your chosen case study, investigating the functional problems, and suggesting remedial actions in view of the IS and its capabilities to improve outdated business process. should be  focus may be based on the following:

Providing background information of your chosen organization/system.
 Identify the kind of systems (software).
Describing TWO business processes; including all related business functions -Please draw on wide sets of process mapping tools, i.e. a cross-functional diagram or alternatively flowchart. Therein, for rigors and coherence purposes, you will need to draw on relevant literature and modelling techniques to the issues raised in your chosen case study.  
Describing the technology and its main IT infrastructure components in your chosen case.
Outlining organizational benefit from the extant IS application in the chosen process. Articulating the management level involved in using the system.  
Discussing the business and IS strategies influenced by this kind of technology.
Commenting on any issues\ dysfunctional areas that arose during research of the case study.
it should be for example like SAP or oracle for example in any organization for example in HR what is the process with the follow diagram

 

void mergesortint a].int i,int j) int mid; ifi

mid=+j)/2: mergesort(a,i.mid); //left recursion mergesort(a,mid+1.); //right recursion merge(a,i.mid.mid+ 1.,);: //merging of two sorted sub-arrays void merge(int a].int i1,int j1,int i2,int j2) int temp[50]; //array used for merging int ij.k; i=i1;//beginning of the first list J=i2;//beginning of the second list k-0;

i=i1;//beginning of the first list j=i2; //beginning of the second list k=0; whilei<=j1 &&j«=j2) //while elements in both lists if(ali]

ifa[il

 

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

Probability And Statistics For Engineering And The Sciences

Authors: Jay L. Devore

9th Edition

1305251806, 978-1305251809

More Books

Students also viewed these Computer Network questions