Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(7. 5pts) Computational problem solving: Proving correctness/incorrectness Is th

ID: 3880976 • Letter: #

Question

(7. 5pts) Computational problem solving: Proving correctness/incorrectness Is the algorithm below correct or incorrect? Prove it ! It is supposed to count the number of all identical integers that appear consecutively in a file of integers. Eg., lf f contains “1 2 3 3 3 4 35 66 78 8 8 8" then the correct answer is 9. Count(f: input file) count, i, j : integer count = 0 while (end-of-file(f) = false) i-read-next-integer (f) if (end-of-file (f) = false) then j = read-next-integer(f) if i-j then count - count+1 return count

Explanation / Answer

For the below input

1 2 3 3 3 4 3 5 6 6 7 8 8 8 8

index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

FIrst iteration

i =1 (read next integer calls index 0)

j =2  (read next integer calls index 1)

count = 0

Second Iteration

i = 3  (read next integer calls index 2)

j = 3   (read next integer calls index 3)

count = 1

Third iteration

i = 3 (read next integer calls index 4)

j = 4 (read next integer calls index 5)

count = 1

Fourt iteration

i = 3 (read next integer calls index 6)

j = 5 (read next integer calls index 7)

count = 1

Fifth iteration

i = 6 (read next integer calls index 8)

j = 6 (read next integer calls index 9)

count = 2

sixth iteration

i = 7 (read next integer calls index 10)

j = 8 (read next integer calls index 11)

count = 2

seventh iteration

i = 8 (read next integer calls index 12)

j = 8 (read next integer calls index 13)

count = 3

So from above algo the count will show only 3 as comparison is not done correct a step is skipped