Skip to main content

Preparation Manual

Print this page

Section 4: Sample Selected-Response Questions
Computer Science 8–12 (241)

Expand All Answers | Collapse All Answers

This section presents some sample exam questions for you to review as part of your preparation for the exam. To demonstrate how each competency may be assessed, sample questions are accompanied by the competency that they measure. While studying, you may wish to read the competency before and after you consider each sample question. Please note that the competency statements do not appear on the actual exam.

For each sample exam question, there is a correct answer and a rationale for each answer option. The sample questions are included to illustrate the formats and types of questions you will see on the exam; however, your performance on the sample questions should not be viewed as a predictor of your performance on the actual exam.

Domain I—Technology Applications Core

Competency 001—The computer science teacher knows technology terminology and concepts; the appropriate use of hardware, software and digital files; and how to acquire, analyze and evaluate digital information.

1. Which of the following is the principal advantage of saving a word processing document in rich-text format?

  1. The document can be viewed in any Web browser.
  2. A formatted document can be transferred between different applications.
  3. The document can take up less space in memory.
  4. A formatted document can be scanned for viruses when sent as an email attachment.
Enter to expand or collapse answer.Answer expanded
Option B is correct because most word processing applications can read and write rich-text format documents. Option A is incorrect because typical Web browsers do not support rich-text documents directly. Option C is incorrect because rich-text documents take up more space in memory than the corresponding documents in a plain text format or in the native format of the word processing application. Option D is incorrect because other formats can be scanned for viruses as well.

2. Which of the following would most likely be considered unacceptable use of information by a teacher?

  1. Using the school district’s database to determine gender distribution in local schools
  2. Using the Internet history on a classroom computer to audit student Internet use
  3. Using students’ personal data to create a mailing list for a local charity
  4. Using classroom records to determine recipients of academic awards
Enter to expand or collapse answer.Answer expanded
Option C is correct because it fails to protect personally identifiable information. Option A is incorrect because gender (by itself, without any other additional information) is not considered personally identifiable information and because aggregate statistics are computed. Option B is incorrect because students should have no expectations of privacy when accessing Internet content using a classroom computer. The school can monitor the network usage in order to determine compliance with acceptable use guidelines. Option D is incorrect because classroom records are appropriate sources to use when selecting winners of academic awards.

3. Consider the uniform resource locator (URL) https://example.net/index.html. Which of the following are contained in the URL?

  1. Browser name
  2. Email address
  3. File name
  4. Host name
  5. MAC address
  6. Protocol
Enter to expand or collapse answer.Answer expanded
Options C, D, and F are correct. Option C is correct because the file name is indicated by index.html. Option D is correct because the hostname is indicated by example.net. Option F is correct because the protocol is indicated by https. Options A, B, and E are incorrect because the URL does not contain information about browser name, email address, or MAC address.

Competency 002—The computer science teacher knows how to use technology tools to solve problems, evaluate results and communicate information in a variety of formats for diverse audiences.

4. Students in a Texas classroom have been communicating with a class in New York by videoconference. The two classes find that the images they receive from each other occasionally freeze for up to 30 seconds before the video continues. This type of problem can most often be solved by

  1. increasing bandwidth.
  2. upgrading cameras.
  3. increasing video resolution.
  4. upgrading monitors.
Enter to expand or collapse answer.Answer expanded
Option A is correct because an increase in bandwidth will allow more data to be transferred and will help eliminate the freezing of the image. Option B is incorrect because updating cameras will not directly allow more data to be transferred. Option C is incorrect because increasing the video resolution will increase the amount of data to be transferred and could therefore cause the images to freeze for longer time periods. Option D is incorrect because upgrading monitors will not directly allow more data to be transferred.

5. Which of the following is the most appropriate format for graphics that are to be embedded within an Internet document?

  1. BMP
  2. TIFF
  3. PNG
  4. HTML
Enter to expand or collapse answer.Answer expanded
Option C is correct because PNG is a popular image format on the Internet because of its relatively small image size. Other Web-friendly image formats are GIF and JPEG. Options A and B are incorrect because BMP and TIFF images are typically very large. Option D is incorrect because HTML is not a format for graphics.

6. Suppose that the class grade for a six-week period is based on 3 tests (T1, T2, T3), each of which counts for 15%, 4 quizzes (Q1, Q2, Q3, Q4), each of which counts for 10%, and a homework notebook (HW), which counts for 15%. The grades are recorded in a spreadsheet similar to the one below.

Blank. A B C D E F G H I J
1 Name T1 T2 T3 Q1 Q2 Q3 Q4 HW AVG
2 Jane 87 92 80 76 79 87 74 90 Blank.
3 Joe 91 85 77 78 88 96 90 92 Blank.
4 Bill 65 72 70 80 81 74 77 80 Blank.
5 Brenda 96 88 91 76 91 100 74 98 Blank.

Which of the following formulas would be a correct calculation of the six-week weighted average for Jane?

  1. equals left paren B 2 plus C 2 plus D 2 plus E 2 plus F 2 plus G 2 plus H 2 plus I 2 right paren divided by 8.
  2. equals left paren B 2 plus C 2 plus D 2 plus I 2 right paren multiplied by 0.15 plus left paren E 2 plus F 2 plus G 2 plus H 2 right paren multiplied by 0.1.
  3. equals left paren B 2 plus C 2 plus D 2 plus I 2 right paren multiplied by 15 plus left paren E 2 plus F 2 plus G 2 plus H 2 right paren multiplied by 10.
  4. equals left paren B 2 plus C 2 plus D 2 plus I 2 right paren divided by 15 plus left paren E 2 plus F 2 plus G 2 plus H 2 right paren divbided by 10.
Enter to expand or collapse answer.Answer expanded
Option B is correct because it demonstrates the correct computation of a weighted mean, where each value is multiplied by the corresponding percent value and then the results are summed. Option A is incorrect because it calculates the mean, not the weighted average. Option C is incorrect because it is the correct result multiplied by 100. Option D is incorrect because it uses division rather than multiplication.

Competency 003—The computer science teacher knows how to plan, organize, deliver and evaluate instruction that effectively utilizes current technology for teaching the Technology Applications Texas Essential Knowledge and Skills (TEKS) to all students.

