AP CSP - UNIT 6

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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? A 10 B 15 C 5,000 D 10,000

15

Consider the following program. Which of the following expressions represents the value stored in the variable x as a result of executing the program? A 2 * 3 * 3 * 3 B 2 * 4 * 4 * 4 C 2 * 3 * 3 * 3 * 3 D 2 * 4 * 4 * 4 * 4

2 * 3 * 3 * 3 * 3

processor to execute each of two processes. Assume that neither process is dependent on the other. Process Execution Time on Either Processor P30 secondsQ45 seconds Which of the following best approximates the difference in execution time between running the two processes in parallel instead of running them one after the other on a single processor? A 15 seconds B 30 seconds C 45 seconds D 75 seconds

30 seconds

An online game collects data about each player's performance in the game. A program is used to analyze the data to make predictions about how players will perform in a new version of the game. The procedure GetPrediction (idNum) returns a predicted score for the player with ID number idNum. Assume that all predicted scores are positive. The GetPrediction procedure takes approximately 1 minute to return a result. All other operations happen nearly instantaneously. Two versions of the program are shown below. Version I topScore ←← 0 idList ←← [1298702, 1356846, 8848491, 8675309] FOR EACH id IN idList { score ←← GetPrediction (id) IF (score > topScore) { topScore ←← score } } DISPLAY (topScore) Version II idList ←← [1298702, 1356846, 8848491, 8675309] topID ←← idList[1] FOR EACH id IN idList { IF (GetPrediction (id) > GetPrediction (topID)) { topID ←← id } } DISPLAY (GetPrediction (topID)) Which of the following best compares the execution times of the two versions of the program? A Version I requires approximately 1 more minute to execute than version II. B Version I requires approximately 5 more minutes to execute than version II. C Version II requires approximately 1 more minute to execute than version I. D Version II requires approximately 5 more minutes to execute than version I.

Version II requires approximately 5 more minutes to execute than version I.

In the following code segment, assume that x and y have been assigned integer values. sum ←← 0 REPEAT x TIMES { REPEAT y TIMES { sum ←← sum + 1 } } At the end of which of the following code segments is the value of sum the same as the value of sum at the end of the preceding code segment? Select two answers. A sum ←← 0 z ←← x + y REPEAT z TIMES { sum ←← sum + 1 } B sum ←← 0 z ←← x * y REPEAT z TIMES { sum ←← sum + 1 } C sum ←← 0 REPEAT x TIMES { sum ←← sum + 1 } REPEAT y TIMES { sum ←← sum + 1 } D sum ←← 0 REPEAT y TIMES { REPEAT x TIMES { sum ←← sum + 1 } }

sum ←← 0 z ←← x * y REPEAT z TIMES { sum ←← sum + 1 } sum ←← 0 REPEAT y TIMES { REPEAT x TIMES { sum ←← sum + 1 } }

A sorted list of numbers contains 500 elements. Which of the following is closest to the maximum number of list elements that will be examined when performing a binary search for a value in the list? A 10 B 50 C 250 D 500

10

A video-streaming service maintains a database of information about its customers and the videos they have watched. The program below analyzes the data in the database and compares the number of viewers of science fiction videos to the number of viewers of videos of other genres. It uses the procedure , which returns the number of unique users who viewed videos of a given category in the past year. The procedure takes approximately 1 hour to return a result, regardless of the number of videos of the given genre. All other operations happen nearly instantaneously. Which of the following best approximates the amount of time it takes the program to execute? A 1 hour B 2 hours C 4 hours D 5 hours

5 hours

A sorted list of numbers contains 128 elements. Which of the following is closest to the maximum number of list elements that can be examined when performing a binary search for a value in the list? A 2 B 8 C 64 D 128

8

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? A 5 B 8 C 100 D 200

8

A certain computer has two identical processors that are able to run in parallel. Each processor can run only one process at a time, and each process must be executed on a single processor. The following table indicates the amount of time it takes to execute each of three processes on a single processor. Assume that none of the processes are dependent on any of the other processes. Which of the following best approximates the minimum possible time to execute all three processes when the two processors are run in parallel? A 60 seconds B 70 seconds C 80 seconds D 90 seconds

