Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started