Question 1

The code segment below is intended to swap the values of the variables first and second using a temporary variable, temp.

The block code consists of 3 lines. Line 1: temp, left arrow, first Line 2: first, left arrow, second Line 3: MISSING CODE

Which of the following can be used to replace missing code so that the code segment works as intended?

Answer 1

Answer: B
I had choosen option A as the code segment assigns the inital value of First to temp, and then assings the initial value of second to first. The inital value of second which has been store in first is then assigned to second. Therfore the vaule of second has not changed from its original value.

This makes sense as the code is sort of a loop that assignes the same value over and over again, the value of second.

Question 10

The procedure One word, Draw Circle, open parenthesis, x comma y comma r, close parenthesis can be used to draw a circle on a coordinate grid. The circle is centered at the coordinate x comma y and has a radius of runits. The procedure will be used to draw the following figure on a coordinate grid.

The figure shows an x y coordinate plane with 3 circles plotted. Each circle has a radius of 2. 1 circle is centered at the coordinate (3, 6), 1 circle is centered at the coordinate (5, 4), and 1 circle is centered at the coordinate (7, 2).

Which of the following code segments can be used to draw the figure?

Asnwer 10

Answer: B
I had choosen option C but it turns out that is incorrect as the code segment draws a circle centered at the co-ordinates (7,2) and then moves to the right and up, drawing circles at (9,4) and (11,6).

The main code change for that woulr be yPos = yPos -2 instead of +2 which i had choosen, ie the cirlce moves down and not up.

Ouestion 11

A spinner is divided into three sections. The sector labeled Red is four times as large as each of the sectors labeled Blue and Yellow, which are of equal size.

The figure shows a spinner divided into 3 sections. The sector labeled Red is 4 times as large as each of the sectors labeled Blue and Yellow, which are of equal size.

The procedure below is intended to simulate the behavior of the spinner.

The block code consists of 2 lines. Begin block Line 1: PROCEDURE Spinner Line 2, indented 1 tab: begin block, MISSING CODE, end block End block

Which of the following can be used to replace missing code so that the procedure correctly simulates the spinner?

Answer 11

Answer: D
I had choosen the option A but the correct answer is option D as the code segment simulates a spinner in which selecting each of the three sections in equally likely. The option which I had choosen assigns a random value spin of 1,3 but with a 1,6 the spinner becomes more even with all colors giving each color more likely the chance to be choosen. And thus option D is the correct answer.

Question 14

Consider the two programs below.

Program A: The block code consists of 4 lines. Line 1: i, left arrow, 1 Begin block Line 2: REPEAT UNTIL, begin block, i greater than 10, end block Begin block Line 3, indented 1 tab: DISPLAY, begin block, i, end block Line 4, indented 1 tab: i, left arrow, i plus 1 End block End block Program B: The block code consists of 4 lines. Line 1: i, left arrow, 1 Begin block Line 2: REPEAT UNTIL, begin block, i greater than 10, end block Begin block Line 3, indented 1 tab: i, left arrow, i plus 1 Line 4, indented 1 tab: DISPLAY, begin block, i, end block End block End block Which of the following best compares the values displayed by programs A and B?

Answer 14

Answer: C

The answer to this is C but I had choosen B instead. This makes sense as the porgram does not oupt the same number of value but a different set of value as the display i and the i = i + 1 are switched which thereby leads to different sets of output values. The correct answer is that both programs display the same number of values but the values themselves differ and the program is st to repeat until i > 10.

Question 17

Which of the following actions could be used to help reduce the digital divide?

I. Providing free education and training on how to use computing devices II. Providing free or low-cost computing devices to low-income individuals III. Providing networks and infrastructure to people in remote areas

Answer 17

Answer: D I had put I and II but the correct answer is all of them I, II and III. This makes sence as a lack of access to networks contributed to digital divide. The issue can only be addressed by providing networks and infrastructure. And thus by providing all three, free education and training on how to use computing devices, low cost computing decives and network and infrostructure to people in remote areas can help reduce the digital divide.

Question 20

An application program interface (API) provides a procedure Max, which returns the greater of its two integer arguments.

A programmer would like to find the greatest of three integer values a, b, and c. Which of the following expressions will produce the desired result in every case?

