A.P Computer Science Practice Questions for CodeHS Unit 13 and 3.11 - 3.18 College Board

¡Supera tus tareas y exámenes ahora con Quizwiz!

In the following procedure, the parameter str is a string and the parameter num is a number. PROCEDURE printArgs(str, num) { DISPLAY(num) DISPLAY(str) DISPLAY(num) } Consider the following code segment. printArgs("**", 1) printArgs("*", 2) What is displayed as a result of executing the code segment?

B 1 ** 1 2 * 2

A time stamp indicates the date and time that a measurement was taken. A data scientist has a list containing 10,000 time stamps, sorted in chronological order. Which of the following is closest to the maximum number of values that will need to be examined when performing a binary search for a value in the list?

B 15

A sorted list of numbers contains 200 elements. Which of the following is closest to the maximum number of list elements that will need to be examined when performing a binary search for a particular value in the list?

B 8

Which of the following procedures would be most useful as part of a program to determine whether a word appears in two different text files?

B A procedure isFound, which takes a word and a text file as input and returns true if the word appears in the text file

For which of the following situations would it be best to use a heuristic in order to find a solution that runs in a reasonable amount of time?

B Finding the fastest route that visits every location among n� locations, which requires n!�! possible routes be examined.

A computer science student completes a program and asks a classmate for feedback. The classmate suggests rewriting some of the code to include more procedural abstraction. Which of the following is NOT a benefit of procedural abstraction?

B Making the code run faster

A student wants to determine whether a certain problem is undecidable. Which of the following will demonstrate that the problem is undecidable?

B Show that for one instance of the problem, no algorithm can be written that is capable of providing a correct yes-or-no answer.

A graphic artist uses a program to draw geometric shapes in a given pattern. The program uses an algorithm that draws the shapes based on input from the artist. The table shows the approximate number of steps the algorithm takes to draw different numbers of shapes. Number of Shapes Drawn Number of Steps 417524635750 Based on the values in the table, which of the following best characterizes the algorithm for drawing n� shapes, where n� is a very large number?

B The algorithm runs in a reasonable amount of time because it will use approximately n2�2 steps to draw n� shapes.

Suppose that a list of numbers contains values [-4, -1, 1, 5, 2, 10, 10, 15, 30]. Which of the following best explains why a binary search should NOT be used to search for an item in this list?

B The elements of the list are not sorted.

A large number of genetic codes are stored as binary values in a list. Which one of the following conditions must be true in order for a researcher to obtain the correct result when using a binary search algorithm to determine if a given genetic code is in the list?

B The list must be sorted based on the genetic code values

A city planner is using simulation software to study crowd flow out of a large arena after an event has ended. The arena is located in an urban city. Which of the following best describes a limitation of using a simulation for this purpose?

B The model used by the simulation software often omits details so that it is easier to implement.

Consider the following procedure. Procedure CallExplanationdrawCircle(xPos, yPos, rad)Draws a circle on a coordinate grid with center (xPos, yPos) and radius rad The drawCircle procedure is to be used to draw the following figure on a coordinate grid. Let the value of the variable x be 2, the value of the variable y be 2, and the value of the variable r be 1. Which of the following code segments can be used to draw the figure?

B drawCircle(x, y, r) drawCircle(x, y + 3, r) drawCircle(x + 3, y, r) drawCircle(x + 3, y + 3, r)

Consider the following procedure. Procedure CallExplanationdrawLine(x1, y1, x2, y2)Draws a line segment on a coordinate grid with endpoints at coordinates (x1, y1) and (x2, y2) The drawLine procedure is to be used to draw the following figure on a coordinate grid. Let the value of the variable xVal be 6 and the value of the variable yVal be 5. Which of the following code segments can be used to draw the figure?

B drawLine(1, 5, xVal, yVal) drawline(1, 5, xVal, yVal + 2) drawline(1, 5, xVal, yVal - 2)

