AP Computer Science Principles

Ace your homework & exams now with Quizwiz!

A student wants to create an algorithm that can determine, given any program and program input, whether or not the program will go into an infinite loop for that input. The problem the student is attempting to solve is considered an undecidable problem. Which of the following is true?

It is possible to create an algorithm that will solve the problem for all programs and inputs, but the algorithm can only be implemented in a low-level programming language.

A population researcher is interested in predicting the number of births that will occur in a particular community. She created a computer model that uses data from the past ten years, including number of residents and the number of babies born. The model predicted that there would be 200 births last year, but the actual number of births last year was only 120. Which of the following strategies is LEAST likely to provide a more accurate prediction?

Removing as many details from the model as possible so that calculations can be performed quickly

Which of the following allows users to refer to Web sites using names, such as example.com, rather than numbers, such as 93.184.216.34 ?

The domain name system (DNS)

A social media site allows users to send messages to each other. A group of researchers gathered user data for the first 10 years of the site's existence. Some of the data are summarized in the table below, along with some of the company milestones. Which of the following hypotheses is most consistent with the data in the table?

The mobile app release led to users tending to write shorter messages.

In public key cryptography, the sender uses the recipient's public key to encrypt a message. Which of the following is needed to decrypt the message?

The sender's private key

A user reads reviews of a popular artist's new album and then downloads the album from theWeb site of a licensed online music seller. Which of the following is LEAST likely to be a consequence of this action?

The user will be in violation of the Digital Millennium Copyright Act (DMCA).

A computer program uses 4 bits to represent nonnegative integers. Which of the following statements describe a possible result when the program uses this number representation? I. The operation 4 + 8 will result in an overflow error. II. The operation 7 + 10 will result in an overflow error. III. The operation 12 + 3 will result in an overflow error.

II only

Participants in a survey were asked how many hours per day they spend reading, how many hours per day they spend using a smartphone, and whether or not they would be interested in a smartphone application that lets users share book reviews. The data from the survey are represented in the graph below. Each × represents a survey participant who said he or she was interested in the application, and each O represents a participant who said he or she was not interested. Which of the following hypotheses is most consistent with the data in the graph?

Participants who read more were generally more likely to say they are interested in the application

A computer program performs the operation 2 ÷ 3 and represents the result as the value 0.6666667. Which of the following best explains this result?

The precision of the result is limited due to the constraints of using a oating-point representation

Consider the following program. Which of the following describes the result of executing the program?

The program displays the sum of the odd integers from 1 to 19.

Which of the following statements accurately describe the hierarchy of theWeb pages example.org and about.example.org ? Select two answers.

TheWeb page about.example.org is a subdomain of example.org. TheWeb page example.org is a domain under the top-level domain .org.

Which of the following best describes the purpose of machine learning programs?

To analyze large data sets, recognize patterns, and make predictions based on data

A media librarian at a movie studio is planning to save digital video files for archival purposes. The movie studio would like to be able to access full-quality videos if they are needed for future projects. Which of the following actions is LEAST likely to support the studio's goal?

Using lossy compression software to reduce the size requirements of the data being stored

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

b

Byte pair encoding is a data encoding technique. The encoding algorithm looks for pairs of characters that appear in the string more than once and replaces each instance of that pair with a corresponding character that does not appear in the string. The algorithm saves a list containing the mapping of character pairs to their corresponding replacement characters. For example, the string "THIS_IS_THE_BEST_WISH" can be encoded as "%#_#_%E_BEST_W#H" by replacing all instances of "TH" with "%" and replacing all instances of "IS" with "#". For which of the following strings is it NOT possible to use byte pair encoding to shorten the string's length?

"LEVEL_UP"

