APCSP 2

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What will happen if the code below is run, and the condition for the if block is false?

The code within the forever loop will continue to execute, constantly checking the condition for the if block.

Which of the following will cause an algorithm to fall into an infinite loop?

The condition of the loop never becomes false

Consider the block of code below: What would be the most appropriate substitute for the missing Boolean Operator if the intention is to display "True" for only values of x between, but not equal to values of 0 and 10?

AND

Which of the following best describes the result of running the code segment?

Nothing is displayed; the program results in an infinite loop.

A team of students is programming a robot to find its way out of a maze (exact layout unknown) for a national competition. The robot will be timed, and teams with the best time will move on to the next level of the competition. What strategy should the team take?

Program the robot with a simple algorithm which, although not necessarily finding the ideal solution, will eliminate some overly long routes and find a reasonable solution quickly. The robot will then follow this route.

Consider the following code segment that allows a customer to request their preferred beverage and size of beverage (ounces). What is displayed if the user enters "16" and then "coffee" when the program runs

Short coffee

A program has been developed to compute the sum of all elements with a value greater than 10 in a list of integers. Which of the following statements best describes how iteration may be used to in the program in this example?

The program will repeat the execution of a block of commands which test the value of an item and add it to a running total (if it is greater than 10) for each value in the list.

A student developed a program that outputs the name of a fruit that begins with a letter, dependent upon the variable keyPressed, which stores the letter (from A to Z only) a user types on the keyboard. Below is a section of code from her program: Which of the following descriptions below would be a way that this student might have written the rest of her code so that it executes as intended? Select two answers.

Use 25 nested IF/ELSE blocks where the IF portion is formatted like the code segment above (changing the letters of the alphabet and fruits) and the else simply holding the next IF portion until the last ELSE, which displays a fruit that begins with Z. Use 26 IF blocks formatted similarly to the one above (changing the letters of the alphabet and fruits).

In a flowchart, a typical decision symbol has what type of output?

boolean (true/false)

Given the following code segment, what would be displayed if age were initialized with a value of 18?

group 2

The volume of a rectangular prism is calculated by multiplying its length (l), width (w) and height (h). What could be substituted into the section of the code below marked < missing code > that would accurately calculate the volume based on the user input of l, w and h?

l * w * h

Which statement below best describes the characteristics of an undecidable problem?

No algorithm can be constructed that always leads to a correct solution to the problem.

Below is a block of code intended to navigate a robot through a grid of squares. For which of the following grids will the code correctly navigate the robot to a final destination of the grey square and then terminate?

--

x ← 0 a ← 3 k ← 4 REPEAT a TIMES { REPEAT k TIMES { x ← x + a } x ← x * (-1) } DISPLAY x When the code above is run, what will be the final value of the variable x, displayed at the end of the program?

-12

Which of the following CollegeBoard AP Computer Science Principles Pseudocode commands is used to record something typed by a user of the program so that it can be used in the program?

INPUT ()

What is displayed as a result of running the following program? a ← 6 b ← 11 IF (a = b) { DISPLAY ("January") } ELSE { IF (a > b) { DISPLAY ("February") } ELSE { IF (a > 0) { DISPLAY ("March") } ELSE { DISPLAY ("April") } } }

March

Consider the following equivalent code segments that each display the first 12 positive and even integers.

Segment B will execute in less time than Segment A.

Which of the following best describes the output of the following code segment?

The word HI could be displayed 1, 2, 3, 4, 5, 6, 7, 8, 9, or 10 times

What should replace <missing statement> in the following code be if we want this code to repeat until the variable a is greater than 10? a ← 0 REPEAT UNTIL (<missing statement>) { a ← a + 1 }

a > 10

This is a section of code taken from a larger program. What outputs would be the best choice to substitute in for "missing output 1" and "missing output 2", based on the condition?

missing output 1: value does not equal 4 missing output 2: value is equal to 4

The algorithm below is used to simulate the results of rolling a standard 6-sided die 5 times. Consider the goal of determining whether the simulation resulted in more results which were odd than results which were even. Step 1:Initialize the variables odd_counter and roll_counter to 0.Step 2:A variable dice_roll is randomly assigned an integer value between 1 and 6 inclusive. If dice_roll has a value of 1, 3 or 5, then odd_counter is incremented by 1.Step 3:Increment the value of roll_counter by 1.Step 4:Repeat steps 2 and 3 until roll_counter equals 5. Following the execution of the algorithm, which of the following expressions indicates that the simulation resulted in more results which were odd than results which were even?

odd_counter>2

