17.2.1 - CodeHS AP Computer Science Principles

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/69

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:21 PM on 4/25/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

70 Terms

1
New cards

Which of the following is NOT a characteristic of the redundant nature of routing on the Internet?

The ability to use a hierarchical naming system to avoid naming conflicts

2
New cards

A cell phone company recently upgraded its network to include 5th generation technology (5g). They wanted to track the rollout, compared to the last upgrade when they rolled out the 4th generation technology (4g). 5g allows users to download data at higher speeds compared to 4g data. The accompanying table and chart show the total data usage across their system for the first 3 years (only 30 months are available for 5g).

7500

3
New cards

Procedures A and B are meant to get the minimum value of a list of one or more integers. We have the two procedures below

Procedure A

PROCEDURE getMin(list)

{

min ← list[1]

FOR EACH item IN list

{

IF (item < min) {

min ← item

}

}

RETURN min

}

Procedure B

PROCEDURE getMin(list)

{

min ← list[1]

counter ← 1

REPEAT LENGTH (list) TIMES:

{

counter ← counter + 1

item ← list[counter]

IF (item < min) {

min ← item

}

}

RETURN min

}

Procedure A returns the correct minimum value, but Procedure B does not.

4
New cards

Consider the following code segment:

i ← 1

counter ← 1

repeat until

{

DISPLAY (i)

i ← i * 2

counter ← counter + 1

}

counter > 10

5
New cards

The question below uses a robot in a grid of squares. The robot is represented by a triangle, which is initially at the bottom-left square of the grid facing toward the right of the grid. The robot can move into a white or gray square, but cannot move into a black region.

The goal is to move the robot in a grid to a gray square.

REPEAT UNTIL (CAN_MOVE (left))

{

MOVE_FORWARD ()

}

ROTATE_LEFT ()

MOVE_FORWARD ()

6
New cards

An online video publisher began offering unlimited video file storage for its users in 2013. As a result, they saw their business grow rapidly. The amount of storage that the company needed was also increasing rapidly.

To help decrease this cost, the company implemented a new lossy data compression algorithm. This algorithm allowed them to shrink the file of all new and existing videos, but it did have an impact on the quality of the videos.

The number of customers and the number of GB of storage are represented in the following charts and table.

The lossy compression algorithm impacted the quality of videos, so users started using other services.

7
New cards

Consider the code segment below.

PROCEDURE Mystery (word, list)

{

FOR EACH item IN list

{

IF (item = word)

{

RETURN (true)

}

}

RETURN (false)

}

Which of the following best describes the behavior of the Mystery PROCEDURE?

Return whether or not word is in list

8
New cards

Consider the code segment below.

PROCEDURE Mystery (word, list)

{

x ← 0

y ← 0

FOR EACH item IN list

{

IF (item = word)

{

x ← x + 1

}

ELSE

{

x ← 0

}

IF (x > y)

{

y ← x

}

}

RETURN (y)

}

What is the value of

Mystery("karel", ["karel", "karel", "tracy", "karel", "karel", "karel", "tracy"])

3

9
New cards

Which of the following statements are true about this network:

I - The network is fault tolerant. If a single connection fails, any two devices can still communicate.

II - Computers B and F need to first communicate with at least one other device in order to communicate with each other.

I and II

10
New cards

Which of the following code options will make the robot (the triangle) touch all of the gray squares?

MOVE_FORWARD ()

ROTATE_LEFT ()

MOVE_FORWARD ()

REPEAT 3 TIMES:

{

ROTATE_LEFT ()

MOVE_FORWARD ()

MOVE_FORWARD ()

}

11
New cards

researcher is emailing images of soil samples back to her lab so her team can analyze them. She notices that the images sent in her email are of lower quality than the images on her camera. Which of the following could be a possible explanation for the difference in image quality?

Before being sent, the image was compressed using a lossy compression technique

12
New cards

What is the minimum number of bits you would need to represent a number on a 0 to 10 scale?