7. A teacher has assigned students several topics to discuss outside of class using an electronic form of communication. The teacher wants the students’ messages to be organized by topic and wants to have all historical messages available to students. To facilitate this type of communication most effectively, the teacher should have students

  1. participate in a threaded discussion group.
  2. send email messages with attached document files.
  3. update pages on the class’s Web site.
  4. engage in dialogue in a real-time chat room.
Enter to expand or collapse answer.Answer expanded
Option A is correct because it meets both the requirement that the messages are organized by topic and the requirement that all old messages are available. Option B is incorrect because it does not meet either requirement. Option C is incorrect because updating a Web page to add a message is unnecessarily time-consuming and would likely lead to contention issues between students attempting to post messages simultaneously. Option D is incorrect because the messages will not be organized by topic.

8. A computer science teacher is going to have the students in a class read an article from a technology journal as homework. Which of the following instructional strategies best ensures that the students will fully understand the material?

  1. The teacher asks the students the following day if they fully understand the material.
  2. The teacher asks the students to take notes on the material as they are reading it.
  3. The teacher assigns problems or questions on key concepts for the students to complete after they have finished reading the material.
  4. The teacher reviews the material in a class presentation the following day and instructs the students to take notes on the presentation.
Enter to expand or collapse answer.Answer expanded
Option C is correct because students can demonstrate understanding by answering problems or questions on key concepts from the material. Options A, B, and D are incorrect because they do not include a robust way for students to demonstrate understanding of the material.

Domain II—Program Design and Development

Competency 004—The computer science teacher knows problem-solving strategies and different procedures for program design.

9. Consider the following flowchart diagram, where arr[0..len–1] is an integer array of length len. Assume that the elements arr[0], arr[1], ..., arr[len–1] have already been initialized.

A flowchart of an algorithm.

The flowchart outline description is as follows: 1. Top of the chart begins start. 2. part left arrow 0. 3. k left arrow 1. 4. k is less than l e n question mark. a. if no, stop. b. if yes, go to step 5. 5. a r r left bracket k right bracket is greater than a r r left bracket 0 right bracket question mark. a. if yes, proceed to k left arrow k plus 1, then go back to k is less than l e n question mark. b. if no, part left arrow part plus 1, then sway left bracket a r r, part, k right bracket. proceed back up to k left arrow k plus 1 then go back to k is less than l e n question mark.

Which of the following pseudocode segments implements the algorithm in the flowchart?

  1. int part ← 0
    int k ← 1
    while ( k < len )
    if ( arr[k] ≤ arr[0] )
    part ← part + 1
    swap ( arr, part, k )
    end if
    k ← k + 1
    end while
  2. int part ← 0
    int k ← 1
    while ( k < len )
    k ← k + 1
    if ( arr[k] ≤ arr[0] )
    part ← part + 1
    swap ( arr, part, k )
    end if
    end while
  3. int part ← 0
    int k ← 1
    while ( k < len )
    if ( arr[k] > arr[0] )
    part ← part + 1
    swap ( arr, part, k )
    end if
    k ← k + 1
    end while
  4. int part ← 0
    int k ← 1
    while ( k < len )
    k ← k + 1
    if ( arr[k] > arr[0] )
    part ← part + 1
    swap ( arr, part, k )
    end if
    end while
Enter to expand or collapse answer.Answer expanded
Option A is correct because the code segment matches the steps in the flowchart. Two variables are initialized, followed by a while loop that is executed when k < len. Within the while loop, the condition on the if statement is the opposite of the corresponding condition in the flowchart, so part is updated and swap is called if the condition on the if statement is true. The variable k is incremented and the condition in the while loop is tested again. Option B is incorrect because the increment of k needs to occur after the if statement. Option C is incorrect because the increment of part and the call to the swap method need to occur when the comparison arr[k] > arr[0] is false. Option D is incorrect for both of the reasons stated in options B and C.

10. Which of the following best describes the purpose of generating a flowchart as part of the design of a computer program?

  1. To test and maintain the efficiency of the overall program
  2. To present the steps needed to solve the programming problem
  3. To ensure that all methods are appropriately linked
  4. To determine the necessary number of global and local variables
Enter to expand or collapse answer.Answer expanded
Option B is correct because a flowchart is a graphic representation of a process, so it can be used to represent the steps in a computer program. Option A is incorrect because a flowchart is not a testing tool. Options C and D are incorrect because flowcharts cannot help to establish links between methods or analyze the variables used in a program.

Diagram of a UML class.

There are 3 rows and one column. The first row states "S T U". The second row has two levels. The first level of row two states minus a b c colon i n t. The second level of row two states minus d e f colon float. The third row has three levels as follows. The first level states plus g h i left and right paren colon i n t. The second level states plus j k l left and right paren colon float. The third level plus m n o left and right paren colon char.

11. Which of the following best describes the information conveyed by the UML class diagram above?

  1. A class named STU contains two private fields and three public methods.
  2. A class named STU contains two public fields and three private methods.
  3. A class named STU contains two private methods and three public fields.
  4. A class named STU contains two public methods and three private fields.
Enter to expand or collapse answer.Answer expanded
Option A is correct. The UML class diagram consists of three stacked boxes. The top box contains the name of the class—STU. The middle box indicates that the STU class contains two fields—abc and def. The two fields are private as shown by the minus sign in front of the field names. Similarly, the bottom box indicates that the STU class contains three methods— ghi(), jkl(), and mno(). The three methods are public as indicated by the plus sign in front of the method names. Option B is incorrect because the two fields are private. Options C and D are incorrect because the class has two fields.

12. Consider the following algorithm for finding the maximum value in an integer array x[0..n–1] of length n, where the index of array x starts at 0.

I. Initialize a variable, max, which will hold the largest value found in the array so far.
II. Go through the array elements and compare each value to max.
III. If a value is greater than max, set it as the new value of max.
IV. After going through the entire array, the maximum value in the array is the value of max.

