1. (a) A mathematical property P is an invariant for the code fragment Code, if the...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. (a) A mathematical property P is an invariant for the code fragment Code, if the Triple: {P} Code {P} is true. Which of the following instances are true and which are false? In each case give values for the variables to support your answer. Property P x+y is even Code x+x+1 Property P x+Y A[i+1] then 4 SORTED false 5 return SORTED 1. Complete the above algorithm by replacing ? in lines 1 and 2, so that it satisfies the specification. [8 marks] [2 marks] [2 marks] ii. What is the complexity of this algorithm in notation? iii. How many times is line 3 executed in the best case? iv. Modify the algorithm to improve its best case performance. Give an example array which will demonstrate the improvement. [13 marks] 1. (a) A mathematical property P is an invariant for the code fragment Code, if the Triple: {P} Code {P} is true. Which of the following instances are true and which are false? In each case give values for the variables to support your answer. Property P x+y is even Code x+x+1 Property P x+Y A[i+1] then 4 SORTED false 5 return SORTED 1. Complete the above algorithm by replacing ? in lines 1 and 2, so that it satisfies the specification. [8 marks] [2 marks] [2 marks] ii. What is the complexity of this algorithm in notation? iii. How many times is line 3 executed in the best case? iv. Modify the algorithm to improve its best case performance. Give an example array which will demonstrate the improvement. [13 marks]
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Briefly describe ASCII and Unicode and draw attention to any relationship between them. [3 marks] (b) Briefly explain what a Reader is in the context of reading characters from data. [3 marks] A...
-
Download a copy of the ACFE Compensation Guide for Anti-fraud Professionals, which is available at no charge at: www.acfe.com/documents/2008-comp-guide.pdf. Based on this resource, answer the...
-
Explain the purpose of adding prior taxable gifts to current taxable gifts and show whether these prior gifts could be taxed multiple times over the years.
-
Firm LD, a calendar year taxpayer, owns 20,000 shares of MXP stock with a $160,000 basis. In November, LD's chief financial officer learned that MXP had just declared bankruptcy. The CFO was unable...
-
Outline the various issues related to project budgeting.
-
Monat Company has grown rapidly since its founding in 2002. To instill loyalty in its employees, Monat is contemplating establishment of a defined benefit plan. Monat knows that lenders and potential...
-
Five resistors 3.10, 30, 4.20, 5.10 and 6.802, are connected in parallel. This combination is then connected in series with a 13.10 resistor. Calculate the total resistance of the combination and the...
-
Jake claims that he can buy a $210,000 for about the same as his rent, and therefore he should definitely buy because he has heard that "renting is bad". Help him walk through this argument. a....
-
In an applied research context you do not need to explain the relationships between the variables in your conceptual model. Discuss this statement. (2-3 paragraphs).
-
Is Maslow's hierarchy of needs an still an accurate reflection of people's needs? In what ways does it reflect your individual needs or differ from your actual needs? Develop and suggest a revised...
-
Risk is an important aspect of business and investment. The impact of risk needs to be measured on all capital projects and investments. In fact, most accomplished investors consider the measure and...
-
List the pros and cons of socialism and the pros and cons of capitalism. Now look back at your lists and tell me what you think are the functions of the economic system under capitalism and what are...
-
Recent balance sheets are provided for Twitter, Incorporated, a global platform for real-time public self-expression and conversation. TWITTER, INCORPORATED CONSOLIDATED BALANCE SHEETS (In thousands,...
-
The functions s and t are defined as follows. s(x) = -2x+1 t(x)=-5x-5 Find the value of s (t (4)).
-
The XYZ Corporation had a net profit of $120,000 in the fiscal year just ended. The capital stock consists of 8,000 shares of 8% convertible preferred stock with a par value of $50 per share and...
-
As economic conditions change, how do banks adjust their asset portfolio?
-
In each case determine if X lies in U = span{Y, Z}. If X is in U, write it as a linear combination of Y and Z; if X is not in U, show why not. (a) X = [2 -1 0 1]T, Y=[l 0 0 1]T, and Z=[0 1 0 1]T. (b)...
-
Let T: P2 R3 be defined by T(p) = (p(0)), p(1),(p(2)) for all p in P2. Let B = {1,x, x2}and D = [(1,0,0),(0,1,0),(0,0,1)] (a) show that MDB (T) = And conclude that T is an isomorphism. (b) Generalize...
-
Find the possible flows in each of the following networks of pipes. (a) (b) 50 fs 60 40 50 25 60 40
-
Suppose \(Y_{i}\) is distributed i.i.d. \(N\left(0, \sigma^{2} ight)\) for \(i=1,2, \ldots, n\). a. Show that \(E\left(Y_{i}^{2} / \sigma^{2} ight)=1\). b. Show that \(W=\left(1 / \sigma^{2} ight)...
-
Suppose that \(Y_{1}, Y_{2}, \ldots, Y_{n}\) are random variables with a common mean \(\mu_{Y}\); a common variance \(\sigma_{Y}^{2}\); and the same correlation \(ho\) (so that the correlation...
-
Suppose you have some money to invest - for simplicity, \(\$ 1\) - and you are planning to put a fraction \(w\) into a stock market mutual fund and the rest, \(1-w\), into a bond mutual fund. Suppose...
Study smarter with the SolutionInn App