Answer 20

Answer: A I had origianlly put the answer as option b, it being Max(a,b)- Max(b,a) because i thought it would lead to the average value. But that value would be a totally different one. This expression only produces the different between the maximum of A and B and the maximum of b and c. The correct expresion of Max(max(a,b)), makes sense as it first finds the max of a and b then the max of that value and c which ould lead to the code always fiidin gthe greatest of the three interger values a, b and c no matter what the senario is.

Question 21

The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing right.

The figure shows a grid of squares with 4 columns and 8 rows. The square in the first row and third column is gray, and all other squares are white. The square in the fourth row and first column contains a right-facing triangle, representing a robot. A path of arrows shows the robot’s movement from its initial location to the gray square. The path shows the robot moving 2 squares to the right from its initial location, then 3 squares up to the gray square.

Consider the procedures below.

The block code consists of 3 lines. Begin block Line 1: PROCEDURE, Move X Times, 1 word with capital M, X, and T, begin block, x, end block Begin block Line 2, indented 1 tab: REPEAT x TIMES Begin block Line 3, indented 2 tabs: MOVE underscore FORWARD End Block End block End block The block code consists of 3 lines. Begin block Line 1: PROCEDURE, Right X Times, 1 word with capital R, X, and T, begin block, x, end block Begin block Line 2, indented 1 tab: REPEAT x TIMES Begin block Line 3, indented 2 tabs: ROTATE underscore RIGHT End block End block End block

Which of the following code segments will move the robot to the gray square?

Answer 21

Answer: B This makes sense as the robot moves the robot 2 times forward and then turn to the right thrice and them moves three steps forward. I seem to have missed is by chance as my code segments moves the robot forward three squares, rotates it thrice and move the robot 3 spaces forward. This was a silly error that occured on my behalf, but is a great learning opportunity for psuedo code practice as that focused a lot in the AP exam.

Question 23

The following figures represent different ways of configuring a network of physically linked computers labeled P, Q, R, and S. A line between two computers indicates that the computers can communicate directly with each other. In which configuration is it NOT possible to have redundant routing between computers P and S?

Answer 23

Answer B

I had origianlly chosen option A thinign that since the question as for there to no possible redundance in the path that was travelled, but as it turns out there are multiple way that the code could’ve travvled between those four point if and when they are connected that way but if the four point were connected in the way it was said in the answer the only possible route would either be forward or backwards and nothing in the middle and thus reduces the most possible redunances in the code.

Question 26

The grid below contains a robot represented as a triangle, initially facing up. The robot can move into a white or gray square but cannot move into a black region.

The figure shows a grid of squares with 5 columns and 4 rows. The square in the fourth row and first column contains an upward-facing triangle, representing a robot. The first row contains all white squares. The second row contains, left to right, white, black, black, black, white. The third row contains, left to right, white, black, gray, white, white. The fourth row contains, left to right, white, black, black, black, white.

The code segment below uses the procedure One word, Goal Reached, which evaluates to true if the robot is in the gray square and evaluates to falseotherwise.

The program consists of 4 lines. Begin program Line 1: REPEAT UNTIL, open parenthesis, one word Goal Reached, open parenthesis, close parenthesis, close parenthesis Line 2: open brace Line 3: MISSING CODE Line 4: close brace End program.

Which of the following replacements for missing code can be used to move the robot to the gray square?

Answer 26

Answer: D This option i had origianlly chosenwas a for the psuedo code question but the correct answer is D. The answer which I had choosen move the robot one sqaure forward from tis inital location and then rotated the robot right. From there, the robot cannot move forward and the body of the if statement is fullfilled and thus the loop does not exicute anymore. The correect option qould be D which moves the robot forawd and right is it is possible, the difference between my code and the correct one was the includion of MOVE_FORWARD () command in the if loop.

Question 28

A text-editing application uses binary sequences to represent each of 200 different characters. What is the minimum number of bits needed to assign a unique bit sequence to each of the possible characters?

Answer 28

Answer: D The option that I had origianlly choosen was B ir 6 but using 6 bits will only allow for upto 64 characters and 2 to the 6 is 64 then the question asked for 200 characters and thus 2 to 8 would give you 200 characters and thus 8 bits would be the correct answer.