Which of the following flowcharts represents the algorithm?

  1. Flowchart of an algorithm.The flowchart outline description is as follows: 1. Top of the chart begins start. 2. max left arrow x left bracket 0 right bracket. 3. k left arrow 0. 4. k is less than n question mark. A. If no, return max, then stop. B. If yes, x left bracket k right bracket is greater than max question mark. roman numeral 1, if no, go back to k is less than n question mark. Roman number 2, if yes, max left arrow x left bracket k right bracket, then k left arrow k plus 1, then go back to k is less than n question mark.
  2. Flowchart of an algorithm.The flowchart outline description is as follows: 1. Top of the chart begins start. 2. max left arrow x left bracket 0 right bracket. 3. k left arrow 0. 4. k is less than n question mark. A. If no, return max, then stop. B. If yes, x left bracket k right bracket is greater than max question mark. roman numeral 1, if no, k left arrow k plus 1, then go back to k is less than n question mark. Roman number 2, if yes, max left arrow x left bracket k right bracket, then k left arrow k plus 1, then go back to k is less than n question mark.
  3. Flowchart of an algorithm.The flowchart outline description is as follows: 1. Top of the chart begins start. 2. max left arrow x left bracket 0 right bracket. 3. k left arrow 0. 4. k is less than n question mark. A. If no, return max, then stop. B. If yes, x left bracket k right bracket is greater than max question mark. roman numeral 1, if yes, go back to k is less than n question mark. roman numeral 2, if no, max left arrow x left bracket k right bracket, proceed to k left arrow k plus 1, then go back to k is less than n question mark.
  4. Flowchart of an algorithm.The flowchart outline description is as follows: 1. Top of the chart begins start. 2. max left arrow x left bracket 0 right bracket. 3. k left arrow 0. 4. k is less than n question mark. A. If no, return max, then stop. B. If yes, x left bracket k right bracket is greater than max question mark. roman numeral 1, if yes, proceed to k left arrow k plus 1, then go back to k is less than n question mark. roman numeral 2, if no, max left arrow x left bracket k right bracket, proceed to k left arrow k plus 1, then go back to k is less than n question mark.
Enter to expand or collapse answer.Answer expanded
Option B is correct because the flowchart matches the steps in the algorithm. The variable max is initialized to the first element in the array. An array index k is initialized to 0. If the condition k < n is false, the value of the variable max is returned and the algorithm stops. If the condition k < n is true, the array element x[k] is compared to max. If x[k] is larger than max, then the value of x[k] is set as the new value of max, the array index k is incremented by 1, and the flow returns back to the condition k < n; otherwise, the value of max is not changed, the array index k is incremented by 1, and the flow returns back to the condition k < n. Option A is incorrect because the increment of k should execute regardless of whether the condition x[k] > max is satisfied or not. Option D is incorrect because the Yes and No branches for the x[k] > max condition are switched. Option C is incorrect because it represents a combination of the issues in options A and D.

Competency 005—The computer science teacher knows procedures for software development and implementation.

13. A software system is to be developed for which the requirements are well understood and the risk of failure is minimal. To meet these requirements, which of the following software development models would be most appropriate to use?

  1. Chaos
  2. Incremental
  3. Spiral
  4. Waterfall
Enter to expand or collapse answer.Answer expanded
Option D is correct because waterfall is typically used when requirements are well understood and the risk of failure is minimal. Options A, B, and C are incorrect because those software development models are typically used in situations where the requirements are not well understood at the beginning of a project and change is anticipated.

14. The most appropriate way to use a library of program code is to access the

  1. methods or functions by way of the interface.
  2. implementation details of the methods or functions.
  3. methods or functions by way of the source code.
  4. documentation of the methods or functions.
Enter to expand or collapse answer.Answer expanded
Option A is correct because the methods or functions in a library are accessed using an interface. Options B, C, and D are incorrect because accessing the implementation details, source code, or documentation provides information about how the methods or functions work but does not provide access to their functionality.

15. Consider the following pseudocode segment with integer variables, where the precondition at the beginning of the segment is missing.

// missing precondition
x ← x + 1
y ← y + x
// postcondition: y double equal sign =, or is equal to 2 times x.


Which of the following would be a valid precondition for the code segment above?
  1. y double equal sign, or is equal to x minus 1.
  2. y double equal sign, or is equal to x.
  3. y double equal sign, or is equal to x plus 1.
  4. y double equal sign, or is equal to x plus 2.
Enter to expand or collapse answer.Answer expanded
Option C is correct because the precondition y is equal to x plus 1 is equivalent to the postcondition y is equal to 2 times x. If x_pre and y_pre are the values of x and y before the code segment and if x_post and y_post are the values of x and y after the code segment, then we have the following relations.

x_post = x_pre + 1
y_post = x_pre + y_pre + 1


When x_post and y_post replace x and y in the postcondition y is equal to 2 times x, we get x_pre + y_pre + 1 = 2 * (x_pre + 1), or equivalently y_pre = x_pre + 1. Option A is incorrect because the given precondition is equivalent to the postcondition y == 2 * x − 2. Option B is incorrect because the given precondition is equivalent to the postcondition y is equal to 2 times x minus 1. Option D is incorrect because the given precondition is equivalent to the postcondition y is equal to 2 times x plus 1..

16. Consider the following pseudocode segment with floating point variables, where the function squareRoot is the standard square root function.

if ( /* missing condition */ )
answer ← squareRoot ( a / ( b – c ) )
end if

Assume the programming language evaluates compound Boolean expressions from left to right and short-circuits the logical operators and and or as soon as the result of an expression is known. Which of the following could replace /* missing condition */ so the code segment would not generate a run-time error?

  1. b – c ≠ 0
  2. a / ( b – c ) ≥ 0
  3. ( b – c ≠ 0 ) and ( a / ( b – c ) ≥ 0 )
  4. ( b – c ≠ 0 ) or ( a / ( b – c ) ≥ 0 )
Enter to expand or collapse answer.Answer expanded
Option C is correct. There are two run-time errors that might occur. The first one is a division-by-zero error which occurs when b − c equals 0. The second is a not-a-number (NaN) error which occurs when taking the square root of a negative number. Both of these conditions must be checked prior to executing the body of the if statement. Option A is incorrect because b − c ≠ 0 does not guarantee that a / ( b − c ) is nonnegative, possibly leading to the evaluation of a square root of a negative number. Option B is incorrect because the evaluation of a / ( b − c ) would generate a run-time error when the values of b and c are equal. Option D is incorrect because the logical operator or is short circuited as soon as b − c ≠ 0 is satisfied, possibly leading to the evaluation of a square root of a negative number.

Competency 006—The computer science teacher knows computer science terminology and concepts and the characteristics of different programming languages and paradigms.

17. Which of the following techniques is used by most programming languages to intercept events that disrupt the normal flow of a program’s execution?

  1. Code security
  2. Flow control
  3. Exception handling
  4. Error detection
