AP Computer Science Principles Unit 2 Review - Additional Practice

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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

This question uses a robot in a grid of squares. The robot is represented by a triangle which is initially in the bottom left-hand corner and is facing toward the top of the grid. Based on the following algorithm, what would the robot's final position be? Move two squares forward . . . if you can move to the right . . . . . . rotate right . . . . . . move two squares forward . . . if you can move to the left . . . . . . rotate left . . . . . . move forward one square Rotate left

In middle, facing left

The question below uses a robot in a grid of squares. The robot is represented by a triangle which is initially located in the center square facing towards the top. Which of the following code segments would successfully move the robot to the grey square?

REPEAT 2 TIMES { MOVE_FORWARD () REPEAT 2 TIMES { ROTATE_RIGHT () MOVE_FORWARD () } ROTATE_LEFT () }

What kind of flow pattern is best represented by this portion of a larger flowchart?

Selection

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

The amount of storage required by the algorithm

Below is a robot represented by a triangle, in a grid of squares. The robot is in the upper right-hand corner and is facing toward the bottom. Following is the code that is supposed to move the robot through the grid to get to the grey square; however, two of the REPEAT n TIMES and/or IF CONDITION lines have been swapped. Which lines of instruction need to be swapped in order to make the code work as intended? Select two answers.

-Line 1 -Line 4

"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

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. Which of the following plans would be the most practical and most efficient solution for computing an accurate population count, no matter how large the community grows?

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.

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

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.

Consider the following algorithm which uses the variables i and sum: What will happen when the algorithm is run?

Nothing will be displayed, the program will run indefinitely.

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.

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which starts in the bottom left square of the grid facing up. The robot can move into any white square (including the numbered squares) but not into a black square. The program below is intended to move the robot from its starting position on the left to the far right of the grid. It uses the procedure Square_Number () which returns the value of the number written on the square if there is one and returns 0 otherwise. REPEAT UNTIL NOT (Square_Number ()=0) { IF (CAN_MOVE (right)) { ROTATE_RIGHT () } IF (CAN_MOVE (forward)) { MOVE_FORWARD () } IF (CAN_MOVE (left)) { ROTATE_LEFT () } } What is the result of running the program?

The robot will reach the right of the grid and finish on the square numbered 1.

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.

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 flow chart is intended to display the lyrics of a song when followed correctly. 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

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 describes a search algorithm which would be very inefficient for finding values in the middle of a large ordered data set?

Sequential

The question below uses a robot in a grid of squares. The following code segment is used to move the robot within the grid. x ← RANDOM (1, 2) REPEAT x TIMES { MOVE FORWARD () } y ← RANDOM (1, 2) REPEAT y TIMES { ROTATE LEFT () } The robot is represented as a triangle, which finishes in the center square of the grid facing towards the bottom of the grid. Which of the following does NOT represent a possible starting position and direction for the robot?

facing right

n ← 3 REPEAT 3 TIMES { REPEAT n TIMES { MOVE_FORWARD( ) } ROTATE_LEFT( ) n ← n - 1 }

middle, middle


संबंधित स्टडी सेट्स

PrepU ch. 21 assessing heart and neck vessels

View Set

Health Emergencies: Life-Threatening Allergies

View Set

AWS Certified Machine Learning 1

View Set

Religion Chapter 4 Semester 2 study q's

View Set