Quiz Correction
-
Q12 Binary representation of indigo Correct answer is C because the decimal value 75 is equal to the binary number 01001011.
-
Q15 Compare output of program a and b The correct answer is A because Program A initializes i to 1. Inside the loop, it prints i and then increments i. The loop terminates when i is greater than 10, which occurs after 10 is printed. Program A prints 1 2 3 4 5 6 7 8 9 10. Program B initializes i to 0. Inside the loop, it increments i and then prints i. The loop terminates when i equals 10, which occurs after 10 is printed. Program B prints 1 2 3 4 5 6 7 8 9 10.
-
Q16 Error in wordList traversal The correct anser is D because the program traverses wordList starting at the end of the list and moving to the start of the list, removing any elements that are equal to “the” or “a” along the way.
-
Q20 Average amount of data per user The correct answer is A because the two line graphs are roughly the same shape. Each value on the right line graph is about 10 times the corresponding value on the left line graph. Therefore, the average amount of data stored per user is about 10 GB.
-
Q21 File size distribution The correct anser is B because the files that are up to 10 MB represent 17% + 24% + 25% + 10%, or 76%.
-
Q22 Simulate spinner The correct answer is D because for this spinner, there is a 1/8 chance of “Lose a turn”, a 1/8 chance of “Move 2 spaces”, and a 6/8 chance of “Move 1 space”. The variable spin is set to a random value between 1 and 8.
-
Q28 Swap alpha and beta The answer is B because code segment II assigns the initial value of alpha to temp, then assigns the initial value of alpha to beta. The initial value of alpha, which has been stored in temp, is then assigned to beta. Therefore, both variables are assigned the initial value of alpha.
-
Q32 Calculate course grade The answer is D because this code segment takes the sum of the individual scores and subtracts the lowest score. To obtain the average, the result is divided by one less than the number of scores.
-
Q39 Error in calculating sum The correct answer is C because as is, the program does not include the first element of the list in the sum because i is incremented before nums[i] is added to sum. By interchanging these two lines of code, the program will include all of the first ten elements of the list when computing the sum.
-
Q41 TrimLeft and TrimRight The correct answer is C because statement II is incorrect. It will first call TrimRight to remove the eleven rightmost characters, which includes more than just the file extension. It will then pass the result to TrimLeft to remove the four leftmost characters, which does not remove the entire date tag.
-
Q50 Reasonable time algorithms The correct answer is D because Algorithm I accesses elements 2n times (twice for each of n elements), which is considered reasonable time. Algorithm II accesses n^2 elements (n times for each of n elements), which is considered reasonable time. Algorithm III accesses 10 elements, which is considered reasonable time.
-
Q56 Compare execution times of two versions The correct answer is D because version II calls the GetPrediction procedure twice for each element of idList, and then again in the final display statement. This results in the procedure being called nine times, requiring approximately 9 minutes of execution time.
-
Q58 Error in AnyPairs procedure The correct answer is C because for this set of inputs, false is returned even though two of the inputs are equal in value. The IF condition x = y evaluates to false, so the body of the ELSE statement is executed. The expression y = z evaluates to false, so false is returned.
-
Q65 Calls to concat and substring The correct answer is B and C. C is correct because this code segment stores the substring “jack” in animal. It then concatenates “jack” and “a”, storing the result “jacka” in animal. Lastly, it concatenates “jacka” and the substring “lope”, storing the result “jackalope” in animal.
-
Q66 Error in counting perfect numbers The correct answer is A and C. C is correct because every integer from start to end should be checked, so currentNum should only be incremented inside the loop but outside the body of the IF statement.
-
Q67 Error in numOccurrences procedure The correct answer is A and B. A is correct because the last time “birch” is encountered in the list, count is again increased to 1, causing the procedure to return 1 instead of the intended result 2. B is correct because this code segment, count is increased to 1 the first time “maple” is encountered in the list. However, count is reset to 0 when the code segment moves to the next list element. This causes the procedure to return 0 instead of the intended result 1.