4

13
New cards

A video viewing Website previously used 32-bit integers to store the number of views for each video, but a video that had been watched billions of times hit the maximum value. What is it called when this maximum is exceeded?

overflow error

14
New cards

Question: 14

Consider the code segment below.

PROCEDURE Mystery (number)

{

RETURN ((number MOD 2) = 0)

}

Which of the following best describes the behavior of the Mystery PROCEDURE?

Returns whether or not number is even

15
New cards

A bank uses a computer program during the night to tell if the alarm should be rung. Sensors in the bank set the following Boolean variables:

vaultClosed: set to true if the bank vault is closed; otherwise false

heardNoise: set to true if a microphone heard noise; otherwise false

sawMovement: set to true if a camera saw movement in the bank; otherwise false

The automatic alarm should notify the police if there is noise and movement in the bank, or if the bank vault is open. Which of the following boolean expressions can be used in a selection statement to ring the alarm?

NOT vaultClosed OR (heardNoise AND sawMovement)

16
New cards

We want to create an algorithm called swapValues. Given two variables x and y the result should have the values of x and y swapped. Which of the following algorithms correctly swaps the values of x and y?

temp ← x

x ← y

y ← temp

17
New cards

Which of the following programs is most likely to benefit from the use of a heuristic?

A program that computes the best move to play in a board game

18
New cards

A Website is considering an update to its servers that would save the geolocations of users accessing the site. Which of the following is LEAST likely to occur as a result of this update?

Users in a certain location may no longer be able to access the Website

19
New cards

Given the following algorithms, which one uses selection?

Given two numbers display the larger of the two

20
New cards

Digital images are often represented by the red, green, and blue values (an RGB triplet) of each individual pixel in the image. A photographer is manipulating a digital image and overwriting the original image. Which of the following describes a lossy transformation of the digital image (a transformation in which information is lost and cannot be restored)?

Creating the gray scale of an image by averaging the amounts of red, green, and blue in each pixel and assigning this new value to the corresponding pixel in the new image. The new value of each pixel represents a shade of gray, ranging from white to black.

21
New cards

A city government is attempting to reduce the digital divide between groups with differing access to computing and the Internet.

Which of the following actions is MOST likely to be effective in this purpose?

Providing free wireless Internet connections at locations in low-income neighborhoods

22
New cards

Program 1 and 2 below are intended to calculate the average of the integers in a list, number_list.

Program 1

sum ← 0

FOR EACH number in number_list

{

sum ← sum + number

}

DISPLAY (sum / LENGTH (number_list))

Program 2

counter ← 1

sum ← 0

FOR EACH number in number_list

{

sum ← sum + number

counter ← counter + 1

}

DISPLAY (sum / counter)

Program 1 displays the correct average, but Program 2 does not

23
New cards

An online video publisher began offering unlimited video file storage for its users in 2013. As a result, they saw their business grow rapidly. The amount of storage that the company needed was also increasing rapidly.

To help decrease this cost, the company implemented a new lossy data compression algorithm. This algorithm allowed them to shrink the file of all new and existing videos, but it did have an impact on the quality of the videos.

The number of customers and the number of GB of storage are represented in the following charts and table.

2017

24
New cards

and is considering two different types of material to use for the beams in the building. The company decides to use a computer simulation of each option to determine which material will cause the building to be more stable.

Which of the following is NOT true about the company's plan?

simulation will not produce usable results

25
New cards

A search engine has a trend-tracking feature that provides information on how popular a search term is. The data can be filtered by geographic region, date, and search term.

Which of the following questions is LEAST likely to be answerable using the trends feature?

What region of the country has the highest population of a particular animal?

26
New cards

In the procedure Mystery written below, the parameter number is a positive integer.

PROCEDURE Mystery (number)

{

result ← 1

REPEAT UNTIL (number = 1)

{

result ← result * number

number ← number - 1

}

RETURN (result)

}