Enter to expand or collapse answer.Answer expanded
Option C is correct because exception handling is used to intercept events. Options A, B, and D are incorrect because they refer to the presence of security holes in code, the flow of execution of programming statements, and the detection (but not necessarily handling) of errors in a program.

18. If execution speed and direct communication with devices such as controllers and processors are essential to the success of a project, which of the following programming languages would be most appropriate to use?

  1. C
  2. Java
  3. PHP
  4. Visual Basic
Enter to expand or collapse answer.Answer expanded
Option A is correct because C is a relatively small, efficient programming language that can be used to communicate directly with various devices. Options B, C, and D are incorrect because these languages are less appropriate to use when execution speed and direct communication with devices are essential.

19. How many bytes are needed for an array of 1,000 integers if each integer requires 32 bits of storage?

  1. 1,000 bytes
  2. 4,000 bytes
  3. 16,000 bytes
  4. 32,000 bytes
Enter to expand or collapse answer.Answer expanded
Option B is correct because an array of 1,000 integers is represented by a contiguous block of 1,000 integers and therefore requires 1,000 × 32 = 32,000 bits, or equivalently 32,000 over 8 = 4,000 bytes. Option A is incorrect because 1,000 bytes is the number of bytes needed for an array of 250 integers. Option C is incorrect because 16,000 bytes is the number of bytes needed for an array of 4,000 integers. Option D is incorrect because 32,000 bytes is the number of bytes needed for an array of 8,000 integers.

20. Which of the following is unique to the object-oriented paradigm of programming?

  1. Support for abstract data types (ADTs)
  2. Support for the concepts of encapsulation and inheritance
  3. Support for control structures
  4. Support for the practice of code reuse
Enter to expand or collapse answer.Answer expanded
Option B is correct because encapsulation and inheritance are two of the fundamental concepts of the object-oriented programming paradigm and are not present in other programming paradigms. Option A is incorrect because ADTs are supported in many programming paradigms and are not unique to the object-oriented programming paradigm. Option C is incorrect because control structures are present in all programming paradigms and are not unique to the object-oriented programming paradigm. Option D is incorrect because code can be reused in all programming paradigms and this practice is not unique to the object-oriented programming paradigm.

Domain III—Programming Language Topics

Competency 007—The computer science teacher correctly and efficiently uses data types, data structures and functions in the development of code.

21. Which of the following is most efficient for manipulating a list that contains integers and is of predefined size?

  1. A stack
  2. A linked list
  3. An array
  4. A sequential file
Enter to expand or collapse answer.Answer expanded
Option C is correct because an array is most appropriate for traversing and updating a list with the given conditions. Options A and B are incorrect because stacks and linked lists do not have predefined sizes; they are intended to grow and shrink. Option D is incorrect because a sequential file does not provide easy access to individual elements and modifying individual elements is difficult.

22. A programmer is developing a program to read strings from a file and store the strings in a data structure. The strings are unordered in the file but must be accessible in alphabetical order in the data structure. The program must also be able to add and remove strings from the data structure.

Which of the following data structures is the best choice for the program so that the requirements for creating the data structure, adding and removing elements, and accessing individual elements are met as efficiently as possible?

  1. A binary search tree
  2. A linked list
  3. A queue
  4. A stack
Enter to expand or collapse answer.Answer expanded
Option A is correct. Of the data structures given the only one that maintains its elements in sorted order by default is the binary search tree. Option B is incorrect. A linked list can be used to maintain data in sorted order but requires sequential search to find an item to remove or to create the initial ordered list. Options C and D are incorrect because neither data structure facilitates the maintenance of a list in sorted order.

23. Consider the following pseudocode procedure calc, where the first and second parameters are passed by value and the third and fourth parameters are passed by reference. That is, actual parameters passed to formal parameters w and x are passed by value, while those passed to formal parameters y and z are passed by reference.

procedure calc ( pass-by-value int w,
pass-by-value int x,
pass-by-reference int y,
pass-by-reference int z )

w ← w + 1
x ← x * 2
y ← y + 3
z ← z * 4
end procedure

What are the values of a and b at the end of the code fragment below?

int a ← 5
int b ← 6
calc ( a, a, b, b )
  1. a = 5 and b = 24
  2. a = 5 and b = 36
  3. a = 10 and b = 6
  4. a = 12 and b = 6
Enter to expand or collapse answer.Answer expanded
Option B is correct because at the end of the code fragment the values of a and b are 5 and 36, respectively. Since the first two parameters are passed by value, the value of a after the calc call is the same as the value of a before the calc call. Since the last two parameters are passed by reference, the parameters y and z point to variable b. The value of b at the end of the code fragment is the value of z at the end of the procedure. Since the value of b is originally 6, the value of b after y ← y + 3 is 9, and the value of b after z ← z * 4 is 36. Option A is incorrect because it fails to recognize that z has the value 9 when the statement z = z * 4 is executed, using the original value of 6 instead. Option D is incorrect because it confuses the meaning of pass-by-reference and pass-by-value. Option C is incorrect because it results from the errors present in both options A and D.

24. Consider a class Stack defined with methods push ( x ), pop () and peek () that implement a stack data structure. (Note that void push ( int x ) pushes the integer x onto the top of the stack; int pop () removes the integer at the top of the stack and returns that integer; int peek () returns the integer at the top of the stack without removing it from the stack.)

Consider the following pseudocode fragment, where S is a Stack instance that will hold integers.

Stack S ← new Stack ()
S.push ( 4 )
S.push ( 3 )
S.push ( S.peek () + S.peek () )
S.push ( S.pop () * S.pop () )
print ( S.peek () )

What is printed by the last line of code?

  1. 18
  2. 21
  3. 28
  4. 32
Enter to expand or collapse answer.Answer expanded
Option A is correct In the second and third lines of code, the values 4 and 3 are pushed onto the stack. In the fourth line of code, both peek operations return the value 3, so the value 6 is pushed onto the stack. In the fifth line of code, the two pop operations return 6 and 3, removing those values from the stack. Their product, 18, is then pushed onto the stack. The final line of code returns the value at the top of the stack, 18. Options B, C, and D are incorrect because they correspond to incorrect arithmetic operations or misconceptions about stack methods.

25. What is the sum of the binary (base 2) number 1100 base 2. and the hexadecimal (base 16) number 3 base 16?

  1. F base 16.
  2. 15 base 16.
  3. 1003 base 10.
  4. 1103 base 18.