80 seconds

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. Based on the values in the table, which of the algorithms appear to run in reasonable time? Select two answers. A Algorithm A B Algorithm B C Algorithm C D Algorithm D

Algorithm A Algorithm D

Which of the following best describes a challenge involved in using a parallel computing solution? A A parallel computing solution may not be appropriate for an algorithm in which each step requires the output from the preceding step. B A parallel computing solution may not be appropriate for an algorithm in which the same formula is applied to many numeric data elements. C A parallel computing solution may not be appropriate for an algorithm that can be easily broken down into small independent tasks. D A parallel computing solution may not be appropriate for an algorithm that searches for occurrences of a key word in a large number of documents.

A parallel computing solution may not be appropriate for an algorithm in which each step requires the output from the preceding step.

Which of the following programs is most likely to benefit from the use of a heuristic? A A program that calculates a student's grade based on the student's quiz and homework scores B A program that encrypts a folder of digital files C A program that finds the shortest driving route between two locations on a map D A program that sorts a list of numbers in order from least to greatest

A program that finds the shortest driving route between two locations on a map

A company delivers packages by truck and would like to minimize the length of the route that each driver must travel in order to reach nn delivery locations. The company is considering two different algorithms for determining delivery routes. Algorithm IGenerate all possible routes, compute their lengths, and then select the shortest possible route. This algorithm does not run in reasonable time.Algorithm IIStarting from an arbitrary delivery location, find the nearest unvisited delivery location. Continue creating the route by selecting the nearest unvisited location until all locations have been visited. This algorithm does not guarantee the shortest possible route and runs in time proportional to n2n2. Which of the following best categorizes algorithm II? A Algorithm II attempts to use an algorithmic approach to solve an otherwise undecidable problem. B Algorithm II uses a heuristic approach to provide an approximate solution in reasonable time. C Algorithm II provides no improvement over algorithm I because neither algorithm runs in reasonable time. D Algorithm II requires a much faster computer in order to provide any improvement over algorithm I.

Algorithm II uses a heuristic approach to provide an approximate solution in reasonable time.

The two code segments below are each intended to display the average of the numbers in the list . Assume that contains more than one value. Which of the following best describes the two code segments? A Code segment I displays the correct average, but code segment II does not. B Code segment II displays the correct average, but code segment I does not. C Both code segments display the correct average, but code segment I requires more arithmetic operations than code segment II. D Both code segments display the correct average, but code segment II requires more arithmetic operations than code segment I.

Both code segments display the correct average, but code segment I requires more arithmetic operations than code segment II.

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom left square of the grid and facing right. The following programs are each intended to move the robot to the gray square. Program II uses the procedure GoalReached, which returns true if the robot is in the gray square and returns false otherwise. Which of the following statements best describes the correctness of the programs? A Program I correctly moves the robot to the gray square, but program II does not. B Program II correctly moves the robot to the gray square, but program I does not. C Both program I and program II correctly move the robot to the gray square. D Neither program I nor program II correctly moves the robot to the gray square.

Both program I and program II correctly move the robot to the gray square.

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the bottom right square of the grid and facing toward the top of the grid. The following programs are each intended to move the robot to the gray square. Program II uses the procedure GOALREACHED, which returns TRUE if the robot is in the gray square and returns FALSE otherwise. Which of the following statements is true? A Program I correctly moves the robot to the gray square, but program II does not. B Program II correctly moves the robot to the gray square, but program I does not. C Both program I and program II correctly move the robot to the gray square. D Neither program I nor program II correctly moves the robot to the gray square.

Both program I and program II correctly move the robot to the gray square.

Programs I and II below are each intended to calculate the sum of the integers from 1 to n. Assume that n is a positive integer (e.g., 1, 2, 3, ...). Which of the following best describes the behavior of the two programs? A Program I displays the correct sum, but program II does not. B Program II displays the correct sum, but program I does not. C Both program I and program II display the correct sum. D Neither program I nor program II displays the correct sum.

Both program I and program II display the correct sum.

Consider the code segment below. Which of the following changes will NOT affect the results when the code segment is executed? A Changing line 3 to b <-- 10 B Changing line 3 to a <-- b + 10 C Changing line 7 to b <-- 20 D Changing line 7 to a <-- b + 20