Which of the following best describes the result of running the Mystery procedure?

The return value will be a positive integer greater than or equal to the initial value of number

27
New cards

Which of the following is true about why it is important to write clear function names

The name makes it clear what the purpose of the function is.

28
New cards

Which of the following statements describes a limitation of using a heuristic approach to solve a problem?

A heuristic approach can only provide an approximate solution, rather than an exact solution

29
New cards

Biologists are researching the migration patterns of birds. They have attached tracking collars to several wild birds.

For each bird, the following geolocation data is collected at frequent intervals.

The time

The date

The location of the bird

Which of the following questions about the group of tracked birds COULD be answered using only the data collected from the tracking collars?

Correct Answer

In what month do the birds tend to travel the farthest?

30
New cards

Which of the following Boolean expressions is not equivalent to the expression

num * -1 ≥ 10

(num < 0) AND (num * -1 = 10)

31
New cards

Given the following Mystery procedure, how can you best describe the result it returns?

PROCEDURE Mystery (list, target)

{

length ← LENGTH (list)

i ← 1

REPEAT length TIMES

{

if (list[i] = target)

{

REMOVE(list, i)

}

ELSE

{

i ← i + 1

}

}

RETURN (list)

}

This procedure returns the list without any instance of the given target

32
New cards

Which of the following is considered an unethical use of computer resources?

Using an image on a website without giving credit to the original creator

33
New cards

Computers are often used to search through large sets of data to find useful patterns in the data.

Which of the following tasks is an example where searching for patterns is needed to produce useful information?

Correct Answer

An online retail store analyzing customers' viewing habits to suggest other products based on the purchasing history of other customers

34
New cards

Algorithm 1:

Given a list songList, and a target value songToFind:

Step 1: A variable position is assigned a random index within songList

Step 2: A variable song is assigned the value at songList[position]

Step 3: IF song = songToFind, return position. ELSE, go back to step 1

Algorithm 2:

Given a list songList, and a target value songToFind:

Step 1: Repeat Steps 2 and 3 for every index i in songList:

Step 2: A variable song is assigned the value at songList[i]

Step 3: IF song = songToFind, return i

Step 4: Return -1

Generally, as the size of songList becomes larger, Algorithm 2 will be more efficient than Algorithm 1

35
New cards

Why is it important to focus on programming style in addition to programming functionality?

I) Program style helps others understand your program and maintain it

II) Programming style only applies to certain programming languages

III) Programming style increases the reusability of your code

I and III

36
New cards

Consider the code segment below. You can assume that Mystery returns either true or false, and Input_List_From_User asks the user for several values and returns them as a list.

inputList ← Input_List_From_User ()

resultList ← []

FOR EACH item in inputList

{

IF (Mystery (item))

{

APPEND (resultList, item)

}

}

Based on the code segment, how would you best describe the value of resultList?

resultList contains all items from inputList that met the Mystery condition

37
New cards

The computer science department at a university is using the following program to determine the average GPA of the department on a 4 point scale. Unfortunately, some of the data was entered incorrectly and values greater than 4 exist in the system. The department determines that if a student's GPA is greater than 4 it should be excluded from the average. The students' GPAs are stored in the list studentGPAs, which is indexed from 1 to n.

IF (studentGPAs[i] ≤ 4)

{

gradePointAverageSum ← gradePointAverageSum + studentGPAs[i]

}

ELSE

{

numGPAs ← numGPAs - 1

}

i ← i + 1

38
New cards

What is the purpose of the Digital Millennium Copyright Act?

To criminalize the act of circumventing, or getting around, access controls that block access to copyrighted works.

39
New cards

A blogging Website allows users to post messages and to comment on other messages that have been posted. When a user posts a message, the message itself is considered data. In addition to the data, the site stores the following metadata.

The time the message was posted

The name of the user who posted the message

The names of any users who comment on the message and the times the comments were made

Which of the following questions could NOT be answered using only the data and metadata collected?