Enter to expand or collapse answer.Answer expanded
Option A is correct. To add the two numbers, they must first be converted to the same base. Since 3 base 16 = 0011 base 2., the sum of the two numbers is 1100 base 2. + 0011 base 2. = 1111 base 2. , which is equal to the decimal number 15 base 10. and also equal to the hexadecimal number F base 16..
Options B and C are incorrect because they are not equal to the decimal number 15 base 10. or to the hexadecimal number F base 16.. Option D is incorrect because the sum is not computed by adding the numbers and by adding the two bases.

26. Consider the following array initialization, where array x has been declared properly but the declaration is not shown.


x ← { 0, { 1, { 2, 3 } }, 4 }

Which of the following diagrams best represents array x ?

  1. A diagram of an array.Two separate columns all with one row. The first column has 1 box labeled x with an arrow pointing out to right side to the first box of the second column and the second column has 5 boxes labeled as followed: 0, 1, 2, 3, 4.
  2. A diagram of an array.Three separate columns all with one row. The first column has 1 box labeled x with an arrow pointing out to right side to the first box of the second column. the second column has 4 boxes. The first box is labeled 0, the second box is labeled 1, the third box has an arrow pointing out to the right side of it to the first box of the third column, and the fourth box is labeled 4. The third column is has two boxes and starts next to the third box in column two. The first box of column 3 is labeled 2 and the second box is labeled 3.
  3. A diagram of an array.Four separate columns all with one row. The first column has 1 box labeled x with an arrow pointing out to right side to the first box of the second column. The second column has three boxes. The first box is labeled 0, the second box is labeled 1, the third box has an arrow pointing out to the right side of it to the first box of the third column. The third column is has three boxes and starts next to the third box in column two. The first box of column three is labeled 2, the second box is labeled 3, and the third box has an arrow pointing out the right side of it to the first box of column four. Column four starts next to the third box of column three and has one box, which is labeled 4.
  4. A diagram of an array.Four separate columns all with one row. The first column has 1 box labeled x with an arrow pointing out to right side to the first box of the second column. The second column has three boxes. The first box is labeled 0, the second box is has an arrow pointing out to the right side of it to the first box of the third column, and the third box is labeled 4. The third column is has two boxes and starts next to the second box in column two. The first box of column three is labeled 1 and the second box has an arrow pointing out the right side of it to the first box of column four. Colum four starts next to the second box of column three and has two boxes. The first box is labeled 2 and the second box is labeled 3.
Enter to expand or collapse answer.Answer expanded
Option D is correct because array x is an array with three elements, where the first element is 0, the second element is the array { 1, { 2, 3 } }, and the third element is 4. The array { 1, { 2, 3 } } is an array with two elements, where the first element is 1 and the second element is the array { 2, 3 } with two elements, 2 and 3. Option A is incorrect because the diagram in option A represents the array { 0, 1, 2, 3, 4 }. Option B is incorrect because the diagram in option B represents the array { 0, 1, { 2, 3 }, 4 }. Option C is incorrect because the diagram in option C represents the array { 0, 1, { 2, 3, { 4 } } }.

27. Consider the following pseudocode segment, where x and y are integer arrays of length 5. The index of each array starts at 0.

int[] x ← { 1, 2, 3, 4, 5 }
int[] y ← { 8, 6, 4, 2, 0 }

What is the value of the expression x[y[3]] + y[x[1]] ?

  1. 7
  2. 8
  3. 11
  4. 12
Enter to expand or collapse answer.Answer expanded
Option A is correct. Since the index of each array starts at 0, the value of y[3] is 2, and the value of x[2] is 3. Similarly, the value of x[1] is 2, and the value of y[2] is 4. The value of the expression x[y[3]] + y[x[1]] is 3 + 4, or 7. Options B, C, and D are incorrect because they correspond to the cases where the index of one or both of the arrays is assumed to start at 1.

28. Assume that a singly linked list of integers is implemented using the following pseudocode class declaration.

class Node
int data
Node next
end Node


Consider the following (incomplete) method g, which takes the head of a singly linked list of integers as argument.

void g ( Node x )
if ( x ≠ null )
/* missing code segment */
end if
end g


Which of the following would correctly complete the method g so that the call g ( x ) prints out the contents of x in reversestart underline reverse end underline. order?

  1. print x.data
    x ← x.next
  2. print x.data
    g ( x.next )
  3. g ( x.next )
    print x.data
  4. g ( x )
    print x.data
Enter to expand or collapse answer.Answer expanded
Option C is correct because the print x.data statement follows the recursive call g ( x.next ), resulting in the contents of x being printed in the reverse order. Option A is incorrect because it prints the contents of x in order. Option B is incorrect because it also prints the contents of x in order. Option D is incorrect because it produces an infinite loop.

Competency 008—The computer science teacher correctly and efficiently uses statements and control structures in the development of code.

29. Consider the following pseudocode functions, where each print statement prints on a separate line of output and then executes a line feed.

void f1 ( int n )
int k ← 0
do {
k ← k + 1
print k
} while ( k < n )
end f1
void f2 ( int n )
int k ← 0
while ( k < n )
k ← k + 1
print k
end while
end f2


Which of the following describes all the values of the input n for which functions f1 and f2 print the same sequence of numbers?

  1. n is greater than 0.
  2. n is greater than or equal to 0.
  3. n is less than 0.
  4. n is less than or equal to 0.
Enter to expand or collapse answer.Answer expanded
Option A is correct because when n is a positive integer the two functions print the same sequence of numbers. Options B, C, and D are incorrect because when n is 0 or negative, the do-while loop in function f1 is executed once and prints one number; the while loop in function f2 is never entered and no numbers are printed.

30. Consider the following pseudocode fragment, where x is an integer variable initialized to a nonnegative integer value.

// x is a nonnegative integer
int sum
x ← x / 2 // integer division; truncates fractions
for ( sum ← 1; x > 0; x ← x / 2 )
sum ← sum + 1
end for


Which of the following will calculate the same value of sum as the fragment above?

  1. int sum ← 0
    x ← x / 2
    while ( x ≥ 0 )
    sum ← sum + 1
    x ← x / 2
    end while
  2. int sum ← 1
    x ← x / 2
    while ( x ≥ 0 )
    sum ← sum + 1
    x ← x / 2
    end while
  3. int sum ← 0
    do {
    sum ← sum + 1
    x ← x / 2
    } while ( x > 0 )
  4. int sum ← 1
    do {
    sum ← sum + 1
    x ← x / 2
    } while ( x > 0 )