Changing line 3 to b <-- 10

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? A Appending a value to a list of n elements, which requires no list elements be examined. B Finding the fastest route that visits every location among nn locations, which requires n possible routes be examined. C Performing a binary search for a score in a sorted list of n scores, which requires that fewer than n scores be examined. D Performing a linear search for a name in an unsorted database of n people, which requires that up to n entries be examined.

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

A programmer is deciding between using a linear or binary search to find a target value in a sorted list. Which of the following is true? A In all cases, a binary search of a sorted list requires fewer comparisons than a linear search. B Generally, the advantage of using a binary search over a linear search increases as the size of the list increases. C A linear search will generally run faster than a binary search because a linear search requires fewer lines of code to implement. D Using a linear search is preferable to using a binary search if there is a chance that the target may not be found in the list.

Generally, the advantage of using a binary search over a linear search increases as the size of the list increases.

Consider the following algorithms. Each algorithm operates on a list containing n elements, where n is a very large integer. An algorithm that accesses each element in the list twice An algorithm that accesses each element in the list n times An algorithm that accesses only the first 10 elements in the list, regardless of the size of the list Which of the algorithms run in reasonable time? A I only B III only C I and II only D I, II, and III

I, II, and III

For which of the following lists can a binary search be used to search for an item in the list? ["blue", "green", "jade", "mauve", "pink"] [5, 5, 5, 5, 6, 7, 8, 8, 8] [10, 5, 3, 2, -4, -8, -9, -12] A I only B III only C I and III only D I, II, and III

I, II, and III

Consider the following code segment with an integer variable num. IF(num > 0) { DISPLAY("positive") } IF(num < 0) { DISPLAY("negative") } IF(num = 0) { DISPLAY("zero") } Which of the following code segments is equivalent to the code segment above? A IF(num < 0) { DISPLAY("negative") } ELSE { DISPLAY("positive") } IF(num = 0) { DISPLAY("zero") } B IF(num < 0) { DISPLAY("negative") } ELSE { IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") } } C IF(num ≤ 0) { DISPLAY("negative") } ELSE { IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") } } D IF(num ≤ 0) { DISPLAY("negative") } IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") }

IF(num < 0) { DISPLAY("negative") } ELSE { IF(num = 0) { DISPLAY("zero") } ELSE { DISPLAY("positive") } }

Three different numbers need to be placed in order from least to greatest. For example, if the numbers are ordered 9, 16, 4, they should be reordered as 4, 9, 16. Which of the following algorithms can be used to place any three numbers in the correct order? A If the first number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them. B If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. C If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. Then, if the first number is greater than the last number, swap them. D If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them.

If the first number is greater than the middle number, swap them. Then, if the middle number is greater than the last number, swap them. Then, if the first number is greater than the middle number, swap them.

The following question uses a robot in a grid of squares. The robot is represented as a triangle, which is initially facing toward the top of the grid. The following code segment moves the robot around the grid. Assume that n is a positive integer. Line 1: count ←← 0 Line 2: REPEAT n TIMES Line 3: { Line 4: REPEAT 2 TIMES Line 5: { Line 6: MOVE_FORWARD() Line 7: } Line 8: ROTATE_RIGHT() Line 9: } Consider the goal of modifying the code segment to count the number of squares the robot visits before execution terminates. Which of the following modifications can be made to the code segment to correctly count the number of squares the robot moves to? A Inserting the statement count ←← count + 1 between line 6 and line 7 B Inserting the statement count ←← count + 2 between line 6 and line 7 C Inserting the statement count ←← count + 1 between line 8 and line 9 D Inserting the statement count ←← count + n between line 8 and line 9

Inserting the statement count ←← count + 1 between line 6 and line 7

A programmer wrote the code segment below to display the average of all the elements in a list called numbers. There is always at least one number in the list. The programmer wants to reduce the number of operations that are performed when the program is run. Which change will result in a correct program with a reduced number of operations performed? A Interchanging line 1 and line 2 B Interchanging line 5 and line 6 C Interchanging line 6 and line 7 D Interchanging line 7 and line 8

Interchanging line 7 and line 8

