Ask your own question, for FREE!
Mathematics 8 Online
OpenStudy (anonymous):

Give a postcondition for the following algorithm that completely describes how the final value of i is related to x. Precondition: x is a positive odd integer. i ← 0 while i < x do i ← i + 2 i=???

OpenStudy (anonymous):

@Zarkon

OpenStudy (anonymous):

@Loser66

OpenStudy (loser66):

It' s computer science, sweeties. tag @e.mccormick. He is the right one. (computer science student)

OpenStudy (e.mccormick):

Does i ← 0 mean i=0? and i ← i + 2 mean i = i + 2?

OpenStudy (e.mccormick):

Seems like some sort of meta language or logic description, and not really programming. However, the principal should be the same. A while loop continues as long is the condition is true. Therefore, because x is any positive, odd integer, and i starts at 0, the first time through i will become 2. If x is 1, this all ends right there. If x is not 1, then it is still greater than 2 and the loop starts over. Now i becomes 4. Again, is x 3? If so, the loop condition is met and it ends. Otherwise it repeats. This happens as many times as needed until i passes x, but it stops as soon as i passes x. Therefore.... can you see what i would have to be at that point?

OpenStudy (anonymous):

seems like the answer is not that simple..but thx for ur input

OpenStudy (anonymous):

thx @Loser66

OpenStudy (loser66):

hahaaha why do you say thank you to me? e.mccormick helps you, right?

OpenStudy (loser66):

wrong address, sweeties.!!

OpenStudy (e.mccormick):

hmm... What language is it in. The ← may have a different meaning. Otherwise, \(i=x+1\) is the postcondition.

OpenStudy (anonymous):

I don't know what language it is..

OpenStudy (anonymous):

I know loser66, but u hooked it up lol

OpenStudy (loser66):

e.mccormick asks you about the program you study in C, C++ or java?

OpenStudy (e.mccormick):

Not just those. I feel malia667 got the question. Like I thought, it sounds like it is just a meta language or something manufactured for the course. Here is a reference to the sort of pre-post analysis I did to come up with my answer. It should be correct, so I don't know why it would fail to follow the same rules they describe there. http://cs.engr.uky.edu/~lewis/essays/algorithms/correct/correct1.html

OpenStudy (anonymous):

ok lemme take a look..yes its more of a general question

OpenStudy (anonymous):

@oldrin.bataku any ideas on this one?

OpenStudy (anonymous):

I can handle any CS or programming questions as well

OpenStudy (anonymous):

Note that since \(x\) is odd and \(i\) is even, we end up with the smallest even \(i\) that is greater than our odd \(x\) -- which happens to just be \(i=x+1\).

OpenStudy (anonymous):

ok just like what e.mccormick said..got it thanks :) let me see if that works

OpenStudy (anonymous):

It should make intuitive sense that repeatedly adding \(2\) to \(0\) gives you successive even integers, and the loop terminates once we reach an even number greater than or equal to \(x\) -- it'll always \(>\) since \(x\) is odd and thus we see it is necessarily \(i=x+1\)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!