Enter to expand or collapse answer.Answer expanded
Option C is correct because the given do-while loop is equivalent to the given for loop. Options A and B are incorrect because the value of x will eventually become 0 and the while loop will loop forever. Option D is incorrect because the variable sum needs to be initialized to 0.

31. Consider the following pseudocode fragment with integer variables.

total ← 0
x ← 1

while ( x < ( 2 * n ) )
if ( ( x % 2 ) == 1 ) // if x is odd
total ← total + x
end if
x ← x + 1
end while

print ( total )


Assume that n has been initialized with a positive integer value. What value is printed when the code fragment is executed?

  1. 0
  2. n
  3. 2n
  4. n squared.
Enter to expand or collapse answer.Answer expanded
Option D is correct. The code segment adds all the positive odd numbers less than 2n and prints the sum. Since 1 + 3 + 5 + ...+(2n − 1) = n squared, the correct answer is D. Options A, B, and C are incorrect because they do not represent the printed value.

32. In a distribution center, x identical items are to be placed into a number of identical boxes. If at most y items fit in a box, which of the following expressions describes the maximum possible number of full boxes? (In the expressions below, / represents decimal division and \ represents integer division.)

  1. x / y
  2. ( x / y ) + ( x % y )
  3. x \ y
  4. ( x \ y ) + ( x % y )
Enter to expand or collapse answer.Answer expanded
Option C is correct because the maximum possible number of full boxes is equal to the result of the integer division of x, the total number of items, by y, the maximum number of items a box will hold. Options A and B are incorrect because they return real numbers that may have fractional components. Option D is incorrect because it adds the remainder of the integer division to the result of the integer division.

33. Consider the following arithmetic expression.

6 / 3 – 7 % 2 + 4 * 5

According to standard operator precedence and standard operator associativity, what is the fourth operation performed when calculating the value of the expression?

  1. Addition
  2. Modulus (remainder)
  3. Multiplication
  4. Subtraction
Enter to expand or collapse answer.Answer expanded
Option D is correct. Division, modulus, and multiplication have the same precedence and have higher precedence than addition and subtraction. Since the associativity for division, modulus, and multiplication is left to right, the first operation performed is division, the second operation is modulus, and the third operation is multiplication. Addition and subtraction have the same precedence and their associativity is also left to right, so the fourth operation is subtraction and the fifth operation is addition. Option A is incorrect because addition is the fifth operation performed. Option B is incorrect because modulus is the second operation performed. Option C is incorrect because multiplication is the third operation performed.

34. Consider an integer array x of length 25, where the index of the array starts at 0. Which of the following pseudocode segments prints the elements of the array in reverse order?

  1. for ( int i ← 0; i < 25; i ← i + 1 )
    print x[i + 1]
    end for
  2. for ( int i ← 0; i < 25; i ← i + 1 )
    print x[i]
    end for
  3. for ( int i ← 25; i > 0; i ← i – 1 )
    print x[i – 1]
    end for
  4. for ( int i ← 25; i > 0; i ← i – 1 )
    print x[i]
    end for
Enter to expand or collapse answer.Answer expanded
Option C is correct because the array elements are printed in decreasing order of their index, and the code segment prints all the array elements from x[24] to x[0]. Option A is incorrect because the array elements are printed in increasing order of their index, the print starts with x[1], and there is an array index out-of-bounds error when x[25] is evaluated. Option B is incorrect because the array elements are printed in increasing order of their index. Option D is incorrect because there is an array index outof-bounds error when x[25] is evaluated and because x[0] is never printed.

Competency 009—The computer science teacher knows how to construct, compare and analyze various algorithms.

35. Which of the following represents the average-case performance of a quicksort algorithm?

  1. O(n)
  2. Oleft paren log base 2 n right paren.
  3. Oleft paren n squared right paren.
  4. Oleft paren n log base 2 n right paren.
Enter to expand or collapse answer.Answer expanded
Option D is correct because on average the quicksort algorithm takes Oleft paren n log base 2 n right paren. comparisons to sort n items. Options A, B, and C are incorrect because they are not equivalent to Oleft paren n log base 2 n right paren..

36. Consider the following pseudocode function, where each print statement prints on a separate line of output and then executes a line feed.

void h ( int n )
if ( n ≥ 4 )
h ( n / 2 )
end if
print n
end h


What is printed when the call h ( 16 ) is executed?

  1. 2
  2. 16
  3. 16
    8
    4
    2
  4. 2
    4
    8
    16
Enter to expand or collapse answer.Answer expanded
Option D is correct because the call h(16) prints four lines of output containing the numbers 2, 4, 8, and 16, respectively. It first calls h(8) and then will print 16 on a new line after the call h(8) completes. The call h(8) calls h(4) and then will print 8 on a new line after the call h(4) completes. The call h(4) calls h(2) and then will print 4 on a new line after the call h(2) completes. The call h(2) prints 2, the first value printed. As each recursive call returns, the values 2, 4, 8, and 16 are printed. Options A, B, and C are incorrect because they correspond to misconceptions about how recursive functions work.

37. A specific sorting algorithm begins by finding the largest element of an array and swapping that element with the last element of the array. Which of the following sorting algorithms fits this description?

  1. Quicksort
  2. Insertion sort
  3. Heapsort
  4. Selection sort
Enter to expand or collapse answer.Answer expanded
Option D is correct because the question describes how selection sort works. Option A is incorrect because quicksort uses a partition operation to divide the input array into two smaller sub-arrays and then sorts the sub-arrays recursively. Option B is incorrect because, in each iteration, insertion sort removes one element from the input, finds its correct location in the part already sorted and inserts it there. Option C is incorrect because heapsort uses a heap data structure.

38. Consider the following pseudocode binary search function, which returns the largest array index from one given index to another, k, such that a[k] ≤ x.

// precondition 1: integer array a is sorted in
// ascending order
// precondition 2: 0 ≤ first < last < length of array a
// precondition 3: a[first] ≤ x < a[last]
int f ( int array a, int x, int first, int last )
while ( first + 1 ≠ last )
int mid ← ( first + last ) / 2 // integer
// division
if ( x < a[mid] )
last ← mid
else
first ← mid
end if
end while
return first
end f