A student wants to create an algorithm that can determine, given any program and program input, whether or not the program will go into an infinite loop for that input. The problem the student is attempting to solve is considered an undecidable problem. Which of the following is true? A It is possible to create an algorithm that will solve the problem for all programs and inputs, but the algorithm can only be implemented in a low-level programming language. B It is possible to create an algorithm that will solve the problem for all programs and inputs, but the algorithm requires simultaneous execution on multiple CPUs. C It is possible to create an algorithm that will solve the problem for all programs and inputs, but the algorithm will not run in reasonable time. D It is not possible to create an algorithm that will solve the problem for all programs and inputs.

It is not possible to create an algorithm that will solve the problem for all programs and inputs.

The following grid contains a robot represented as a triangle, which is initially in the bottom-left square of the grid and facing the top of the grid. The robot can move into a white or a gray square but cannot move into a black region. The following code segment implements an algorithm that moves the robot from its initial position to the gray square and facing the top of the grid. When the robot reaches the gray square, it turns around and faces the bottom of the grid. Which of the following changes, if any, should be made to the code segment to move the robot back to its original position in the bottom-left square of the grid and facing toward the bottom of the grid? A Interchange the ROTATE_RIGHT and the ROTATE_LEFT blocks. B Replace ROTATE_RIGHT with ROTATE_LEFT. C Replace ROTATE_LEFT with ROTATE_RIGHT. D No change is needed; the algorithm is correct as is.

No change is needed; the algorithm is correct as is.

Consider the two programs below. Which of the following best compares the values displayed by programs A and B? A Program A and program B display identical values in the same order. B Program A and program B display the same values in different orders. C Program A and program B display the same number of values, but the values differ. D Program B displays one more value than program A.

Program A and program B display the same values in different orders.

A computer has two processors that are able to run in parallel. The table below indicates the amount of time it takes either processor to execute four different processes. Assume that none of the processes is dependent on any of the other processes. A program is used to assign processes to each of the processors. Which of the following describes how the program should assign the four processes to optimize execution time? A Processes W and X should be assigned to one processor, and processes Y and Z should be assigned to the other processor. B Processes W and Y should be assigned to one processor, and processes X and Z should be assigned to the other processor. C Processes W and Z should be assigned to one processor, and processes X and Y should be assigned to the other processor. D Process Z should be assigned to one processor, and processes W, X, and Y should be assigned to the other processor.

Processes W and Z should be assigned to one processor, and processes X and Y should be assigned to the other processor.

Consider the two programs below. Which of the following best compares the values displayed by programs A and B? A Program A and program B display identical values. B Program A and program B display the same values in different orders. C Program A and program B display the same number of values, but the values differ. D Program A and program B display a different number of values.

Program A and program B display the same number of values, but the values differ.

A certain computer has two identical processors that are able to run in parallel. The following table indicates the amount of time it takes to execute each of four processes on a single processor. Assume that none of the processes is dependent on any of the other processes. Which of the following parallel computing solutions would minimize the amount of time it takes to execute all four processes? A Running processes P and Q on one processor and processes R and S on the other processor B Running processes P and R on one processor and processes Q and S on the other processor C Running processes P and S on one processor and processes Q and R on the other processor D Running process P on one processor and processes Q, R, and S on the other processor

Running processes P and Q on one processor and processes R and S on the other processor

A student wants to determine whether a certain problem is undecidable. Which of the following will demonstrate that the problem is undecidable? A Show that for one instance of the problem, an algorithm can be written that is always capable of providing a correct yes-or-no answer. 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. C Show that for one instance of the problem, a heuristic is needed to write an algorithm that is capable of providing a correct yes-or-no answer. D Show that for one instance of the problem, an algorithm that runs in unreasonable time can be written that is capable of providing a correct yes-or-no answer.

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

Which of the following best explains how algorithms that run on a computer can be used to solve problems? A All problems can be solved with an algorithm that runs in a reasonable amount of time. B All problems can be solved with an algorithm, but some algorithms might need a heuristic to run in a reasonable amount of time. C All problems can be solved with an algorithm, but some algorithms might run in an unreasonable amount of time. D Some problems cannot be solved by an algorithm.