In what country is the site most active?

40
New cards

Consider the code segment below.

x = RANDOM (1, 10)

y = RANDOM (10, 20)

DISPLAY (x == y)

Which of the following best describes the behavior of the the code?

The program could display either true or false

41
New cards

The robot must get to the grey square at the bottom left hand corner by jumping over the black hurdle. The program to achieve this is:

ROTATE_LEFT ()

MOVE_FORWARD ()

ROTATE_RIGHT ()

JUMP_HURDLE ()

ROTATE_RIGHT ()

MOVE_FORWARD ()

Which of the procedures below is the correct implementation of the JUMP_HURDLE procedure used in the above program?

PROCEDURE JumpHurdle ()

{

MOVE_FORWARD ()

ROTATE_LEFT ()

MOVE_FORWARD ()

MOVE_FORWARD ()

ROTATE_LEFT ()

MOVE_FORWARD()

}

42
New cards

Consider the following program, which is intended to print the count of even numbers between 1 and number

count ← 0

i ← 1

REPEAT number TIMES

{

IF (i MOD 2 = 0)

{

count ← count + 1

}

i ← i + 1

}

DISPLAY count

Which of the following best describes the behavior of this program?

The program correctly displays the count of even numbers between 1 and number

43
New cards

The chart shows that the data usage for 5g is higher than it was for a similar time period for 4g. Based on the explanation and the datsa, which of the following is the LEAST likely explanation for the higher data usage for 5g?

The average file size has grown over time

44
New cards

Consider the code segment below.

PROCEDURE Mystery (x)

{

result ← 0

REPEAT 2 TIMES

{

REPEAT 3 TIMES

{

result ← x + result

}

}

RETURN result

}

Which of the following expressions is equivalent to the value returned from Mystery(x)?

23x

45
New cards

A programmer wrote the following program intending to print the maximum value in list. You can assume list contains numerical values and has at least one element in it.

Line 1: max ← 0

Line 2: FOR EACH num IN list

Line 3: {

Line 4: IF (num > max)

Line 5: {

Line 6: max ← num

Line 7: }

Line 8: }

Line 9: DISPLAY (max)

What change do you need to make to be able to display the correct maximum value for any list of integers?

change line 1

46
New cards

Based on the information in the table, which of the following tasks is likely to take the longest amount of time when scaled up for a very large company of approximately 100,000 customers?

task B

47
New cards

Which of the following statements are true about how the file is sent to the user?

I - The file is broken down into several packets for transmission.

II - The packets must be reassembled by the user's device upon receipt.

III - The user's browser must request each individual packet, in order, until all packets are received

I and II

48
New cards

A byte is made up of 8 bits (binary digits). You have a programming language that uses one byte to represent characters and are now modifying your language to use two bytes to represent characters. How many more characters can you represent in your new programming language?

2^8 as many

49
New cards

Line 1: IF (x = 0)

Line 2: {

Line 3: x ← -1 * x + y

Line 4: }

Line 5: ELSE

Line 6: {

Line 7: x ← x + y

Line 8: }

Which of the following will NOT affect the results when the code segment is executed?

change line 3

50
New cards

Given the following code segment, how can you best describe its behavior?

result ← 0

FOR EACH n IN list

{

if (n MOD 2 = 0)

{

result ← result + n

}

}

DISPLAY result

This code displays the sum of the even numbers in list

51
New cards

ASCII is a character-encoding scheme that uses 7 bits to represent each character. The decimal (base 10) values 65 through 90 represent the capital letters A through Z, as shown in the table below.

Q

52
New cards

Which of the following describes a limitation of cloud computing?

Storing data using cloud computing rather than storing on a personal computer may weaken the security of data

53
New cards

Consider the code segment below.

PROCEDURE Mystery (x, y)

{

result ← 0

REPEAT y TIMES

{

REPEAT x TIMES

{

result ← result + 1

}

}

RETURN result

}

