Question

In: Computer Science

According to the loop invariant theorem, a valid loop invariant ?(?)I(n) must have the property that...

According to the loop invariant theorem, a valid loop invariant ?(?)I(n) must have the property that

Select one:

a. ?(?)=0I(n)=0 after a finite number of steps.

b. After the loop, ?→?(?)P→I(N) where ?P is the postcondition.

c. ?(0)→?I(0)→Q, where ?Q is the precondition.

d. None of the other answers are correct

Solutions

Expert Solution

THE LOOP INVARIANT THEOREM

A->B means that A implies B

(d) is the correct answer as none of the option is correct

(a) is wrong because I(n) does not beomes 0 after a finite number of steps, it is the G which becomes 0 after a finite number of steps.

(b) is wrong because after the loop I(N) implies P as given in point IV of algorithm

(c) is wrong because Q implies I(0) as given in point I of the algorithm


Related Solutions

Find a loop invariant (I) for the following while loop with the post-condition {Q: S=1}, where...
Find a loop invariant (I) for the following while loop with the post-condition {Q: S=1}, where S is an integer and the operator / represents an integer division. Show your work step by step to receive full credit. while (S > 1) do S = S / 2; }
Show that two m×n matrices are equivalent if and only if they have the same invariant...
Show that two m×n matrices are equivalent if and only if they have the same invariant factors, i.e. (by Problem 4), if and only if they have the same Smith normal form.
What property must emulsifiers have that fats lack?
What property must emulsifiers have that fats lack?
My question is if n<r when there is no loop. I can't enter numbers again.Where is...
My question is if n<r when there is no loop. I can't enter numbers again.Where is the problem? How do it? #include int fact(int no) { if (no == 0) return 1; return no * fact(no - 1); } int calc(int n, int r,int *com,int *per) //as given in question formula of permutation n!/(n-r)! { *com=fact(n)/(fact(r)*fact(n-r)); *per=fact(n)/fact(n-r); } int main() { int n=0,r=0,co,pe; while(n<=0 || r<=0) { printf("Enter N value:"); scanf("%d",&n); printf("Enter R value:"); scanf("%d",&r); if(n { printf("N value should...
A contract is a set of legally enforceable promises. A valid contract must have agreement/ offer...
A contract is a set of legally enforceable promises. A valid contract must have agreement/ offer consideration, legal object/purpose, and parties with legal capacity. Sometimes two parties will enter into a contract with the intent to benefit a third party. In these situations, a third-party beneficiary contract is formed. Third-party contracts are difficult to follow with the rights and obligations of the parties. You are required to create a contract (keep it simple-one page). You will select the subject of...
1. There are n identical users of a common-property resource. The output of user i is...
1. There are n identical users of a common-property resource. The output of user i is denoted yi . “Pollution” is a by-product of output. Let pi = yi be the amount of pollution generated by user i’s output yi . The profit that accrues to user i—not deducting for pollution damages—when i’s output is yi is given by 2yi − y 2 i . Pollutants reduce profit. When y1 + ... + yn is total output, the loss to...
I need to generate a loop for 1,000 Monte Carlo iterations in R. I have two...
I need to generate a loop for 1,000 Monte Carlo iterations in R. I have two randomly generated standard normal variables for this with sample sizes of 100.
The owner of the property must sign the contract to confirm they have received a special...
The owner of the property must sign the contract to confirm they have received a special document. What is the document and what does it contain? it is question of certificate 4 in building and construction from assesment of CPCCBC4008B Conduct on-site supervision of building and construction projects
I have n books with n different titles. I want to put them on the shelves...
I have n books with n different titles. I want to put them on the shelves in my library. How many different ways are there to arrange them on one shelf? On two shelves? On k shelves?
I have to use a sentinel while loop to complete the following task in a java...
I have to use a sentinel while loop to complete the following task in a java program, I want to see how this is executed so I can better understand how the sentinel while loop works. Thank you! Convert Lab 10 from a counter controlled WHILE loop to a sentinel WHILE loop. Do the following: Prompts the user to enter a grade or a -1 to quit. IF the user entered a -1 THEN Display a message that the User...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT