2. (20 pts.) The following algorithm returns the median of three numbers. Add as
ID: 3529130 • Letter: 2
Question
2. (20 pts.) The following algorithm returns the median of three numbers. Add assert statements that describe what is true (or should be true) before the procedure starts, before each if statement, and at the end of the procedure. You may simply assert m is the median of a, b, and c" rather than trying to gure out a way to state this as a logical statement. procedure median(a; b; c) // need assertion here x := a y := b // need assertion here if x > y then x := b y := a // need assertion here if y < c then m := y else if x > c then m := x else m := c // need assertion here return mExplanation / Answer
x=a;
y=b;
if(x > y) x=b;y=a; // y contains larger of (a,b)
hence if(y < c) median=y [increasing sequence x < y < c]
else if(x > c) median=x [c < x < y]
else median=c [x < c <y]
Hence true
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.