Which of the following expressions is equivalent to the value returned from Mystery(x, y)?

y*x

54
New cards

In the program below, the initial value of a is 0 and the initial value of b is 1.

IF (b = 0)

{

IF (b = 1)

{

DISPLAY ("Karel")

}

}

ELSE

{

IF (a = 1)

{

DISPLAY ("Tracy")

}

ELSE

{

DISPLAY ("Dog")

}

DISPLAY ("Turtle")

}

What is displayed as a result of running this program?

Dog Turtle

55
New cards

Which of the following statements are true:

I - Every problem can be solved with an algorithm for all inputs, but some of these algorithms have not yet been discovered

II - Every problem can be solved with an algorithm for all inputs, but some problems cannot be solved in a reasonable amount of time

III - There exist problems that cannot be solved by any algorithm for all inputs

III only

56
New cards

Which of the following statements describes an advantage of using a computer simulation to model a real-world object or system?

Simulations allow us to test real-world events without the cost or danger of building and testing the phenomena in the real world.

57
New cards

What does this flowchart algorithm display?

?

58
New cards

What is the minimum number of connections that must be broken or removed in the network before computer E can no longer communicate with computer F?

2

59
New cards

Based on the code segment, how would you best describe the value of resultList

resultList contains the result of calling the Mystery procedure on every item in inputList

60
New cards

A large data set contains information about all students in colleges across the United States. The data set contains the following information about each student.

The student's gender

The state in which the student attends college

The student's grade point average on a 4.0 scale

The student's major

Which of the following questions could be answered by analyzing only information in the data set?

How many states have computer science as the most common major for female students?

61
New cards

For which of the following goals would it be more useful to computationally analyze the metadata instead of the data?

I. Estimate the number of texts that will be sent next month

II. Determine the most frequently used emoji in text messages

III. Determine if two phones have been in contact in the last week

I and III

62
New cards

Based on the data, which period saw the highest percentage growth in 4g usage from the previous period?

18 - 24

63
New cards

Assume we have an algorithm used to simulate the results of flipping a coin n times. Two variables used for the algorithm are heads_counter, storing the number of heads we've had, and flip_counter, storing the number of flips we've made. We want to add on to the algorithm so that at the end we display whether there were an odd or even number of tails.

Here are two algorithms that display whether we have an even or odd number of tails:

Algorithm A: Set the value of num_tails to (flip_counter - heads_counter). If the value of num_tails MOD 2 is equal to 0, DISPLAY ("Even"), otherwise DISPLAY ("ODD").

Algorithm B: Set the value of even_flips to (n MOD 2) = 0 and set the value of even_heads to (heads_counter MOD 2) = 0. If even_flips is equal to even_heads then DISPLAY ("EVEN"), otherwise DISPLAY ("ODD").

Both A and B

64
New cards

Which of the following activities poses the LEAST potential cybersecurity risk?

Sharing your device's public key used for encryption

65
New cards

Consider the following code segment:

i ← 100

repeat until i = 0

{

}

Which of the following replacements for will cause an infinite loop?

i ← i MOD 3

66
New cards

Which of the following code options can be used to move the robot (the black triangle) to the gray square?

REPEAT 4 TIMES: { ROTATE_LEFT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () ROTATE_RIGHT () MOVE_FORWARD () ROTATE_LEFT () }

67
New cards

A program is expressed in a programming language. Which of the following is true of the program?

The program can also be expressed as binary code, which is what the program will be translated to in order to execute on the computer

68
New cards

Which of the following are true statements about phishing attacks?

I only

69
New cards

Consider the code segment below.

PROCEDURE Mystery (x)

{

result ← 0

REPEAT 5 TIMES

{

result ← x + result

}

RETURN result

}

Which of the following expressions is equivalent to the value returned from Mystery(x)?

x * 5

70
New cards

Which of the following activities poses the greatest personal cybersecurity risk?

Emailing your bank account number to an online vendor to purchase a product from them