ap comp sci Unit 6

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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?

8

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?

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

A certain game keeps track of the maximum and minimum scores obtained so far. If num represents the most recent score obtained, which of the following algorithms correctly updates the values of the maximum and the minimum?

If num is less than the minimum, set the minimum equal to num. Otherwise, if num is greater than the maximum, set the maximum equal to num.

A student is creating an algorithm to display the distance between the numbers num1 and num2 on a number line. The following table shows the distance for several different values. Value of num1 Value of num2 Distance Between num1 and num2 5 2 3 1 8 7 -3 4 7 Which of the following algorithms displays the correct distance for all possible values of num1 and num2 ?

Step 1: Subtract num1 from num2 and store the result in the variable diff. Step 2: Take the absolute value diff and display the result.

The figure below shows four grids, each containing a robot represented as a triangle. The robot cannot move to a black square or move beyond the edge of the grid. Which of the following algorithms will allow the robot to make a single circuit around the rectangular region of black squares, finishing in the exact location and direction that it started in each of the four grids?

Step 1:Keep moving forward, one square at a time, until the square to the right of the robot is no longer black. Step 2:Turn right and move one square forward. Step 3: Repeat steps 1 and 2 three more times.

Which of the following algorithms display all integers between 1 and 20, inclusive, that are not divisible by 3 ? Select two answers.

Step 1:Set x to 1.Step 2: If x is divisible by 3, then do nothing; otherwise display x. Step 3:Increment x by 1.Step 4: Repeat steps 2 and 3 until x is greater than 20. Step 1:Set x to 1. Step 2: If x is divisible by 3, then do nothing; otherwise display x. Step 3:Increment x by 1. Step 4: Repeat steps 2 and 3 until x is 20.

The following algorithm is intended to take a positive integer as input and display its individual digits in order from right to left. For example, if the input is 512, the algorithm should produce the output 2 1 5. Step 3 of the algorithm is missing. Step 1: Input a positive integer from the user and store it in the variable number. Step 2: Divide number by 10 and record the integer quotient and the remainder. The integer quotient is the quotient with any part after the decimal point dropped. For example, when 127 is divided by 10, the quotient is 12.7, the integer quotient is 12 and the remainder is 7. Step 3: (missing step) Step 4: Repeat steps 2 and 3 until number is 0. Which of the following can be used as step 3 so that the algorithm works as intended?

Step 3: Display the integer quotient of number divided by 10 and store the remainder in number.

A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display the number of elements in the list that have a value greater than 100. The algorithm uses the variables count and position. Steps 3 and 4 are missing. Step 1 Set count to 0 and position to 1. Step 2 If the value of the element at index position is greater than 100, increase the value of count by 1. Step 3 (missing step) Step 4 (missing step) Step 5 Display the value of count. Which of the following could be used to replace steps 3 and 4 so that the algorithm works as intended?

Step 3: Increase the value of position by 1. Step 4: Repeat steps 2 and 3 until the value of position is greater than n.

Which of the following code segments can be used to interchange the values of the variables num1 and num2 ?

Temp <-- num1 num1 <-- num2 num2 <-- Temp

Which of the following best describes the ability of parallel computing solutions to improve efficiency?

The efficiency of a solution that can be broken down into parallel portions is still limited by a sequential portion.

The procedure BinarySearch (numList, target) correctly implements a binary search algorithm on the list of numbers numList. The procedure returns an index where target occurs in numList, or -1 if target does not occur in numList. Which of the following conditions must be met in order for the procedure to work as intended?

The values in numList must be in sorted order.

Which of the following best explains the ability to solve problems algorithmically?

There exist some problems that cannot be solved algorithmically using any computer.


Set pelajaran terkait

Lecture 4 - Quality System Regulation (QSR)

View Set

LSAT Logical Reasoning (PowerScore)

View Set

ATI priority setting framework review test

View Set

Anatomy and Physiology Skeletal System Anatomy Unit Test Review

View Set