Consider a game where a player spins a wheel divided into four identical sections, labeled A, B, C, and D. If the player spins A, the score is 10. If the player spins B, the score is 5. If the player spins C or D, the score is -1. The following code segment is intended to implement the game. Which of the following could be used as a replacement for <MISSING STATEMENT> so the code segment works as intended?

B (random, 1, 4)

A natural science museum opened a new display that lets the visitors view animations of how the health of a coral reef varies based on water temperature, pollution levels, and the number of fish living around the reef. The visitors are able to choose a numerical value for each of the conditions. The exhibit's animations are determined by using a database to look up how healthy the coral reef is at the particular settings the visitor chooses and displaying a corresponding picture. What is one advantage of using an interactive exhibit like this instead of showing a poster with the same information?

By allowing the visitors to interact with the exhibit, the visitors will be able to understand coral reefs better since they will see the impacts of many different conditions in an easy-to-understand manner.

Polly and Sergei are working on a project to explain how the rise in oil prices is leading to a rise in lunch prices at their school. Polly wants to have a chart showing the oil prices every day over the past 18 months and a different chart showing the lunch prices every day over the past 18 months. Sergei argues that having two separate charts won't show the relationship between oil prices and lunch prices. He also thinks that the charts are showing too many data points. Instead, he wants to use a program to make a chart that shows both the oil prices and the lunch prices on the same chart. In addition, rather than plotting the prices for every day, he only wants to chart the average monthly prices for oil and lunch. Why would Sergei's approach make it easier for other people to analyze the data than Polly's approach

By transforming and summarizing the available data, Sergei's chart would more effective in showing any trends that may have occurred.

A student is writing a program that is intended to replace each negative value in a particular column of a spreadsheet with the value 0. Which of the following procedures is most likely to be useful in the student's program?

C A procedure findNegative, which returns the row number of the first negative value that appears in the column or -1 if there are no negative values.

A student has a data file containing 10,000 numerical values. The student is writing a program to compute the average of the numbers contained in the file. Which of the following procedures is most likely to be useful in the student's program?

C A procedure that returns the sum of the values in the file

A student wrote the following procedure to calculate the sum of the integers from 1 to 5. The student later decides to modify the procedure to calculate the sum of the integers from 1 to max, which represents any positive integer greater than 1. Which of the following changes should be made to the procedure to meet the student's goal? I. The procedure should take max as an input parameter. II. The condition in the REPEAT UNTIL block should be changed to count > max. III. The condition in the REPEAT UNTIL block should be changed to max < 5.

C I and II

In which of the following scenarios is using a simulation more beneficial than performing a calculation? Select two answers.

C Investigating ways to reduce the amount of trash in the ocean D Studying the effect of a genetic change in a population

A game program contains the following code to update three score variables, health, food, and knowledge. The maximum values for the three variables are 100, 80, and 25, respectively. health ←← health + 10 IF(health > 100) { health ←← 100 } food ←← food + 1 IF(food > 80) { food ←← 80 } knowledge ←← knowledge + 5 IF(knowledge > 25) { knowledge ←← 25 } The game program's author would like to write a procedure that could be used to update any variable in the game (myScore) that has a maximum value (myLimit) by a given amount (myAmount). A correct call of the procedure is shown below. myScore ←← updateScore(myScore, myAmount, myLimit) Which of the following is a correct implementation of updateScore ?

C PROCEDURE updateScore(score, amount, limit) { score ←← score + amount IF(score > limit) { score ←← limit } RETURN(score) }

Which of the following are benefits of procedural abstraction? Select two answers.

C Procedural abstraction makes it easier for people to read computer programs. D Procedural abstraction provides an opportunity to give a name to a block of code that describes the purpose of the code block.

In a certain game, a player may have the opportunity to attempt a bonus round to earn extra points. In a typical game, a player is given 1 to 4 bonus round attempts. For each attempt, the player typically earns the extra points 70% of the time and does not earn the extra points 30% of the time. The following code segment can be used to simulate the bonus round. Which of the following is NOT a possible output of this simulation?

