Question: Consider this algorithm countEven(A): Input: une sequence Table of integers Output: the number of even numbers in the table. Example: countEven({20, 44, 45, 32, 5,
Consider this algorithm countEven(A): Input: une sequence Table of integers Output: the number of even numbers in the table. Example: countEven({20, 44, 45, 32, 5, 64, 18, 7, 37, 48}) = 6 should be the correct answer count = 0; for (i = 1; i <= 10; i++){ if ((A[i] & 3) == 0) // test whether the two rightmost bits are ones
a) (5 points) Is this algorithm correct? (Answer only Yes or No) b) (10 points) Whatever is your answer, prove it using the fastest method: a counterexample, a proof by contradiction, or a proof by induction.
count++;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