Question 29

The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output.

The figure shows a logic gate with inputs A, B, C, and D. Inputs A and B lead into an AND gate. Inputs C and D lead into an OR gate. The outputs of the AND and OR gates lead into a second OR gate. The output of the second OR gate is labeled output.

For which of the following input values will the circuit have an output of false ?

Answer 29

Answer: A

I had origianlly chosen option C which would lead to the result ad the and gate producing an output of false and the first or gate producing an output of true. The second or gate will have one false input and one true input causing the circuit to have an output of true. But this was not the intended output as the intented output was false as thus setting A to true B,C,D to false would lead to two false inputs leading to the overall putput to be false fufillign the requirements for the question.

Question 31

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom right square of the grid and facing toward the top of the grid.

The figure shows a grid of squares with 5 columns and 5 rows. The bottom right square of the grid contains an upward-facing triangle, representing a robot. The top left square of the grid is shaded gray. All other squares are white.

The following programs are each intended to move the robot to the gray square. Program II uses the procedure One word, Goal Reached, which returns true if the robot is in the gray square and returns

false otherwise. Program I: The block code consists of 5 lines. Begin block Line 1: REPEAT 4 TIMES Begin block Line 2, indented 1 tab: MOVE underscore FORWARD Line 3, indented 1 tab: ROTATE underscore LEFT Line 4, indented 1 tab: MOVE underscore FORWARD Line 5, indented 1 tab: ROTATE underscore RIGHT End block End blockProgram II: The block code consists of 5 lines. Begin block Line 1: REPEAT UNTIL, begin block, Goal Reached, 1 word with capital G and R, end block Begin block Line 2, indented 1 tab: IF, begin block, CAN underscore MOVE, begin block, forward, end block, end block Begin block Line 3, indented 2 tabs: MOVE underscore FORWARD End block Line 4, indented 1 tab: ELSE Begin block Line 5, indented 2 tabs: ROTATE underscore LEFT End block End block End block

Answer 31

Asnwer: C I had originally choosen the option B as my answer but that would be incorrect as program 1 also correctly move the robot tot the gray square by repeatedly moving the robot forward, rotating left, moving forward and rotating right. Thus the correct answer would be that both program 1 and 2 move the robot correctly to teh gray square as both program might look different but produce the same output in the end. Program 1 loops trhough tthe code until the ouput is received but program two sets restrictions which make the robot move in specific spots and block to reach it’s final goal of the gray block.

Question 37

The two code segments below are each intended to display the average of the numbers in the list One word, num List. Assume that One word, num List contains more than one value.

Program I: The block code consists of 5 lines. Line 1: sum, left arrow, zero Begin block Line 2: FOR EACH num IN num List, 1 word with capital L Begin block Line 3, indented 1 tab: sum, left arrow, sum plus num Line 4, indented 1 tab: a v g, 1 word, left arrow, sum divided by LENGTH, begin block, num List, end block End block End block Line 5: DISPLAY, begin block, a v g, end blockProgram II: The block code consists of 5 lines. Line 1: sum, left arrow, zero Begin block Line 2: FOR EACH num IN num List, 1 word with capital L Begin block Line 3, indented 1 tab: sum, left arrow, sum plus num End block End block Line 4: a v g, 1 word, left arrow, sum divided by LENGTH, begin block, num List, end block Line 5: DISPLAY, begin block, a v g, end block

Which of the following best describes the two code segments?

Answer 37

Answer: D

I had originally put the answer as C but that would be incorreect as both code segments display the correct average. Code segment 1 requires more airthmetic opration because it performs the operation sum/lenght (numlist) within the loop, while the code segment II performs the same operation only once. And thus both code segments disply the correct average but code segment 1 required more airtmetic operation than code segment 11 and thus the correct answer ould be option C and not option D.

Question 41

Grades in a computer science course are based on total points earned on a midterm exam and a final exam. The teacher provides a way for students to improve their course grades if they receive high scores on the final exam: if a student’s final exam score is greater than the student’s midterm exam score, the final exam score replaces the midterm exam score in the calculation of total points.

The table below shows two students’ scores on the midterm and final exams and the calculated total points each student earns.