Some problems cannot be solved by an algorithm.

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? A Step 1:Keep moving forward, one square at a time, until the square to the right of the robot is black.Step 2:Turn right and move one square forward.Step 3:Repeat steps 1 and 2 three more times. B 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. C Step 1:Move forward three squares.Step 2:Turn right and move one square forward.Step 3: If the square to the right of the robot is black, repeat steps 1 and 2. D Step 1:Move forward three squares.Step 2:Turn right and move one square forward.Step 3:If the square to the right of the robot is not black, repeat steps 1 and 2.

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.

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 nn shapes, where nn is a very large number? A The algorithm runs in a reasonable amount of time because it will use approximately n steps to draw n shapes. B The algorithm runs in a reasonable amount of time because it will use approximately n2 steps to draw n shapes. C The algorithm runs in an unreasonable amount of time because it will use approximately n steps to draw n shapes. D The algorithm runs in an unreasonable amount of time because it will use approximately n2 steps to draw nn shapes.

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

An online retailer uses an algorithm to sort a list of n items by price. The table below shows the approximate number of steps the algorithm takes to sort lists of different sizes. Based on the values in the table, which of the following best characterizes the algorithm for very large values of n ? A The algorithm runs in reasonable time. B The algorithm runs, but not in reasonable time. C The algorithm attempts to solve an undecidable problem. D The algorithm attempts to find an approximate solution whenever it fails to find an exact solution.

The algorithm runs in reasonable time.

Which of the following best describes the ability of parallel computing solutions to improve efficiency? A Any problem that can be solved sequentially can be solved using a parallel solution in approximately half the time. B Any solution can be broken down into smaller and smaller parallel portions, making the improvement in efficiency theoretically limitless as long as there are enough processors available. C The efficiency of parallel computing solutions is rarely improved over the efficiency of sequential computing solutions. D The efficiency of a solution that can be broken down into parallel portions is still limited by a sequential portion.

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

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? A The list contains both positive and negative elements. B The elements of the list are not sorted. C The list contains an odd number of elements. D The list contains duplicate elements.

The elements of the list are not sorted.

A certain computer game is played between a human player and a computer-controlled player. Every time the computer-controlled player has a turn, the game runs slowly because the computer evaluates all potential moves and selects the best one. Which of the following best describes the possibility of improving the running speed of the game? A The game's running speed can only be improved if the game is played between two human players instead of with the computer-controlled player. B The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn. C The game's running speed cannot be improved because computers can only be programmed to find the best possible solution. D The game's running speed cannot be improved because the game is an example of an algorithm that does not run in a reasonable time.

The game's running speed might be improved by using a process that finds approximate solutions every time the computer-controlled player has a turn.

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? A The genetic codes must be converted from binary to decimal numbers. B The list must be sorted based on the genetic code values. C The number of genetic code values in the list must be a power of 2. D The number of genetic code values in the list must be even.

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

Consider the following program, which is intended to display the number of times a number target appears in a list. Which of the following best describes the behavior of the program? A The program correctly displays the number of times target appears in the list. B The program does not work as intended when target does not appear in the list. C The program does not work as intended when target appears in the list more than once. D The program does not work as intended when target appears as the last element of the list.

The program correctly displays the number of times target appears in the list.

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? A The value of x is approximately equal to the value of y. B The value of x is approximately 10 less than the value of y. C The value of x is approximately 13 less than the value of y. D The value of x is approximately 200 less than the value of y.

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

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? A The length of numList must be even. B The list numList must not contain any duplicate values. C The values in numList must be in sorted order. D The value of target must not be equal to -1.

The values in numList must be in sorted order.

Which of the following statements is true? A Every problem can be solved with an algorithm for all possible inputs, in a reasonable amount of time, using a modern computer. B Every problem can be solved with an algorithm for all possible inputs, but some will take more than 100 years, even with the fastest possible computer. C Every problem can be solved with an algorithm for all possible inputs, but some of these algorithms have not been discovered yet. D There exist problems that no algorithm will ever be able to solve for all possible inputs.

There exist problems that no algorithm will ever be able to solve for all possible inputs.

Which of the following best explains the ability to solve problems algorithmically? A Any problem can be solved algorithmically, though some algorithmic solutions may require humans to validate the results. B Any problem can be solved algorithmically, though some algorithmic solutions must be executed on multiple devices in parallel. C Any problem can be solved algorithmically, though some algorithmic solutions require a very large amount of data storage to execute. D There exist some problems that cannot be solved algorithmically using any computer.

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

