AlbaLed Posted October 25, 2003 Share Posted October 25, 2003 13. Suppose one wishes to be certain that after execution of the statement if a > b then x := a the value of x will equal the value of a. Of the following, which is the weakest (least restrictive) condition that must necessarily hold before execution of that statement? A. (x = a) or (a > b) B. (x = a) and (a > b) C. a > b D. x > b E. x = a 29. S -> A0B A -> BB|0 B -> AA|1 What is the number of terminal strings of length 5 generated by the context-free grammar shown above? (A) 4 (B) 5 © 6 (D) 7 (E) 8 I did solve this problems to my best, but no match with ETS's answer keys AlbaLed Quote Link to comment Share on other sites More sharing options...
ozgulker Posted October 25, 2003 Share Posted October 25, 2003 13. Certainly a > b must hold, oth. you wont enter the if. weakest (least restrictive) condition among the choices thus with (x = a) or (a > b) you enter the if. Don't mind why x = a, or x = sth else, or sth else = sth else. The important thing here is (a > b) and any stupid thing ORed with it. 29. I hate those questions by the way. You will try one by one and hope you will not miss anything. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted October 25, 2003 Author Share Posted October 25, 2003 So you're saying answer is B ? If that is the case, I think that is a strong condition because if either of the clauses is true, then after the execution x is definitely a. Did you check choice D, by any chance? Is that a strong condition? Thanks AlbaLed Quote Link to comment Share on other sites More sharing options...
ozgulker Posted October 25, 2003 Share Posted October 25, 2003 No I say the answer is a A. (x = a) or (a > b) What I understand from weakest(least restrictive) condition is that it should contain something that must necessarily hold, in this case (a>b) and something that does not affect the execution (in this case (or (x=a). Strong condition is something that should hold always, in this case (x > a) is a strong condition. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted October 25, 2003 Author Share Posted October 25, 2003 Sorry I meant A, My main concern is about D, because it only contains a condition which does not affect the execution at all. I think A is a weak condition, but D is weaker. What do you think maked D a stonger conditiona than A? AlbaLed Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted October 25, 2003 Author Share Posted October 25, 2003 Here is a usefull definition "The weakest precondition is the least restrictive precondition that will guarantee the validity of the associated postcondition (x=a in our case)" I had forgotten it So D in this case is not even a valid precondition AlbaLed Quote Link to comment Share on other sites More sharing options...
ozgulker Posted October 25, 2003 Share Posted October 25, 2003 Sorry this time, I misspelled it. Strong condition is something that should hold always, in this case (x > a) is a strong condition. IT should be a > b by the way. Yes you have given the answer yourself. A is the weakest, C is the strongest, B, D, E does not satisfy the conditions. Also you should check out the exact wording in the question Suppose one wishes to be certain that after execution of the statement if a > b then x := a the value of x will equal the value of a. Of the following, which is the weakest (least restrictive) condition that must necessarily hold before execution of that statement? B, D, E are out of the table right away. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted October 25, 2003 Author Share Posted October 25, 2003 Thanx here is a useful link that describes semantics http://clem.mscd.edu/~gordona/csi3210/lects/lect19.html Can you try 29 and see what you get? AlbaLed Quote Link to comment Share on other sites More sharing options...
rafi_dery Posted October 25, 2003 Share Posted October 25, 2003 29. (B) Since S -> A0B to get a string of length 5, the possibilities are: len(A) | len(B) --------|------- 4 | 0 impossible 3 | 1 two: 00101 10001 * 2 | 2 one possiblity: 11000 1 | 3 two: 00011 00110 ** 0 | 4 impossible * (3,1): S->A0B->BB0B->AAB0B->00101 S->A0B->BB0B->BAA0B->10001 ** (3,2): S->A0B->A0AA->A0BBA->00110 S->A0B->A0AA->A0ABB->00011 Quote Link to comment Share on other sites More sharing options...
basantikaveeru Posted October 25, 2003 Share Posted October 25, 2003 I am not sure if B and E are off the table, since they would also gurantee the post-condition. Also not sure if "strongest" could be defined as a>b, it could be x=a as well. Weakest condition is the one which could cover iff (if and only if) test. Thanks for the link albaled. Quote Link to comment Share on other sites More sharing options...
AlbaLed Posted October 25, 2003 Author Share Posted October 25, 2003 Guys, only D is of the table, it is not a valid precondition, here is how I would rank them B C or E A Nice approach rafi_dery AlbaLed Quote Link to comment Share on other sites More sharing options...
ozgulker Posted October 25, 2003 Share Posted October 25, 2003 Sorry guys, I have not seen that x = a actually satisfies the condition. (I was distracted by the a > b more). Yes, then the result is as shown by albaled. Quote Link to comment Share on other sites More sharing options...
crackit Posted October 25, 2003 Share Posted October 25, 2003 hi guys, i agree with answers A and B Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.