The block of code below is supposed to display "Multiple of 5" if the positive number value is in fact a multiple of 5.

(value MOD 5) = 0

Which of the following best describes the type of language used in the below algorithm? Prompt user for number if number is greater than or equal to 0 Output "Positive" else Output "Negative" Repeat 4 times

Pseudocode

The diagram below shows a circuit composed of three logic gates labeled OR and AND. Each gate takes two inputs and produces a single output. If inputs B and C are both true, which of the following best describes the final output produced by the circuit?

The output will be true if input D is true, and false otherwise.

This question references a robot in a grid of squares. The robot is represented by the triangle in the bottom left-hand corner and is facing toward the top. Based on the following program, what would the robot's final position be? MOVE_FORWARD MOVE_FORWARD IF (CAN_MOVE(right)) { ROTATE_RIGHT MOVE_FORWARD MOVE_FORWARD } IF (CAN_MOVE(left)) { ROTATE_LEFT MOVE_FORWARD ROTATE_LEF

--

Using the script below, what is the final output of the program?

1

The figure below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom white square and facing up. The goal is to move the triangle to the gray square. Consider the procedure MOVETURN below. Which of the following code segments will move the robot to the gray square?

--

Which is NOT true about comments in programs?

All published programs have their comments available.

If the variable score has a value of 10 at the beginning of a program, which runs according to the following flowchart, what will the value of score be at the end?

10

--

-15

Consider the given code fragment. Determine the output of the program fragment. m ← 2 REPEAT UNTIL(m > 500) { DISPLAY(m) m ← m + 2 }

All even numbers 2 4 6 8 ... 500

Consider the following code segment: What values, when inputted by the user, of A, B, and C will cause the code to display "Invalid Input"?

A = -5 B = 0 C = 0

In which of the following programs would the use of heuristics be LEAST likely to be recommended?

A program that calculates the total bill for all the items in a customer's online shopping cart including any taxes

Which of the following are examples of abstraction?

A programmer writes a procedure called volumeSphere which has a parameter radius and computes the area of a sphere with that radius. She uses this in her code each time the volume of a sphere needs to be computed. A diagram of a computer circuit is drawn using "logic gates".

Consider the following two algorithms for determining the tallest person in a group.

Algorithm A is never faster than Algorithm B

A particular problem is currently not able to be practically solved by using an algorithm. Which of the following statements about the problem could possibly be true? No algorithm has yet been developed which would solve this problem, but it is possible one may be developed in the future. An algorithm has been developed which would solve this problem but technology is not yet available which would compute this algorithm fast enough to be practicable. It is impossible to develop an algorithm which would solve this problem.

I, II, and III

