Jump to content
Urch Forums

2 Questions from ets sample '99


AlbaLed

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...