The code segment below is intended to display all multiples of 5 between the values start and end, inclusive. For example, if start has the value 35 and end has the value 50, the code segment should display the values 35, 40, 45, and 50. Assume that start and end are multiples of 5 and that start is less than end. Line 1: i ← start Line 2: REPEAT <MISSING EXPRESSION> TIMES Line 3: { Line 4: DISPLAY (i) Line 5: i ← i + 5 Line 6: } Which of the following could replace <MISSING EXPRESSION> in line 2 so that the code segment works as intended?

((end - start) / 5) + 1 b end - start + 6

Which of the following statements describe how cloud computing has affected Internet communication? Select two answers.

Cloud computing has reduced concerns about intellectual property rights. Cloud computing has introduced new data-security concerns.

The two code segments below are each intended to display the average of the numbers in the list numList. Assume that numList contains more than one value. Which of the following best describes the two code segments?

Code segment II displays the correct average, but code segment I does not.

Which of the following are true statements about how the Internet enables crowdsourcing? I. The Internet can provide crowdsourcing participants access to useful tools, information, and professional knowledge. II. The speed and reach of the Internet can lower geographic barriers, allowing individuals from different locations to contribute to projects. III. Using the Internet to distribute solutions across many users allows all computational problems to be solved in reasonable time, even for very large input sizes.

I and II only

Grades in a computer science course are based on total points earned on a midterm exam and a final exam. The teacher provides a way for students to improve their course grades if they receive high scores on the final exam: if a student's final exam score is greater than the student's midterm exam score, the final exam score replaces the midterm exam score in the calculation of total points. The table below shows two students' scores on the midterm and final exams and the calculated total points each student earns. Khalil does better on the midterm exam than on the nal exam, so his original midterm and nal exam scores are added to compute his total points. Josena does better on the nal exam than on the midterm exam, so her nal exam score replaces her midterm exam score in the total points calculation. The teacher has data representing the scores of thousands of students. For each student, the data contain the student name, the midterm exam score, the final exam score, and the result of the total points calculation. Which of the following could be determined from the data?

I, II, and III