Consider the following incomplete, equivalent, recursive implementation.

int g ( int array a, int x, int first, int last )
if ( first + 1 is equal to last )
return first
end if
int mid ← ( first + last ) / 2
// missing code block
end g


Which of the following could replace the missing code block so that the recursive function will work as intended?

  1. if ( x ≥ a[mid] )
    return g ( a, x, first, mid )
    end if
    return g ( a, x, mid, last )
  2. if ( x ≥ a[mid] )
    return g ( a, x, mid, first )
    end if
    return g ( a, x, last, mid )
  3. if ( x ≥ a[mid] )
    return g ( a, x, mid, last )
    end if
    return g ( a, x, first, mid )
  4. if ( x ≥ a[mid] )
    return g ( a, x, last, mid )
    end if
    return g ( a, x, mid, first )
Enter to expand or collapse answer.Answer expanded
Option C is correct because, if x ≥ a[mid], the value x could only be in a[mid..last]; otherwise, the value x could only be in a[first..mid]. Options A, B, and D are incorrect because they correspond to misconceptions about how binary search works.

39. Consider the following pseudocode function.

// precondition: n and k are nonnegative integers
int f ( int n, int k )
if ( k * n is equal to 0 )
return 1
else
return f ( n − 1, k − 1 ) + f ( n − 1, k )
end if
end f


What value is returned by the call f ( 4, 2 ) ?

  1. 4
  2. 5
  3. 7
  4. 11
Enter to expand or collapse answer.Answer expanded
Option D is correct because the value returned by the call f(4, 2) is 11.
f(4, 2)= f(3,1) + f(3,2)
= f(2,0) + f(2,1) +
f(2,1) + f(2,2)
= 1 + 2 * f(2,1) +
f(2,2)
= 1 + 2 * (f(1,0) +
f(1,1)) + (f(1,1) +
f(1,2))
= 3 + 3 * f(1,1) +
f(1,2)
= 3 + 3 * (f(0,0) +
f(0,1)) + (f(0,1) +
f(0,2))
= 11

Options A, B, and C are incorrect because they correspond to misconceptions about how recursive functions work.

40. Consider the following pseudocode segment with integer variables that implements a selection sort. Assume that A is an integer array of length n with indexing that starts at 0.

for ( int j ← 0; j < n − 1; j ← j + 1 )
int x ← j
for ( int i ← j + 1; i < n; i ← i + 1 )
// missing code block
end for
if ( x ≠ j )
swap ( A[x], A[j] ) // swap the two array entries
end if
end for


Which of the following could replace the missing code block so that the code segment will work as intended?

  1. if ( A[x] > A[i] )
    x ← i
    end if
  2. if ( A[x] > A[i] )
    A[x] ← A[i]
    end if
  3. if ( x > i )
    x ← i
    end if
  4. if ( x > i )
    A[x] ← A[i]
    end if
Enter to expand or collapse answer.Answer expanded
Option A is correct. In each iteration of the outer for loop, the inner for loop identifies the smallest value in subarray A[j+1..n−1] and the if statement swaps it with A[j]. Option B is incorrect because it overwrites A[x] rather than updates variable x. Option C is incorrect because it compares the indexes of array elements rather than the array values. Option D is incorrect because it results from the errors present in both options B and C.

41. Consider the following pseudocode, which implements an insertion sort.

// precondition 1: A is an array of integers.
// precondition 2: The length of array A is n.
// precondition 3: The index of array A starts at 0.
int[] insertionSort ( pass-by-reference int[] A, int n )
for ( int j ← 1; j ≤ n − 1; j ← j + 1 )
int temp ← A[j]
int k ← j − 1
while ( ( k ≥ 0 ) and ( A[k] > temp ) )
A[k + 1] ← A[k]
k ← k − 1
end while
A[k + 1] ← temp
end for
return A // returns the sorted array
end insertionSort

Which of the following best describes the average running time of insertionSort?

  1. O(1)
  2. Oleft paren log n right paren.
  3. Oleft paren n log n right paren.
  4. Oleft paren n squared right paren.
Enter to expand or collapse answer.Answer expanded
Option D is correct because on average the insertion sort takes O left paren n squared right paren. to sort n items. Options A, B, and C are incorrect because they are not equivalent to O left paren n squared right paren..

42. Consider the following three pseudocode procedures.

Procedure 1
procedure p1 ( int s, int e )
int k
for ( k ← s; k < e; k ← k + 2 )
print ( k )
end for
end procedure p1


Procedure 2
procedure p2 ( int s, int e )
do {
s ← s + 2
print ( s )
} while ( s < e )
end procedure p2


Procedure 3
procedure p3 ( int s, int e )
print ( s )
if ( s < e )
p3 ( s + 2 )
end if
end procedure p3

Assume that s and e have been initialized with integer values. Which of the following statements about the output of the procedures is true?

  1. For each pair ( s, e ), the three procedures will produce the same output.
  2. For each pair ( s, e ), procedure 1 and procedure 2 will produce the same output, but for some pairs ( s, e ), procedure 1 and procedure 3 will produce different output.
  3. For each pair ( s, e ), procedure 2 and procedure 3 will produce the same output, but for some pairs ( s, e ), procedure 1 and procedure 2 will produce different output.
  4. For some pairs ( s, e ), the three procedures will produce three different outputs.
Enter to expand or collapse answer.Answer expanded
Option D is correct because the three procedures will produce three different outputs when s is 1 and e is 2. For this pair, procedure 1 will print 1, procedure 2 will print 3, and procedure 3 will print 1 and 3. Options A, B, and C are incorrect because the three procedures will produce three different outputs for the pair ( 1, 2 ).

Domain IV—Specialized Topics

Competency 010—The computer science teacher knows discrete mathematics topics relevant to computer science.

43. Which of the following truth tables correctly represents the Boolean expression ( pq) if and only if (pq) ?

  1. p q (p ∧ q) if and only if (p ∨ q)
    1 1 0
    1 0 1
    0 1 1
    0 0 0
  2. p q (p ∧ q) if and only if (p ∨ q)
    1 1 1
    1 0 0
    0 1 0
    0 0 1
  3. p q (p ∧ q) if and only if (p ∨ q)
    1 1 1
    1 0 1
    0 1 1
    0 0 0
  4. p q (p ∧ q) if and only if (p ∨ q)
    1 1 1
    1 0 0
    0 1 0
    0 0 0