C The player had 3 bonus round attempts and 7 of them earned extra points.

A student is developing a program that allows users to look up the definitions of words that appear in a book. The student plans to perform a large number of searches through a dictionary containing words and their definitions. The student will use a procedure written by a computer scientist to quickly search the dictionary (and knows that the procedure will return a definition if one is available). The student cannot modify the search procedure written by the computer scientist but can call the procedure by supplying a word. Which of the following is a true statement about the student's use of the computer scientist's search procedure?

C The student is reusing the computer scientist's procedural abstraction by knowing what the procedure does without knowing how it does it.

A team of programmers is designing software. One portion of the project presents a problem for which there is not an obvious solution. After some research, the team determines that the problem is undecidable. Which of the following best explains the consequence of the problem being undecidable?

C There is no possible algorithm that can be used to solve all instances of the problem.

Which of the following CANNOT be displayed as a result of executing the code segment?

D 1 3 2 4

In which of the following scenarios would a simulation be the LEAST beneficial?

D A retail company wants to determine the most popular item that was sold on the company's Web site last month.

Consider the following code segment. Which of the following describes the possible values of ans as a result of executing the code segment?

D Any integer value from 7 to 16, inclusive

For which of the following lists can a binary search be used to search for an item in the list? 1. ["blue", "green", "jade", "mauve", "pink"] 2. [5, 5, 5, 5, 6, 7, 8, 8, 8] 3. [10, 5, 3, 2, -4, -8, -9, -12]

D I, II, and III

A computer program contains code in several places that asks a user to enter an integer within a specified range of values. The code repeats the input request if the value that the user enters is not within the specified range. A programmer would like to create a procedure that will generalize this functionality and can be used throughout the program. The correct use of the procedure is shown below, where min is the least acceptable value, max is the greatest acceptable value, and promptString is the string that should be printed to prompt the user enter a value. inputVal ←← getRange(min, max, promptString) Which of the following is a correct implementation of the getRange procedure?

D PROCEDURE getRange(min, max, promptString) { DISPLAY(promptString) x ←← INPUT() REPEAT UNTIL(x ≥ min AND x ≤ max) { DISPLAY(promptString) x ←← INPUT() } RETURN(x) }

Which of the following best explains how algorithms that run on a computer can be used to solve problems?

D Some problems cannot be solved by an algorithm.

The transportation department plans to build a new high-speed train route between two cities. The transportation department wants to implement a simulation of the train before any construction begins on this project. Which of the following statements is true about the use of a simulation for this project?

D Using a simulation may expose potential safety issues that can be corrected before construction begins.

Consider the following procedures, which are used to control a device that draws lines on paper. Procedure CallExplanationpenDown()Places the device's pen on the paper so that a line is drawn when the device movespenUp()Lifts the device's pen off of the paper so that no line is drawn when the device movesgoForward(x)Moves the device forward x unitsturnRight(x)Rotates the device in place x degrees clockwise (i.e., makes an in-place right turn) Consider the goal of using the device to produce the following drawing, where each line shown has a length of 10 units and the horizontal lines are 10 units apart. The device is positioned at the upper-left corner of a sheet of paper and is facing right. Which of the following code segments will produce the drawing shown?

D penDown() goForward(10) penUp() turnRight(90) goForward(10) turnRight(90) penDown() goForward(10)

Consider the following procedures. PROCEDURE proc1(str) { DISPLAY(str) DISPLAY("happy") } PROCEDURE proc2(str1, str2) { proc1(str2) DISPLAY(str1) } What is displayed as a result of the procedure call proc2("birthday", "to you") ?

D to you happy birthday

Suppose you want to make a visualization that shows how many students bought certain quantities of candy from the vending machine during the month of September. Of the choices below, which chart would best convey this information to the person looking at the graph?

Histogram

What is data? I. Computer readable information II. Information collected about the physical world III. Programs that process images IV. Graphs and charts

I, II

