Question 1
Solution:
Set A
- What does the function call f(31, 0) return? Answer: 0
- What does the function call f(899, 0) return? Answer: 5
- The function computes the number of zeros in the binary representation of the number. Any equivalent way of stating the same should be awarded as well.
Set B
- What does the function call f(25, 0) return? Answer: 3
- What does the function call f(999, 0) return? Answer: 8
- The function computes the number of ones in the binary representation of the number. Any equivalent way of stating the same should be awarded as well.
Rubrics
- 1 point for the correct answer to part a
- 1 point for the correct answer to part b
- 3 points for the correct answer to part c
- 1 point if the student understands how the function works and has given an example of input-output but cannot clearly state what the function computes. (part c )
- 0.5 point if the student understands how the function works but cannot clearly state what the function computes. The student provides no examples.