Preparation Manual
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?
- The document can be viewed in any Web browser.
- A formatted document can be transferred between different applications.
- The document can take up less space in memory.
- 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?
- Using the school district’s database to determine gender distribution in local schools
- Using the Internet history on a classroom computer to audit student Internet use
- Using students’ personal data to create a mailing list for a local charity
- 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?
- Browser name
- Email address
- File name
- Host name
- MAC address
- 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
- increasing bandwidth.
- upgrading cameras.
- increasing video resolution.
- 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?
- BMP
- TIFF
- PNG
- 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?
- 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.
- 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.
- 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.
- 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
- participate in a threaded discussion group.
- send email messages with attached document files.
- update pages on the class’s Web site.
- 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?
- The teacher asks the students the following day if they fully understand the material.
- The teacher asks the students to take notes on the material as they are reading it.
- The teacher assigns problems or questions on key concepts for the students to complete after they have finished reading the material.
- 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.
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?
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 whileint 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 whileint 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 whileint 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 whenk < len
. Within thewhile
loop, the condition on theif
statement is the opposite of the corresponding condition in the flowchart, sopart
is updated andswap
is called if the condition on theif
statement is true. The variablek
is incremented and the condition in thewhile
loop is tested again. Option B is incorrect because the increment ofk
needs to occur after theif
statement. Option C is incorrect because the increment ofpart
and the call to theswap
method need to occur when the comparisonarr[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?
- To test and maintain the efficiency of the overall program
- To present the steps needed to solve the programming problem
- To ensure that all methods are appropriately linked
- 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.
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?
- A class named
STU
contains two private fields and three public methods. - A class named
STU
contains two public fields and three private methods. - A class named
STU
contains two private methods and three public fields. - 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 theSTU
class contains two fields—abc
anddef
. The two fields are private as shown by the minus sign in front of the field names. Similarly, the bottom box indicates that theSTU class contains three methods—
ghi()
,jkl()
, andmno()
. 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?
- 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.
- 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.
- 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.
- 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 indexk is initialized to
0
. If the conditionk < n
is false, the value of the variable max is returned and the algorithm stops. If the conditionk < n
is true, the array elementx[k]
is compared to max. Ifx[k]
is larger than max, then the value ofx[k]
is set as the new value of max, the array indexk
is incremented by1
, and the flow returns back to the conditionk < n
; otherwise, the value of max is not changed, the array indexk
is incremented by1
, and the flow returns back to the conditionk < n
. Option A is incorrect because the increment of k should execute regardless of whether the conditionx[k] > max
is satisfied or not. Option D is incorrect because the Yes and No branches for thex[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?
- Chaos
- Incremental
- Spiral
- 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
- methods or functions by way of the interface.
- implementation details of the methods or functions.
- methods or functions by way of the source code.
- 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?
- y double equal sign, or is equal to x minus 1.
- y double equal sign, or is equal to x.
- y double equal sign, or is equal to x plus 1.
- 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
andy_pre
are the values ofx
andy
before the code segment and ifx_post
andy_post
are the values ofx
andy
after the code segment, then we have the following relations.
x_post = x_pre + 1
y_post = x_pre + y_pre + 1
Whenx_post
andy_post
replacex and
y in the postcondition
y is equal to 2 times x, we get
x_pre + y_pre + 1 = 2 * (x_pre + 1)
, or equivalentlyy_pre = x_pre + 1
. Option A is incorrect because the given precondition is equivalent to the postconditiony == 2 * x − 2
. Option B is incorrect because the given precondition is equivalent to the postconditiony 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?
b – c ≠ 0
a / ( b – c ) ≥ 0
( b – c ≠ 0 ) and ( a / ( b – c ) ≥ 0 )
( 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
equals0
. 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 becauseb − c ≠ 0
does not guarantee thata / ( b − c )
is nonnegative, possibly leading to the evaluation of a square root of a negative number. Option B is incorrect because the evaluation ofa / ( b − c )
would generate a run-time error when the values ofb
andc
are equal. Option D is incorrect because the logical operator or is short circuited as soon asb − 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?
- Code security
- Flow control
- Exception handling
- 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?
- C
- Java
- PHP
- 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,000 bytes
- 4,000 bytes
- 16,000 bytes
- 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?
- Support for abstract data types (ADTs)
- Support for the concepts of encapsulation and inheritance
- Support for control structures
- 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?
- A stack
- A linked list
- An array
- 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?
- A binary search tree
- A linked list
- A queue
- 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 )
a = 5
andb = 24
a = 5
andb = 36
a = 10
andb = 6
a = 12
andb = 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
andb
are5
and36
, respectively. Since the first two parameters are passed by value, the value ofa
after thecalc
call is the same as the value ofa
before thecalc
call. Since the last two parameters are passed by reference, the parametersy
andz
point to variableb
. The value ofb
at the end of the code fragment is the value ofz
at the end of the procedure. Since the value ofb
is originally 6, the value ofb
aftery ← y + 3 is 9
, and the value ofb
afterz ← z * 4
is36
. Option A is incorrect because it fails to recognize that z has the value9
when the statementz = z * 4
is executed, using the original value of6
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?
18
21
28
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?
- F base 16.
- 15 base 16.
- 1003 base 10.
- 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
?
- 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.
- 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.
- 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.
- 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 is0
, the second element is the array{ 1, { 2, 3 } }
, and the third element is4
. The array{ 1, { 2, 3 } }
is an array with two elements, where the first element is1
and the second element is the array{ 2, 3 }
with two elements,2
and3
. 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]]
?
7
8
11
12
- Enter to expand or collapse answer.Answer expanded
- Option A is correct. Since the
index of each array starts at
0
, the value ofy[3]
is2
, and the value ofx[2]
is3
. Similarly, the value ofx[1]
is2
, and the value ofy[2]
is4
. The value of the expressionx[y[3]] + y[x[1]]
is3 + 4
, or7
. 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 at1
.
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?
print x.data
x ← x.nextprint x.data
g ( x.next )g ( x.next )
print x.datag ( 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 ofx
being printed in the reverse order. Option A is incorrect because it prints the contents ofx
in order. Option B is incorrect because it also prints the contents ofx
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?
- n is greater than 0.
- n is greater than or equal to 0.
- n is less than 0. 0>
- 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 is0
or negative, thedo-while
loop in functionf1
is executed once and prints one number; thewhile
loop in functionf2
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?
int sum ← 0
x ← x / 2
while ( x ≥ 0 )
sum ← sum + 1
x ← x / 2
end whileint sum ← 1
x ← x / 2
while ( x ≥ 0 )
sum ← sum + 1
x ← x / 2
end whileint sum ← 0
do {
sum ← sum + 1
x ← x / 2
} while ( x > 0 )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 givenfor
loop. Options A and B are incorrect because the value ofx
will eventually become0
and the while loop will loop forever. Option D is incorrect because the variablesum
needs to be initialized to0
.
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?
0
n
2n
- 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.)
x / y
( x / y ) + ( x % y )
x \ y
( 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, byy
, 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?
- Addition
- Modulus (remainder)
- Multiplication
- 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?
for ( int i ← 0; i < 25; i ← i + 1 )
print x[i + 1]
end forfor ( int i ← 0; i < 25; i ← i + 1 )
print x[i]
end forfor ( int i ← 25; i > 0; i ← i – 1 )
print x[i – 1]
end forfor ( 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]
tox[0]
. Option A is incorrect because the array elements are printed in increasing order of their index, the print starts withx[1]
, and there is an array index out-of-bounds error whenx[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 whenx[25]
is evaluated and becausex[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?
- O(n)
- Oleft paren log base 2 n right paren.
- Oleft paren n squared right paren.
- 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?
2
16
16
8
4
22
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 numbers2, 4, 8,
and16, respectively. It first calls
h(8)
and then will print16
on a new line after the callh(8)
completes. The callh(8)
callsh(4)
and then will print 8 on a new line after the callh(4)
completes. The callh(4)
callsh(2)
and then will print4
on a new line after the callh(2)
completes. The callh(2)
prints2
, the first value printed. As each recursive call returns, the values2, 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?
- Quicksort
- Insertion sort
- Heapsort
- 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?
if ( x ≥ a[mid] )
return g ( a, x, first, mid )
end if
return g ( a, x, mid, last )if ( x ≥ a[mid] )
return g ( a, x, mid, first )
end if
return g ( a, x, last, mid )if ( x ≥ a[mid] )
return g ( a, x, mid, last )
end if
return g ( a, x, first, mid )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 valuex
could only be ina[mid..last];
otherwise, the valuex
could only be ina[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 )
?
4
5
7
11
- Enter to expand or collapse answer.Answer expanded
- Option D is correct because the
value returned by the call
f(4, 2)
is11
.
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?
if ( A[x] > A[i] )
x ← i
end ifif ( A[x] > A[i] )
A[x] ← A[i]
end ifif ( x > i )
x ← i
end ifif ( 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 innerfor
loop identifies the smallest value in subarrayA[j+1..n−1]
and theif
statement swaps it withA[j]
. Option B is incorrect because it overwritesA[x]
rather than updates variablex
. 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
?
- O(1)
- Oleft paren log n right paren.
- Oleft paren n log n right paren.
- 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 p1 ( int s, int e )
int k
for ( k ← s; k < e; k ← k + 2 )
print ( k )
end for
end procedure p1
procedure p2 ( int s, int e )
do {
s ← s + 2
print ( s )
} while ( s < e )
end procedure p2
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?
- For each pair
( s, e )
, the three procedures will produce the same output. - 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. - 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. - 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
is1
ande
is2
. For this pair, procedure 1 will print1
, procedure 2 will print3
, and procedure 3 will print1
and3
. 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 ( p ∧ q) if and only if (p ∨ q) ?
-
p q (p ∧ q) if and only if (p ∨ q) 1 1 0 1 0 1 0 1 1 0 0 0 -
p q (p ∧ q) if and only if (p ∨ q) 1 1 1 1 0 0 0 1 0 0 0 1 -
p q (p ∧ q) if and only if (p ∨ q) 1 1 1 1 0 1 0 1 1 0 0 0 -
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 p ∧ q p ∨ q (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"?
- p which becomes q
- not negation p which becomes q
- q which becomes not negation p
- 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. ?
- q ⇒ pq which becomes p.
- ¬q ⇒ ¬pnot negation q which becomes not negation p.
- q ∨ pq or p.
- q ∧ pq 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?
- It allows the recovery of digital data even though file deletion has occurred.
- It determines whether data are preserved or lost when a computer is turned off.
- It ensures that collected evidence is admissible as evidence in a court of law.
- 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?
- Malware that does not replicate itself but spreads through social engineering
- Malware that replicates by attaching itself to a word processing document
- Malware that replicates by attaching itself to an executable program
- 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?
move[left] ← slow
move[right] ← −slowmove[left] ← 0
move[right] ← slowmove[left] ← slow
move[right] ← 2 * slowmove[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 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?
- dist is greater than or equal to R 1 minus R2.
- dist is less than or equal to R 1 plus R 2.
- 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.
- 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?
- Using a floating-point data type for both integers and floating-point values
- Using a collection of tiles to create the game screen
- Using more than 24 bits for each RGB value
- 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.