Which of the following statements describes how mobile devices, the use of computers in more and more everyday interactions, and the ability to connect with other devices almost anywhere are changing society? I. People are able to use mobile devices for new applications such as finding directions or finding restaurants II. Data can be collected from thousands of sources and can be combined to provide new services to individuals and companies III. Buildings, cars, classrooms, and offices can now be engineered with sensors to automate tasks like adjusting the thermostat or even driving IV. Data that is collected can be used to identify social problems

I, II, III, IV

Which of the following statements are true about using visualizations to display a dataset? I. Visualizations are visually appealing, but don't help the viewer understand relationships that exist in the data II. Visualizations like graphs, charts, or visualizations with pictures are useful for conveying information, while tables just filled with text are not useful. III. Patterns that exist in the data can be found more easily by using a visualization

III only

Question: 4 News reporting agencies often want to find the public's opinion on current events. One particular agency is considering two different strategies to collect this data by collecting responses to online surveys. The two strategies are outlined below. Strategy One:1. Uses a database to store all of the survey responses2. Stores some data as text and some data as numbers3. Will track extra information about the survey taker that won't be publicly visible Strategy Two1. Uses a single spreadsheet to store all of the survey responses2. Stores all data as numbers3. Will not track any information other than the survey responses Which of the following statements is the most accurate comparison of these strategies?

Strategy One will allow the agency to conclude more about the public's opinion because it tracks extra metadata, while Strategy Two will make it hard to find trends and access particular pieces of the data.

The list listOne is a sorted list of numbers that contains 700 elements. The list listTwo is a sorted list of numbers that contains 900 elements. Let x represent the maximum number of list elements that will need to be examined when performing a binary search for a value in listOne, and let y represent the maximum number of list elements that will need to be examined when performing a binary search for a value in listTwo. Which of the following statements about x and y is true?

The value of x is approximately equal to the value of y.

Which of the following statements is true about data visualizations?

Visualizations take many forms, from tables to charts to images.

Which of the following statements is NOT a benefit of using computers to process data?

Websites can spy on people and gather large amounts of personal data without the user knowing.

In which of the following would using a chart to visualize data make sense?

Your school wants to track how many people attend the football games over time throughout the school year.

Consider the following procedure. PROCEDURE doSomething(num1, num2) { DISPLAY(num1) RETURN(num1) DISPLAY(num2) } Consider the following statement. DISPLAY(doSomething(10, 20)) What is displayed as a result of executing the statement above?

A 10 10

Which of the following is a benefit of using a simulation instead of an experiment to make a prediction? Select two answers.

A A simulation allows investigation of a phenomenon without the real-world limitations on time, safety, or budget. B A simulation can be used to model real-world events that are impractical for experiments.

A computer scientist is analyzing four different algorithms used to sort a list. The table below shows the number of steps each algorithm took to sort lists of different sizes. List Size Number of Steps for Algorithm A Number of Steps for Algorithm B Number of Steps for Algorithm C Number of Steps for Algorithm D 1102112204243308694401624165503212025 Based on the values in the table, which of the algorithms appear to run in reasonable time? Select two answers.

A Algorithm A D Algorithm D

For which of the following problems is using a simulation LEAST likely to be beneficial?

A Determining the longest word in a textbook

A spinner contains 12 regions of equal size. The regions are numbered 1 to 12. Which of the following code segments can be used to simulate the results of spinning the spinner three times and assigns the sum of the values obtained by the three spins to the variable sum ?

A sum ←← RANDOM(1, 12) + RANDOM(1, 12) + RANDOM(1, 12)

Which of the following statements is an example of computer-readable data?

A digital spreadsheet filled with measurements about the air quality of different major cities


Conjuntos de estudio relacionados

System Security Management Quiz 8

View Set

Business Studies - Nature of Business

View Set

Nursing Leadership & Management NCLEX Practice Quiz #2

View Set

UNIT 5: TELECOMMUNICATIONS SYSTEMS

View Set

add accent cedilla (ç) in nous form

View Set

Chapter 13: Physical Properties of Solutions HW Pt. 1

View Set