Which of the following best explains why it is not possible to use computers to solve every problem? A Current computer processing capabilities cannot improve significantly. B Large-scale problems require a crowdsourcing model, which is limited by the number of people available to work on the problem. C The ability of a computer to solve a problem is limited by the bandwidth of the computer's Internet connection. D There exist some problems that cannot be solved using any algorithm.

There exist some problems that cannot be solved using any algorithm.

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? A The problem can be solved algorithmically, but it will require an unreasonably long amount of time. B The problem can be solved algorithmically, but it will require an unreasonably large amount of data storage. C There is no possible algorithm that can be used to solve all instances of the problem. D There are several different possible algorithms that can solve the problem, but there is controversy about which is the most efficient.

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

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem? A When the problem can be solved in a reasonable time and an approximate solution is acceptable B When the problem can be solved in a reasonable time and an exact solution is needed C When the problem cannot be solved in a reasonable time and an approximate solution is acceptable D When the problem cannot be solved in a reasonable time and an exact solution is needed

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

A flowchart is a way to visually represent an algorithm. The flowchart below is used by an application to set the Boolean variable available to true under certain conditions. The flowchart uses the Boolean variable weekday and the integer variable miles. Which of the following statements is equivalent to the algorithm in the flowchart? A available <-- weekday or miles < 20 B available <-- weekday and miles < 20 C available <-- weekday or miles >= 20 D available <-- weekday and miles >= 20

available <-- weekday and miles < 20

The question below uses a robot in a grid of squares. The robot is represented as a triangle, which is initially in the center square and facing toward the top of the grid. The following code segment is used to move the robot in the grid. count ←← 1 REPEAT 4 TIMES { REPEAT count TIMES { MOVE_FORWARD() } ROTATE_LEFT() count ←← count + 1 } Which of the following code segments will move the robot from the center square along the same path as the code segment above? A count ←← 0 REPEAT 4 TIMES { count ←← count + 1 REPEAT count TIMES { MOVE_FORWARD() } ROTATE_LEFT() } B count ←← 0 REPEAT 4 TIMES { count ←← count + 1 ROTATE_LEFT() REPEAT count TIMES { MOVE_FORWARD() } } C count ←← 0 REPEAT 4 TIMES { REPEAT count TIMES { ROTATE_LEFT() } MOVE_FORWARD() count ←← count + 1 } D count ←← 0 REPEAT 4 TIMES { ROTATE_LEFT() REPEAT count TIMES { MOVE_FORWARD() } count ←← count + 1 }

count ←← 0 REPEAT 4 TIMES { count ←← count + 1 REPEAT count TIMES { MOVE_FORWARD() } ROTATE_LEFT() }

A student is creating a procedure to determine whether the weather for a particular month was considered very hot. The procedure takes as input a list containing daily high temperatures for a particular month. The procedure is intended to return if the daily high temperature was at least 90 degrees for a majority of days in the month and return otherwise. Which of the following can be used to replace so that the procedure works as intended? A counter < 0.5 x total B counter > 0.5 x total C total < 0.5 x counter D total > 0.5 x counter

counter > 0.5 x total

In the following statement, val1, val2, and result are Boolean variables. Which of the following code segments produce the same result as the statement above for all possible values of val1 and val2 ? Select two answers. A result <-- false IF val1 IF NOT val2 result <-- true B result <-- false IF val1 result <-- true IF NOT val2 result <-- true C IF val1 result <-- false ELSE IF val2 result <-- true ELSE result <-- true D IF val1 IF val 2 result <-- false ELSE result <-- true ELSE result <-- false

result <-- false IF val1 IF NOT val2 result <-- true IF val1 IF val 2 result <-- false ELSE result <-- true ELSE result <-- false


Kaugnay na mga set ng pag-aaral

Duties and Disclosures to Third Parties

View Set

Representing Data Sets with Histograms(Pre-Test and Quiz) 100%

View Set

ACCT 245 2022 FALL QUARTER EXAM PREP

View Set

Geometry B, Assignment 1. Symmetry

View Set

AP Econ Fall FInal Review Unit 8

View Set