A table is shown with 4 columns and 3 rows. The first row of the table contains the column headers, from left to right, Student Name, Midterm Exam Score, Final Exam Score, Total Points Calculation. The table is as follows: Khalil, 90, 80, 90 plus 80 equals 170 Josefina, 70, 90, 90 plus 90 equals 180

Khalil does better on the midterm exam than on the final exam, so his original midterm and final exam scores are added to compute his total points. Josefina does better on the final exam than on the midterm exam, so her final exam score replaces her midterm exam score in the total points calculation. A programmer is writing a procedure to calculate a student’s final grade in the course using the score replacement policy described. The student’s exam scores are stored in the variables One word, midterm Exam and One word, final Exam. The procedure Max, open parenthesis, a comma b returns the larger of a and b.

Which of the following could be used in the procedure to calculate a student’s total points earned in the course and store the result in the variable One word, adjusted Total ?

Answer 41

Answer: B

I had originally put the answer to this question as A bt this would be incorrect as the expression assigns only one score to the adjustTotal variable but option B which is the adjustedTotal = Max( midterm, finalExam) + final exam assigns the correct variable and also calculates a student’s total points earned in the course and store the results in the varible adjustedTotal. And thus for the question above the correcrt answer would be option B

Question 44

A computer program uses 4 bits to represent nonnegative integers. Which of the following statements describe a possible result when the program uses this number representation?

I. The operation 4 plus 8 will result in an overflow error.

II. The operation 7 plus 10 will result in an overflow error.

III. The operation 12 plus 3 will result in an overflow error.

Answer 44

Answer: B

I had originally choosen the option C wich indluded the answers as both II and II but the correct answer to this qould be only II. The operation 10 / 7 causes an overflow error but 12 + 3 does not produce a results large enough to cause an over flow error. Again I feel like this was one of the question that I jsut skimmed through without acutally reading it, and proabaly confused both the + and the / signs in the question which lead to the overall incorrect answer.

Question 45

A NAND gate is a type of logic gate that produces an output of false only when both of its two inputs are true. Otherwise, the gate produces an output of true. Which of the following Boolean expressions correctly models a NAND gate with inputs P and Q ?

Answer 45

Answer: C

The correct answer for this question would be C and not B as the expression (Not p) and Q evaluated to false when P is false and Q is true. A NAND gate should only evaluate to false when both the inputs are true and thus is option C where P and q are defined into a single parenthses, the function NOT (P and Q) would be the correct answer for this question which correctly modfels a NAND gat with teh inputs of P and Q .

Question 46

A student wants to create an algorithm that can determine, given any program and program input, whether or not the program will go into an infinite loop for that input.

The problem the student is attempting to solve is considered an undecidable problem. Which of the following is true?

Answer 46

Answer: D

The correct answer for this question would be option D instead of option C which i had orignnaly put as it is not possible to create an algorithm to solve an undecidable problem for all programs and inputs. An unpredictable problem and the name suggests would be unpredictable and thus writing an for that problem would really be impossible to do.

Question 50

The procedure below searches for the value target in list. It returns true if target is found and returns false otherwise.

The block code consists of 5 lines. Begin block Line 1: Procedure Contains, begin block, list, comma target, end block Begin block Line 2, indented 1 tab: FOR EACH element IN list Begin block Line 3, indented 2 tabs: IF, begin block, element equals target, end block Begin block Line 4, indented 3 tabs: RETURN, begin block, true, end block End block End block Line 5, indented 1 tab: RETURN, begin block, false, end block End Block End Block

Which of the following are true statements about the procedure?

I. It implements a binary search.

II. It implements a linear search.

III. It only works as intended when list is sorted.

Answer 50

Answer: B

I had originnaly put the asnwer to this question as D but the correct answer to the question is B as the procedure implments a linear search but the list does not need to be sorted. As thus option B which is II only is the correct answer as, as mentioned above the program only implements a linear search which does not need for the list to be sorted. - This would lead the correct answer to be II only.

Question 54

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things.

Procedure Square, open parenthesis, n, close parenthesis returns the value N squared. Procedure Cube, open parenthesis, n, close parenthesis returns the value N raised to the third power. Which of the following procedures is a generalization of the procedures described above?

Answer 54

Answer: D

