CS FundamentalsVery hardGATE CS
Which Hoare triple is valid for integer variables (partial correctness)?
- A. {x > 0} y := x * x {y > x}
- B. {true} y := x * x {y > 0}
- C. {x > 0} y := x - 1 {y > 0}
- D. {x ≥ 2} y := x * x {y ≥ 2 * x}
Correct answer: D. {x ≥ 2} y := x * x {y ≥ 2 * x}
x² ≥ 2x holds exactly when x ≥ 2 or x ≤ 0, so the last triple holds. The others fail at a boundary: x = 1 gives y = x in the first and y = 0 in the third, and x = 0 gives y = 0 in the second.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- This loop sums an array: python i = 0; s = 0 while i < n: s = s + a[i] i = i + 1 Which assertion is a loop invariant (true every time the…
- Two identical servers run in parallel (the system works while at least one does). Each fails independently with an exponential failure…
- A team fits the Goel–Okumoto reliability-growth model μ(t) = a(1 − e^(−bt)) to its test data, with a = 120 expected total faults and b =…
- Why does the classic hardware 'bathtub' failure curve not fit software?
- A static analyser is described as SOUND for null-pointer dereferences. What does that guarantee?
- A three-way merge compares five separate regions of a file. Base / ours / theirs: R1 a / a / a; R2 b / B1 / b; R3 c / c / C2; R4 d / D1 /…