The grid below contains a robot represented as a triangle, initially facing up. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL (GoalReached ()) { <MISSING CODE> } Which of the following replacements for <MISSING CODE> can be used to move the robot to the gray square? a IF (CAN_MOVE (forward)) { MOVE_FORWARD () } ROTATE_RIGHT () b IF (CAN_MOVE (forward)) { MOVE_FORWARD () ROTATE_RIGHT () } c IF (CAN_MOVE (right)) { ROTATE_RIGHT () MOVE_FORWARD () } d IF (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD ()

IF (CAN_MOVE (right)) { ROTATE_RIGHT () } MOVE_FORWARD ()

A programmer is developing a word game. The programmer wants to create an algorithm that will take a list of words and return a list containing the first letter of all words that are palindromes (words that read the same backward or forward). The returned list should be in alphabetical order. For example, if the list contains the words ["banana", "kayak", "mom", "apple", "level"], the returned list would contain ["k", "l", "m"] (because "kayak", "level", and "mom" are palindromes). The programmer knows that the following steps are necessary for the algorithm but is not sure in which order they should be executed. Executing which of the following sequences of steps will enable the algorithm to work as intended? I. First shorten, then keep palindromes, then sort II. First keep palindromes, then shorten, then sort III. First sort, then keep palindromes, then shorten

II and III

The program below is intended to count the number of prime numbers in a list called numbers and display the result. The program uses the procedure isPrime (n), which returns true if n is a prime number and false otherwise. The program does not work as intended. Line 1: count ← 0 Line 2: FOR EACH value IN numbers Line 3: { Line 4: count ← 0 Line 5: IF (isPrime (value)) Line 6: { Line 7: count ← count + 1 Line 8: } Line 9: count ← count + 1 Line 10: } Line 11: DISPLAY (count) Which two lines of code should be removed so that the program will work as intended? Select two answers.

Line 9 and 4

An application program interface (API) provides a procedure Max, which returns the greater of its two integer arguments. A programmer would like to find the greatest of three integer values a, b, and c. Which of the following expressions will produce the desired result in every case?

Max (Max (a, b), c)

The latency of a network connection is most appropriately measured with which of the following units?

Milliseconds

In a certain science experiment, 75 percent of trials are expected to be successful and 25 percent of trials are expected to be unsuccessful. The program below is intended to simulate the results of repeated trials of the experiment. successful ← 0 unsuccessful ← 0 REPEAT 1000 TIMES 15/30 { IF (<MISSING CODE>) { successful ← successful + 1 } ELSE { unsuccessful ← unsuccessful + 1 } } DISPLAY (successful) DISPLAY ("trials were successful,") DISPLAY (unsuccessful) DISPLAY ("trials were unsuccessful.") Which of the following can be used to replace <MISSING CODE> so that the simulation works as intended?

RANDOM (1, 100) ≤ 75

Which of the following are ways in which a programmer can use abstraction to manage the complexity of a program? Select two answers

Replacing the string variables name1, name2, name3, and name4 with a list of strings called names Replacing each instance of repeated code with a call to a procedure

A researcher wrote a program to simulate the number of mice in an environment that contains predators. The program uses the following procedures. Code for the simulation is shown below. days ← 0 numMice ← InitialMousePopulation () numPredators ← InitialPredatorPopulation () REPEAT UNTIL (days = 365) { numMice ← NextDayPopulation (numMice, numPredators) days ← days + 1 } DISPLAY ("There are") DISPLAY (numMice) DISPLAY ("mice after one year.") Based on the code, which of the following assumptions is made in the simulation?

The number of predators does not change from day to day.

A student wrote the procedure below, which is intended to ask whether a user wants to keep playing a game. The procedure does not work as intended. PROCEDURE KeepPlaying () { DISPLAY ("Do you want to continue playing (y/n)?") response ← INPUT () IF ((response = "y") AND (response = "yes")) { RETURN (true) } ELSE { RETURN (false) } } Which of the following best describes the result of running the procedure?

The procedure returns false no matter what the input value is.

Two different schools maintain data sets about their currently enrolled students. No individual student is enrolled at both schools. Each line of data contains information, separated by commas, about one student. East High School stores the data in the following format.

The schools can create a single list of student names, sorted by last name. The schools can determine the average number of days students are absent.

A program is created to perform arithmetic operations on positive and negative integers. The program contains the following incorrect procedure, which is intended to return the product of the integers x and y. PROCEDURE Multiply (x, y) { count ← 0 result ← 0 REPEAT UNTIL (count = y) { result ← result + x 22/30 count ← count + 1 } RETURN (result) } A programmer suspects that an error in the program is caused by this procedure. Under which of the following conditions will the procedure NOT return the correct product? Select two answers.

When the values of x and y are both negative. When the value of x is positive and the value of y is negative

Which of the following describes how a distributed denial-of-service (DDoS) attack is most likely to compromise an online store'sWeb site?

By preventing customers from placing orders

Byte pair encoding is a data encoding technique. The encoding algorithm looks for pairs of characters that appear in the string more than once and replaces each instance of that pair with a corresponding character that does not appear in the string. The algorithm saves a list containing the mapping of character pairs to their corresponding replacement characters. For example, the string "THIS_IS_THE_BEST_WISH" can be encoded as "%#_#_%E_BEST_W#H" by replacing all instances of "TH" with "%" and replacing all instances of "IS" with "#". Which of the following statements about byte pair encoding is true?

Byte pair encoding is an example of a lossless transformation because an encoded string can be restored to its original version

A bank customer receives an e-mail from a sender claiming to be a bank employee. The e-mail asks the customer to provide personal information and to call a phone number if he or she has any questions. The customer suspects the e-mail might be a phishing attempt. Which of the following responses is most likely to be a privacy risk for the bank customer?

Calling the phone number given in the e-mail and providing the personal information over the phone

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

NOT (P AND Q)

Which of the following explains a benet of using open standards and protocols for Internet communication?

Open standards and protocols allow dierent manufacturers and developers to build hardware and software that can communicate with hardware and software on the rest of the network.

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. • Procedure Square (n) returns the value n 2 . • Procedure Cube (n) returns the value n 3 Which of the following procedures is a generalization of the procedures described above?

Procedure Power (n, m), which returns the value nm

Consider the two programs below. Which of the following best compares the values displayed by programs A and B?

Program A and program B display the same number of values, but the values dier.

The procedure DrawCircle (x, y, r) can be used to draw a circle on a coordinate grid. The circle is centered at the coordinate (x, y) and has a radius of r units. The procedure will be used to draw the following figure on a coordinate grid. Which of the following code segments can be used to draw the figure?

xPos ← 3 yPos ← 6 REPEAT 3 TIMES { DrawCircle (xPos, yPos, 2) xPos ← xPos + 2 yPos ← yPos - 2 }

Internet protocol version 4 (IPv4) represents each IP address as a 32-bit binary number. Internet protocol version 6 (IPv6) represents each IP address as a 128-bit binary number. Which of the following best describes the result of using 128-bit addresses instead of 32-bit addresses?

296 times as many addresses are available.

Consider the following program, which uses the variables start, end, and current. start ← 1 start ← current DISPLAY (start) DISPLAY (current) end ← 20 current ← 3 current ← current + 1 What is displayed as a result of executing the program?

3 4

A social media site allows users to send messages to each other. A group of researchers gathered user data for the first 10 years of the site's existence. Some of the data are summarized in the table below, along with some of the company milestones. The researchers noticed that the total number of registered users appears to be increasing at about a constant rate. If this pattern continues, which of the following best approximates the total number of registered users, in millions, in year 12 (two years after the last entry in the table) ?

31.2

A video-streaming service maintains a database of information about its customers and the videos they have watched. The program below analyzes the data in the database and compares the number of viewers of science fiction videos to the number of viewers of videos of other genres. It uses the procedure Analysis (category), which returns the number of unique users who viewed videos of a given category in the past year. The Analysis procedure takes approximately 1 hour to return a result, regardless of the number of videos of the given genre. All other operations happen nearly instantaneously. sciFiFans ← Analysis ("science fiction") genreList ← ["comedy", "drama", "mystery", "romance"] FOR EACH genre IN genreList { IF (Analysis (genre) > sciFiFans) { DISPLAY (genre) } } Which of the following best approximates the amount of time it takes the program to execute?

5 hours

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

8

The diagram below shows a circuit composed of three logic gates. Each gate takes two inputs and produces a single output. For which of the following input values will the circuit have an output of false?

A = true, B = false, C = false, D = false

Which of the following describes a benefit of using hexadecimal numbers instead of binary numbers to represent data?

A hexadecimal representation of a value generally requires fewer digits than a binary representation of the same value.

Which of the following best characterizes a high-level programming language?

A language that uses multiple abstractions to manage complexity

A student is writing a program to model different real-world events using simulations. Which of the following simulations will generate a result that would best be stored using a Boolean variable?

A simulation of ipping a fair coin

A color is often represented by a 6-digit hexadecimal number that describes how the colors red, green, and blue are mixed to create the desired color. From left to right, the first two digits represent the amount of red, the second two digits represent the amount of green, and the last two digits represent the amount of blue. Which of the following hexadecimal numbers represents the color with the greatest amount of blue in it?

A100B0

A library of e-books contains metadata for each book. The metadata are intended to help a search feature find books that users are interested in. Which of the following is LEAST likely to be contained in the metadata of each e-book?

An archive containing previous versions of the e-book

Which of the following would be the best use of citizen science?

An experiment that requires data measurements to be taken in many dierent locations

Which of the following is an underlying assumption that is made when Moore's law is used?

As computer hardware improves, future computers will be able to run faster than current computers

A student wrote the following code for a guessing game. Line 1: secretNumber ← RANDOM (1, 100) Line 2: win ← false Line 3: REPEAT UNTIL (win) Line 4: { Line 5: DISPLAY ("Guess a number.") Line 6: guess ← INPUT () Line 7: IF (guess = secretNumber) Line 8: { Line 9: DISPLAY ("You got it right!") Line 10: } Line 11: ELSE Line 12: { Line 13: IF (guess > secretNumber) Line 14: { Line 15: DISPLAY ("Your guess is too high.") Line 16: } Line 17: ELSE Line 18: { Line 19: DISPLAY ("Your guess is too low.") Line 20: } Line 21: } Line 22: } While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction WIN←TRUE somewhere in the code. Where could win <-true be inserted so that the code segment works as intended?

Between line 9 and line 10

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom right square of the grid and facing toward the top of the grid. The following programs are each intended to move the robot to the gray square. Program II uses the procedure GoalReached, which returns true if the robot is in the gray square and returns false otherwise. Which of the following statements is true?

Both program I and program II correctly move the robot to the gray square.

A program contains the following procedures for string manipulation. Which of the following expressions can be used to generate the string "Happy"

Concat (Substring ("Harp", 1, 2), Substring ("Puppy", 3, 3))

Which of the following best describes the role of the Internet Engineering Task Force (IETF) ?

Developing standards and protocols for Internet communication

Which of the following is a true statement about Internet communication?

Every device connected to the Internet is assigned an Internet protocol (IP) address.

Which of the following is an example of symmetric encryption?

Finn and Gwen develop a system that maps each letter of the alphabet to a unique symbol using a secret key. Finn uses the key to write a message to Gwen where each letter is replaced with the corresponding symbol. Gwen uses the key to map each symbol back to the original letter.

A smartphone stores the following data for each photo that is taken using the phone. • The file name of the photo • The date and time the photo was taken • The geographic location where the photo was taken Assume that all of the photos that have been taken on the phone are accessible. Which of the following can be determined using the photo data described above? I. The number of photos that were taken at a particular geographic location II. The number of photos that were taken in the last year III. The name of the person who took the most recent photo

I and II only

Which of the following actions could be used to help reduce the digital divide? I. Providing free education and training on how to use computing devices II. Providing free or low-cost computing devices to low-income individuals III. Providing networks and infrastructure to people in remote areas

I, II, and III

The procedure below searches for the value target in list. It returns true if target is found and returns false otherwise. Which of the following are true statements about the procedure? I. It implements a binary search. II. It implements a linear search. III. It only works as intended when list is sorted.

II only

Which of the following best describes one of the benefits of using an iterative and incremental process of program development?

It helps programmers identify errors as components are added to a working program.

A free online encyclopedia contains articles that can be written and edited by any user. Which of the following are advantages the online encyclopedia has over a traditional paper-based encyclopedia? Select two answers.

The ability to quickly update encyclopedia content as new information becomes available The ability to have a larger number of perspectives reected in the encyclopedia content

An online retailer uses an algorithm to sort a list of n items by price. The table below shows the approximate number of steps the algorithm takes to sort lists of different sizes. Based on the values in the table, which of the following best characterizes the algorithm for very large values of n ?

The algorithm runs in reasonable time.

A musician is creating a song using audio samples. Which of the following actions will minimize the risk of a copyright violation when creating sample-based music?

Using samples published with a no-rights-reserved Creative Commons license

A spinner is divided into three sections. The sector labeled Red is four times as large as each of the sectors labeled Blue and Yellow, which are of equal size. The procedure below is intended to simulate the behavior of the spinner. Which of the following can be used to replace <MISSING CODE> so that the procedure correctly simulates the spinner?

a

Grades in a computer science course are based on total points earned on a midterm exam and a final exam. The teacher provides a way for students to improve their course grades if they receive high scores on the final exam: if a student's final exam score is greater than the student's midterm exam score, the final exam score replaces the midterm exam score in the calculation of total points. The table below shows two students' scores on the midterm and final exams and the calculated total points each student earns. • Khalil does better on the midterm exam than on the final exam, so his original midterm and final exam scores are added to compute his total points. • Josefina does better on the final exam than on the midterm exam, so her final exam score replaces her midterm exam score in the total points calculation. A programmer is writing a procedure to calculate a student's final grade in the course using the score replacement policy described. The student's exam scores are stored in the variables midtermExam and finalExam. The procedure Max (a, b) returns the larger of a and b. Which of the following could be used in the procedure to calculate a student's total points earned in the course and store the result in the variable adjustedTotal?

adjustedTotal ← Max (midtermExam, nalExam) + nalExam

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

c

The ticket prices at a movie theater are given below. Type of Ticket Price(in dollars) Regular 12 Child (ages 12 and below) 9 Senior (ages 60 and above) 9 Additional $5 fee for 3-D movies A programmer is creating an algorithm to set the value of ticketPrice based on the information in the table. The programmer uses the integer variable age for the age of the moviegoer. The Boolean variable is3D is true when the movie is 3-D and false otherwise. Which of the following code segments correctly sets the value of ticketPrice ?

c

A snack bar has a frequent customer program in which every 10th purchase is free. Customers are enrolled in the program when they make their first purchase. A programmer is writing a program to implement the frequent customer program. In one code segment, cost is set to 0 for every 10th purchase by a given customer. The programmer will use the procedure GetCount (customerID), which returns the total number of purchases a customer has made since enrolling in the frequent customer program, including his or her first purchase. Which of the following code segments will set cost to 0 for every 10th purchase a customer makes after enrolling in the frequent customer program? a count ← GetCount (customerID) IF (count / 10 = 0) { cost ← 0 } b count ← GetCount (customerID) IF (NOT (count MOD 10 = 0)) { cost ← 0 } c count ← GetCount (customerID) IF (NOT (count / 10 = 0)) { cost ← 0 } d count ← GetCount (customerID) IF (count MOD 10 = 0) { cost ← 0 }

count ← GetCount (customerID) IF (count MOD 10 = 0) { cost ← 0 }

A student is creating a procedure to determine whether the weather for a particular month was considered very hot. The procedure takes as input a list containing daily high temperatures for a particular month. The procedure is intended to return true if the daily high temperature was at least 90 degrees for a majority of days in the month and return false otherwise. PROCEDURE IsHot (temperatureList) { total ← 0 counter ← 0 FOR EACH temperature IN temperatureList { IF (temperature ≥ 90) { counter ← counter + 1 } total ← total + 1 } RETURN (<MISSING CODE>) } Which of the following can be used to replace <MISSING CODE> so that the procedure works as intended?

counter > 0.5 * total

A flowchart is a way to visually represent an algorithm. The flowchart below is used by an apartment rentalWeb site to set the variable include to true for apartments that meet certain criteria. Which of the following statements is equivalent to the algorithm in the owchart?

include ← (floor > 10) OR (bedrooms = 3)

The code segment below is intended to swap the values of the variables first and second using a temporary variable, temp. temp <----- rst rst<----- second <missing code> Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended?

second <---- temp

The procedure Smallest is intended to return the least value in the list numbers. The procedure does not work as intended. PROCEDURE Smallest (numbers) { min ← numbers[1] FOR EACH number IN numbers { IF (number < min) { 9/30 RETURN (number) } } RETURN (min) } For which of the following values of theList will Smallest (theList) NOT return the intended value? Select two answers.

theList ← [40, 30, 20, 10] theList ← [30, 40, 20, 10]


Related study sets

Sociology quiz 1-6, Sociology of Fam Ch. 7 Review

View Set

Types of Hotels - Targeting specific markets and offering specific amenities.

View Set

Chapter 15: Nursing Care of the Child with an Infection

View Set

Comm 301 Chapter 1- University of Delaware

View Set