I had originally put the answer to this question to be B as i thought the procedure Fourth (n), whicih returns the value of n^4 would be the corrrect answer but that is not the case as my answer is incorrect. The fourth procedure calculated a power of n similar to square and cude procudre but it does not generalize this functionality to calculate any power of n. And thus for this question above the correct answer would be D instead of B ad proceudre power (n, m), which returns the value of n^m produces a generalization of the proceudre describe in the question above.

Question 63

The program below is intended to count the number of prime numbers in a list called numbers and display the result. The program uses the procedure One word, is Prime, open parenthesis, n, close parenthesis, which returns true if n is a prime number and false otherwise.

The program does not work as intended.

The program consists of 11 lines. Begin program Line 1: count, left arrow, 0 Line 2: FOR EACH value IN numbers Line 3: open brace Line 4: count, left arrow, 0 Line 5: IF, open parenthesis, one word is Prime, open parenthesis, value, close parenthesis, close parenthesis Line 6: open brace Line 7: count, left arrow, count plus 1 Line 8: close brace Line 9: count, left arrow, count plus 1 Line 10: close brace Line 11: DISPLAY, open parenthesis, count, close parenthesis End program.

Which two lines of code should be removed so that the program will work as intended?

Answer 63

Answer: B & C

The correct answer to the question above would be B and C instead of A and D as line 1 would be incorrect as the variable count should be set to 0 before the loop so that it starts counting at 1 and line 7, the variable count should be incremented within the if stament so that it only increases whenever the value is prime. And thus option B and D, lines 4 and 9 would be the correct answer as in line 4the count is set to 0 and in line 9 the count in set to be the count plus 1 which when removed makes the procedure function correctly and the isPrime fucntion returns true if n is a prime number and false if otherwise.

Question 65

A program is created to perform arithmetic operations on positive and negative integers. The program contains the following incorrect procedure, which is intended to return the product of the integers x and y.

The program consists of 11 lines. Begin program Line 1: PROCEDURE Multiply, open parenthesis, x comma y, close parenthesis Line 2: open brace Line 3: count, left arrow, 0 Line 4: result, left arrow, 0 Line 5: REPEAT UNTIL, open parenthesis, count equals y, close parenthesis Line 6: open brace Line 7: result, left arrow, result plus x Line 8: count, left arrow, count plus 1 Line 9: close brace Line 10: RETURN, open parenthesis, result, close parenthesis Line 11: close brace End program.

A programmer suspects that an error in the program is caused by this procedure. Under which of the following conditions will the procedure NOT return the correct product?

Answer 65

Answer: B and D For this question I got 1/2 of it correct with getting D as part of the answer. A would be incorrect as the when the values of X and Y are both positive then the proceudre will correctly calcualte the product by adding X to itself Y times but when Y is negetive then the codition count = y will never be met since teh count begin at 0 and repeatedly increases and thus under the contions of B and D the proceudre will never return the correct product.

Question 66

The procedure Smallest is intended to return the least value in the list numbers. The procedure does not work as intended.

The program consists of 12 lines. Begin program Line 1: PROCEDURE Smallest, open parenthesis, numbers, close parenthesis Line 2: open brace Line 3: min, left arrow, numbers, open bracket, 1, close bracket Line 4: FOR EACH number IN numbers Line 5: open brace Line 6: IF, open parenthesis, number is less than min, close parenthesis Line 7: open brace Line 8: RETURN, open parenthesis, number, close parenthesis Line 9: close brace Line 10:close brace Line 11: RETURN, open parenthesis, min, close parenthesis Line 12: close brace End program.

For which of the following values of One word, the List will Smallest, open parenthesis, one word, the List, close parenthesis NOT return the intended value?

Answer 66

Answer: C & D

I had originally choosen the pair of anwer to be B and C as I thought those values of theList will not return the intended value but that was not the case as the correct pair was C and D. For the list 20,10, 30 and 40; 10 would be the first value smalled than the first number in the list so that procedure returns the ocrrect value 10 and thus is teh oppsite of the intended value. But option c which returns the output as 20 and option D which outputs the the resultant value as 30 would both not return the intended value and thus fufills what the question originally asked for. WHich of the following reuslts in a FALSE asnwer…