Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

pseudocode - Prove how the algorithm works

Given the pseudocode

MUL(a,b) 
   x=a
   y=0
   WHILE x>=b DO
      x=x-b
      y=y+1
   IF x=0 THEN
      RETURN(true)
   ELSE
      RETURN(false)

I have to prove how the algorithm works.

So far I have only explained how it works, but I am not sure how you are supposed to prove how it works.

Edit: Just to clarify. I did ask this question on another thread. But the two questions are separate. The assignment I am working on consists of 3 questions. The 1st question is where I explained how the algorithm works. The 2nd question is on my other thread and the 3rd question (this thread) is where I have to prove how the algorithm I explained in question 1 works. The reason why I asked this question is not to get the answer to the question, but simply an explationation as to what I am asked to do since I can't seem to figure it out myself. Personally I would just do the same as the 1st question, but that wouldn't make much sense.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try to show the Pre-condition and Post-condition of the algorithm. Pre-condition predicates the initial state before execution and Post-condition predicates the final state after execution.

The algorithm is correct if it can be proved that if the pre-condition is true, the post-condition must be true.

check this out for more details: prove how algorithm works


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...