Enter to expand or collapse answer.Answer expanded
Option B is correct. The table below shows the complete truth table.

p q pq pq (p ∧ q) if and only if (p ∨ q)
1 1 1 1 1
1 0 0 1 0
0 1 0 1 0
0 0 0 0 1


Option A is incorrect because it’s the negation of the correct values. Option C is incorrect because it results from using "or" instead of "if and only if." Option D is incorrect because it results from using "and" instead of "if and only if."

44. Consider propositions p and q, defined as follows.

p: I go for a run.
q: The sky is dark.

Which of the following is equivalent to the compound proposition "I don’t go for a run when the sky is dark"?

  1. p which becomes q
  2. not negation p which becomes q
  3. q which becomes not negation p
  4. not negation q which becomes p
Enter to expand or collapse answer.Answer expanded
Option C is correct because the compound statement is equivalent to "If the sky is dark, then I don’t go for a run," which is represented by q which becomes p. Option A is incorrect because p which becomes q is equivalent to "If I go for a run, then the sky is dark." Option B is incorrect because not negation p which becomes q is equivalent to "If I don’t go for a run, then the sky is dark." Option D is incorrect because not negation q which becomes p is equivalent to "If the sky is not dark, then I go for a run."

45. If p and q are propositions, which of the following is the contrapositive of the implication p which becomes q. ?

  1. qpq which becomes p.
  2. ¬q ⇒ ¬pnot negation q which becomes not negation p.
  3. qpq or p.
  4. qpq and p.
Enter to expand or collapse answer.Answer expanded
Option B is correct because the contrapositive is obtained by switching the hypothesis and the conclusion and negating both of them. Option A is incorrect because it represents the converse. Option C is incorrect because it represents the disjunction of hypothesis and conclusion. Option D is incorrect because it represents the conjunction of hypothesis and conclusion.

Competency 011—The computer science teacher knows digital forensics topics.

46. Which of the following describes how data remanence is relevant to digital forensics?

  1. It allows the recovery of digital data even though file deletion has occurred.
  2. It determines whether data are preserved or lost when a computer is turned off.
  3. It ensures that collected evidence is admissible as evidence in a court of law.
  4. It establishes who has authorization to monitor and collect network traffic data.
Enter to expand or collapse answer.Answer expanded
Option A is correct because data remanence refers to the data that remain on a storage device after data are deleted. Options B, C, and D are incorrect because they do not describe how data remanence is relevant to digital forensics.

47. Which of the following best describes a computer worm?

  1. Malware that does not replicate itself but spreads through social engineering
  2. Malware that replicates by attaching itself to a word processing document
  3. Malware that replicates by attaching itself to an executable program
  4. Malware that replicates itself as stand-alone software
Enter to expand or collapse answer.Answer expanded
Option D is correct because a computer worm is a stand-alone malware software application that replicates itself in order to spread to other computers. Option A is incorrect because a computer worm replicates itself. Options B and C are incorrect because a computer worm is a stand-alone software application and does not necessarily need to attach itself to other programs.

Competency 012—The computer science teacher knows robotics topics.

48. A robot’s programming system uses the command move[motor] ← value, where motor identifies a particular motor and value is an integer amount of speed, with a positive value indicating forward movement, a negative value indicating backward movement, and 0 indicating a stop. For example, the command move[left] ← 99 will cause the left motor to move forward at a speed of 99.

A student is programming a two-wheel-drive robot to travel through a maze and is having trouble with the corners. The robot swings wide and goes out of bounds. A segment of the code being used for a right turn is similar to the code below, where left is the left wheel motor (from the robot’s perspective), right is the right wheel motor and slow is a positive integer representing an appropriate turning speed.

move[left] ← slow
move[right] ← 0

The teacher suggests that the student consider modifying the robot’s turning code to execute a point (in-place) turn rather than a swing turn. Which of the following code segments could the student use to implement the teacher’s suggestion?

  1. move[left] ← slow
    move[right] ← −slow
  2. move[left] ← 0
    move[right] ← slow
  3. move[left] ← slow
    move[right] ← 2 * slow
  4. move[left] ← −slow
    move[right] ← slow
Enter to expand or collapse answer.Answer expanded
Option A is correct because the algorithm for performing an in-place turn is to set the motors to turn at the same speed in opposite directions. To generate a right turn, the left wheel should go forward, and the right wheel should go backward. Options B and C are incorrect because each executes a swing turn to the left. Option D is incorrect because it executes an in-place left turn.

Competency 013—The computer science teacher knows game and mobile application development topics.

49. Consider a game in a two-dimensional space and the goal of determining whether a collision has occurred between two circular objects (that is, to detect whether two circular objects overlap or touch). The centers of the circular objects are stored in variables (x1, y1) and (x2, y2) and the radii are stored in variables r1 and r2. The distance between the two centers is given by the formula squared root of the two variables x and y.the quanity of the square root of left paren X 1 minus X 2 right paren squared plus left paren Y 1 minus Y 2 right paren squared..

The following pseudocode segment is intended to implement a collision-detection algorithm.

collision ← false
// dist is the distance between centers.
dist ← sqrt ( ( x1 – x2 )^2 + ( y1 – y2 )^2 )
if <missing condition> )
collision ← true
end if

Which of the following could replace left bracket missing condition right bracket so that the collision detection algorithm works as intended?

  1. dist is greater than or equal to R 1 minus R2.
  2. dist is less than or equal to R 1 plus R 2.
  3. left paren dist is less than or equal to R 1 right paren. OR left paren dist is less than or equal to R 2 right paren.
  4. left paren dist is less than or equal to R 1 right paren. AND left paren dist is less than or equal to R 2 right paren.
Enter to expand or collapse answer.Answer expanded
Option B is correct because a collision occurs whenever the distance between the two centers is less than or equal to the sum of the two radii. Options A, C, and D are incorrect because they do not describe the complete conditions when a collision occurs.

50. When handling images in a video game, which of the following is a way of conserving memory?

  1. Using a floating-point data type for both integers and floating-point values
  2. Using a collection of tiles to create the game screen
  3. Using more than 24 bits for each RGB value
  4. Using higher resolution for all images
Enter to expand or collapse answer.Answer expanded
Option B is correct because when using a collection of tiles, the portions of the scene not in use will not consume valuable memory. Options A, C, and D are incorrect because each of the actions will increase memory use.

Return to Navigation