Which of the following best describes the result of running the program below? number ← RANDOM (1, 6) REPEAT UNTIL number > 100 { number ← number * 2 } IF (number = 128) { DISPLAY (true) } ELSE { DISPLAY (false)

If number is a 1, 2 or 4, then the program will display true.

Below is a program that is supposed to be a "Guess a Number" game, wherein the user is trying to accurately guess a randomly generated number between 1 and 100. However, the program is not functioning as intended. Which two lines in the program need to be swapped in order for this program to work correctly? Select two answers.

Line 3 Line 5

A mathematician is working with a programmer to write a program to solve a problem using high level mathematics. The mathematician asks the programmer to help her determine the efficiency of the algorithm. How can the efficiency be determined?

Multiple inputs of various sizes and with different expected outputs can be tested to determine the behavior of algorithm.

Which of the following describes a search algorithm which would be very inefficient for finding values in the middle of a large ordered data set?

Sequential

Which of the following is the best example of a heuristic approach to solving a problem?

sing your thumb and forefinger in order to add a pinch of salt to a meal because the recipe that your grandma has written on an index card says, "Add some salt".

Sam and Emma are creating a multiplayer tic-tac-toe game. Below is a segment of their code that is used so that the Sprite on screen can tell the user whose turn it is. Before each user's turn, this set of code is run. What would condition 1 need to be so that this part of the program runs correctly? The variable turn is initialized as 0 at the start and player 1 always goes first.

turn MOD 2 = 1

The following procedure, validate (x), is intended to display "PASS" if an integer, x, is within the range of 128 through 32768, inclusive. Values of x that are not within the range should display "FAIL". Which of the following sets of test cases would be the best choice to fully test this procedure and provide evidence that it executes as intended for all values of x?

validate(127) validate(128) validate(2048) validate(32768) validate(32769)

Which of the following best describes the conditions which must be satisfied by the user-inputted values of x and y if the program is to display Right Right when run?

x must be 0 and y must be a positive number

After running the script below, what would be said by the sprite?

xyzzy

The partial flowchart below represents a section of a program. If the initial values at the start of this section are a = 10, b = 5 and c = 7, which of the following will be outputted when the program runs?

10, 7, 5

The following uses a robot in a grid of squares. The robot is represented by a triangle and is in the upper left corner facing toward the bottom of the grid. Which blocks of code will properly navigate the robot to the final destination of the grey square in the bottom right corner of the grid? Select two answers.

repeat 4 times rotate left move forward rotate right move forward

Consider the following code segment that appears in the middle of a program. Which of the following can replace the missing statement in the REPEAT UNTIL block so that the user will be required to enter the correct password of "swordfish" before they can continue on with the rest of the program.

userPassword = "swordfish"

Consider the following code segment that is intended to accept two integers, x and y, as input, and then display "yes" if and only if x is greater than y and y is less than or equal to 20. Otherwise, it should display "no". Unfortunately, the above code does not perform as intended. Identify two different options that a programmer might choose, either of which will correct the code so that it performs as intended. Select two answers.

Change the condition in the IF block to be: IF (x > y) AND (y ≤ 20) Swap the two DISPLAY blocks (i.e., DISPLAY "yes" and DISPLAY "no" )

Consider the given code: 1 integer ← 22 2 lowtemp ← 0 3 4 IF(integer < 10) 5 { 6 lowtemp ← lowtemp - 5 7 } 8 ELSE 9 { 10 lowtemp ← lowtemp + 10 11 } 12 13 DISPLAY(lowtemp) What is the best description of the structure implied by line 4?

Selection

What would a sprite say as a result of executing this script?

13

Which of the following illustrates an aspect of efficiency?

All of these

Which of the following algorithms require both selection and iteration?

An algorithm that, given a list of integers, displays the number of even integers in the list. An algorithm that, given a list of integers, displays only the negative integers in the list.

Moore's Law describes the rate at which the number of transistors on a single chip doubles over time. Which of the following assumptions CANNOT be inferred as a direct consequence of this rate of doubling?

Five years from now, web pages will require less memory (RAM) than today's web pages.

A standard deck of playing cards contains 52 cards, with each card being one of four suits: SPADES, HEARTS, CLUBS, and DIAMONDS. Each suit is represented by 13 cards whose values include ACE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, and KING. Consider the following two algorithms that are intended to find the card representing the "TEN of HEARTS" in a randomly shuffled deck and separate it from the other 51 cards in the deck.

Only Algorithm A will always work as intended.

Elsa and her friend Olaf are co-owners of the world's largest ice cream truck, offering their customers the choice of 256 different flavors of ice cream. The truck, which has been built from an 18-wheeled tractor-trailer, houses the 256 tubs of ice cream in the refrigerated trailer. The side of the truck displays a large list of the 256 names of the different flavors, which the customers then name when they place their orders. Business is booming and the duo needs to serve their customers quickly. However, in order to quickly find the right tub of ice cream out of such a large collection, Elsa and Olaf both agree that they need to use an efficient solution. Elsa suggests that they organize the flavors alphabetically while Olaf suggests that they organize the flavors in order from his favorite to his least favorite. Which of the following solutions would allow these ice cream peddlers to find the customers' chosen flavors the most efficiently?

Organize the tubs alphabetically by flavor name and use a binary search algorithm to find the customer's requested flavor.

A mathematics professor at Howard University wants his students to write a program to solve complex mathematical problems. The professor asks a programmer to determine the efficiency of each student's algorithm. How can the programmer determine the efficiency of an algorithm?

Run the program with many different inputs to determine how much CPU time will be required for algorithm to solve the problem for inputs of different sizes. Use mathematical calculations to determine how the number of computations performed by the program will increase as the size of the inputs increase.

Consider the following code: n ← 4 x ← -2.5 IF(n < 3) { DISPLAY("Team A") } ELSE { IF(n < 2) { DISPLAY("Team B") } ELSE { IF(x > -2) { DISPLAY("Team C") } ELSE { DISPLAY("Team D") } } }

Team D

Which of the following is a key factor in determining the efficiency of an algorithm?

The amount of storage required by the algorithm

Frankie is considering whether to use a binary or linear search in her program to find a value in a sorted list. When she tests the algorithms on selection of short lists of fixed-length lists she finds that the binary search is faster on average than the linear search. Another programmer suggests she tests both algorithms on a selection of lists which are 10 times as long as her original test lists. Which of the following best describes the likely results of this test?

The binary search will still be faster on average than the linear search, and the difference in run times between the two searches will be significantly more than 10 times greater than for the shorter lists.

Sally notices that she has the same set of 10 blocks in her code in multiple places. She decides to create a new block (procedure) in Scratch so that she can simply replace those 10 blocks with one procedure. Which of the following gives the best ways in which this could be beneficial to Sally when she debugs and reasons through her program?

The procedure can make the code section more abstract, so she doesn't have to think through all 10 blocks each time she comes across them in her code. If there is an error in the procedure, she can fix the error in the procedure without having to search through her code for each place the procedure is used.

The following question uses a robot in a grid of squares. Which of the following will cause the robot code to stop executing?

The robot attempts to move off its grid.

If the variables onTime and absent both have the value false, what is displayed as a result of running the code segment?

Better late than never.

Consider the following code segments designed to find the area of a triangle using the formula A = ½ bh. Program A Program B Which of the following statements about the above programs is true?

Both programs will work as intended, but Program B is more readable.

Consider the code segment below. Line 1: IF (b ≠ 0) Line 2: { Line 3: a ← a/b Line 4: } Line 5: ELSE Line 6: { Line 7: a ← a*b Line 8: } Which of the following changes will NOT affect the results when the code segment is executed?

Changing line 7 to a ← 0

The program below calculates and displays the sum of the integers from m to n inclusive, where m < n. Line 1: i ← m Line 2: r ← n-m+1 Line 3: sum ← 0 Line 4: REPEAT r TIMES Line 5: { Line 6: sum ← sum+i Line 7: i ← i+1 Line 8: } Line 9: DISPLAY sum If Line 1 is changed to read i ← n, which of the following changes will ensure that the program continues to calculate and displays the sum of the integers from m to n inclusive?

Change line 7 to read i ← i-1

"The iteration (repetition) pattern repeats a set of instructions until a certain <missing word> is met." Which of the following words should be used to replace <missing word>?

Condition

Computers may be programmed to play logic games such as chess and go. These games have an incredibly large number of possible move sequences which may be made. Which of the following describes a good strategy and accompanying rationale for creating an algorithm which a computer can use to play these games?

Develop an algorithm which uses heuristics because this will be able to provide reasonable solutions, and evaluating every possible move will take an impractical amount of time.

The following is the only script attached to a sprite in Scratch. Which of the following best describes what will be drawn on the screen when the green flag is clicked (you may assume the sprite starts in the center of the screen with all default settings)?

Nothing will be drawn; the program lacks a pen down command.

Consider the following code: REPEAT UNTIL (x mod 2 = 1) { x ← x + 3 } Assume that x is initially 6. How many times will the loop iterate?

1

A team of students is collaborating on a program to obtain local weather data from a website, and predict weather-related school closings based on their own formulas. They must present their code to a group of faculty, some of whom have little to no experience with code. What strategies can the group use while writing their code, in order to make it more understandable for the faculty? Select two answers.

Choose meaningful names for all variables and procedures. Include comments detailing the purpose and behavior of variables and procedures.

The local government for a newly developed community would like to begin conducting an annual census to make an accurate count of its current population and gather other relevant demographic information about its residents. The community is currently relatively small and consists of around 500 homes. However, it is growing quickly and expects to have more than 100,000 homes in the next few years.

Every year, mail a copy of the census form to every home in the community and require that each household complete the form themselves and mail it back to a central office for processing. Then follow up with those that did not.

The software for an elevator uses a variable, called level, to track the floor number of the elevator's current position. When a person presses a button indicating that the elevator should rise to a higher floor, the following goUp procedure is invoked with the desired number of floors to climb provided as a parameter. What is displayed if the elevator is currently on the 7th floor (level = 7) and the procedure goUp(3) is invoked?

Level 8 Level 9 Cannot go up. Level 9

Using the flowchart below, what value when entered for Y will generate a mathematical error and prevent our flowchart from being completely executed?

None of these values will produce a mathematical error

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem?

When the problem cannot be accurately solved in a reasonable time and an approximate solution is acceptable.

Consider the code segment below. If the variable Income begins with a value of 90, and Expenses with a value of 100, what will be displayed by running the program?

You can recover.

Which of the following statements are reasons why the lyrics of this song cannot be unambiguously determined from the flowchart? The selection of which statements should be run where there are choices present is ambiguous Which elements of the code should be repeated and how many times is ambiguous The direction each individual arrow should be followed in is ambiguous.I and II only

I and II only

Which of the following are likely to be important considerations when writing a program to be capable of processing large data sets? Reducing the memory usage of the program Reducing the number of statements in the program Reducing the CPU time required to run the program

I and III only

Which of the following is used in the instructions below to determine how the task of "having breakfast" will be performed? Dump cereal in bowl Pour milk in bowl Eat cereal and milk Place spoon and bowl in dishwasher Sequencing Selection Iteration

I only

The following lines of code can be used are part of a program which is designed to calculate the total a person will pay for a meal which costs mealTotal before a tax and tip is paid. The final amount should include tax on the original mealTotal at a percentage of taxRate and a tip at a percentage of tipRate on the original mealTotal. mealTotal ← mealTotal + tip + tax tip ← mealTotal * tipRate / 100 tax ← mealTotal * taxRate / 100 DISPLAY mealTotal In which of the following orders could the lines I-IV be placed if the program is to run as intended? Select two answers.

II, III, I, IV III, II, I, IV

What must you consider when determining the efficiency of an algorithm? Select two choices.

The length of time required to run the program The amount of resources, such as storage, required

In the program below, x is an integer between 5 and 10 inclusive. What is the maximum possible value of answer after running the program?

20

Consider the following: Which of the following values is displayed if the user inputs the following list of values for each prompt? 1 2 3 4 5 6 7 8 9 15

6

Consider the given code using variables a, b, and c. What will be the output of this code? a ← 2 b ← 6 c ← 12 a ← b b ← c DISPLAY(a) DISPLAY(c)

6 12

Consider the following block of code: Which two of the following values are more likely to be displayed than the other two values listed when the this block of code is run? Select two answers.

12 14

What will the final value of a be, after running the script below?

18

What will be displayed when the code segment below, using the variables a, b, and c, is run?

2 0

What would be the final value of the variable third once the following program is complete? first ← 2 second ← 3 third ← first * second second ← third - first first ← first + second + third third ← second * first

48

Which of the following would be the most appropriate name for the following procedure (currently named MYSTERY), where number is any number and the procedure CHECK (number) returns true if the number is an integer and false if not? PROCEDURE MYSTERY (number) { IF (number > 0 AND CHECK (number)) { RETURN (true) } RETURN (false)

IS_POS_INT

A program needs to allow a customer to input integers until the input number is zero. When the input number is zero, the program should write the message "The number of integers you have input is: X" (instead of X there should be the total count of numbers input). What should be added below to replace the question mark?

Increment count by 1

The following program segment is intended to move a robot from the starting position to the ending position as shown above. However, the program segment does not work correctly. Line 1: MOVE_FORWARD () Line 2: MOVE_FORWARD () Line 3: IF(CAN_MOVE (right)) Line 4: { Line 5: MOVE_FORWARD () Line 6: MOVE_FORWARD () Line 7: ROTATE_RIGHT () Line 8: } Line 9: ROTATE_LEFT () Line 10: ROTATE_LEFT () Which 2 lines of code in the segment above must be switched in order for the program to correctly move a robot from the starting position to the ending position? Select two answers.

Line 7 Line 5

A study of beech trees shows that around 40% of these trees may be susceptible to a newly discovered disease. The computer program below is intended to determine the number of trees which may be susceptible to the disease in a forest containing k beech trees: Line 1: total ← 1 Line 2: repeat k times Line 3: { Line 4: IF () Line 5: { Line 6: total ← total + 1 Line 7: } Line 8: } Line 9: DISPLAY (total) Which of the following could be used to replace <MISSING CONDITION> to ensure the program works as intended? Select two answers.

RANDOM (1, 5) < 3 RANDOM (1, 5) ≤ 2

Consider the following code: IF (n > 0) { DISPLAY ("The number is positive.") } ELSE { DISPLAY ("The number is not positive.") } What will be output by this code if the number n is zero?

The number is not positive.

Which of the following best describes an effect of Moore's Law?

The past record of increasing computing power has driven more investment in innovation

A travel organization organizes a trip to London. The price changes based on the number of applicants. The following program is used to display the price of the trip and uses the variable Applicants which is set to the number of applicants for the trip. If the number of applicants is 60, what will be displayed?

The price of the trip is $250!

A company is completing research and development for software which it is planning to produce in approximately 2 years time. Which of the following assumptions should the company make about the processing speeds of the hardware which will be used to run this software.

The processing speeds of hardware which will exist in 2 years time will likely be double the current processing speeds.


Ensembles d'études connexes

Nutrition Ch. 15- Hunger and the Future of Food

View Set

PrepU - Chapter 42: Management of Patients with Musculoskeletal Trauma

View Set

Ch 5. - Other Investment Vehicles

View Set

Quiz 2: Intro to Pharm and Blood Products

View Set