cs

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

In the following procedure, the parameter n is an integer greater than 2. PROCEDURE compute n result <- 1 j <- 2 REPEAT UNTIL j>n result <- result + j j<- j + 1 RETURN result Which of the following best describes the value returned by the procedure?

D. The procedure returns the sum of the integers from 1 to n.

Consider the following procedure. Procedure -CallExplanation drawLine(x1, y1, x2, y2) - Draws a line segment on a coordinate grid with endpoints at coordinates (x1, y1) and (x2, y2) 11 22 33 44 55 The drawLine procedure is to be used to draw the following figure on a coordinate grid. Which of the following code segments can be used to draw the figure?

A. xVal ← 1 yVal ← 0 len ← 1 REPEAT 5 TIMES { drawLine(xVal, yVal, xVal, yVal + len) xVal ← xVal + 1 len ← len + 1 }

A flowchart is a way to visually represent an algorithm. The flowchart below uses the following building blocks. OVAL: start or end of yer algorithm RECTANGLE: One or more processing steps, such as a statement that assigns a value to a variable DIAMOND: A conditional or decision step, where execution proceeds to the side labeled TRUE if the condition is true and to the side labeled FALSE otherwise PARALLELOGRAM: Displays a message oval:Start rectangle: count<-1 diamond: count<5 -->false parallelogram: DISPLAY (count)--> circle: end -->true rectangle: count <-count +1 returns to diamond: count<5 * true or false thingy What is displayed as a result of executing the algorithm in the flowchart?

A. 5

A computer program uses 3 bits to represent integers. When the program adds the decimal (base 10) numbers 5 and 3, the result is 0. Which of the following is the best explanation for the result?

A. An overflow error occurred.

Which of the following research proposals is most likely to be successful as a citizen science project?

A. Collecting pictures of birds from around the world that can then be analyzed to determine how location affects bird size

Two grids are shown below. Each grid contains a robot represented as a triangle. Both robots are initially facing left. Each robot can move into a white or gray square, but cannot move into a black region. GRID 1: Eww bbw www wbb wwS GRID 2: Eww bwb wwb wbb wwS For each grid, the program below is intended to move the robot to the gray square. The program uses the procedure Goal_Reached ( ), which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL (Goal_Reached()) { IF (CAN_MOVE (right__ { ROTATE_RIGHT() } ELSE { IF (CAN_MOVE(left)) { ROTATE_LEFT() } }IF (CAN_MOVE (forward)) { MOVE_FORWARD() } } For which of the grids does the program correctly move the robot to the gray square?

A. Grid 1 only

Assume that the Boolean variable x is assigned the value true and the Boolean variable y is assigned the value false. Which of the following will display the value true ? Select two answers.

A. IF (x) DISPLAY (x OR y) B. IF (x OR y) DISPLAY x

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. 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. NUMBER OF ITEMS - NUMBER OF STEPS 10 - 100 20 - 400 30 - 900 40 - 1600 50 - 2500 60 - 3600 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.

Consider the following code segment. first <- true second <- false second<-first first<-second What are the values of first and second as a result of executing the code segment?

A. The value of first is true, and the value of second is true.

In a certain video game, players are awarded bonus points at the end of a level based on the value of the integer variable timer. The bonus points are awarded as follows. -If timer is less than 30, then 500 bonus points are awarded. -If timer is between 30 and 60 inclusive, then 1000 bonus points are awarded. -If timer is greater than 60, then 1500 bonus points are awarded. Which of the following code segments assigns the correct number of bonus points to bonus for all possible values of timer ? Select two answers.

A. bonus <-500 IF timer >= 30 bonus <- bonus + 500 IF timer >60 bonus <- bonus + 500 D. IF timer > 60 bonus <- 1500 IF timer>=30 and timer <= 60 bonus <- 1000 IF timer < 30 bonus <- 500

Consider the following code segment. j<-1 REPEAT UNTIL <MISSING CONDITION> j<-j +2 Which of the following replacements for <MISSING CONDITION> will result in an infinite loop?

A. j=6

A list of numbers has n elements, indexed from 1 to n. The following algorithm is intended to display true if the value target appears in the list more than once and to display false otherwise. The algorithm uses the variables position and count. Steps 4 and 5 are missing. Step 1:Set count to 0 and position to 1. Step 2:If the value of the element at index position is equal totarget, increase the value of count by 1. Step 3:Increase the value of position by 1. Step 4:(missing step) Step 5:(missing step) Which of the following could be used to replace steps 4 and 5 so that the algorithm works as intended?

A. -Step 4 Repeat steps 2 and 3 until the value of position is greater than n. -Step 5If count is greater than or equal to 2, displaytrue. Otherwise, display false.

A code segment is intended to display the following output. up down down down up down down down Which of the following code segments can be used to display the intended output?

A. REPEAT 2 TIMES DISPLAY "up" REPEAT 3 TIMES Display "down"

The following algorithm is intended to determine the average height, in centimeters, of a group of people in a room. Each person has a card, a pencil, and an eraser. Step 2 of the algorithm is missing. Step 1: All people stand up. Step 2: (missing step) Step 3: Each standing person finds another standing person and they form a pair. If a person cannot find an unpaired standing person, that person remains standing and waits until the next opportunity to form pairs. Step 4: In each pair, one person hands their card to the other person and sits down. Step 5: At this point, the standing person in each pair is holding two cards. The standing person in each pair replaces the top number on their card with the sum of the top numbers on the two cards and replaces the bottom number on their card with the sum of the bottom numbers on the two cards. The sitting partner's card is discarded. Step 6: Repeat steps 3-5 until there is only one person standing. Step 7: The last person standing divides the top number by the bottom number to determine the average height. Which of the following can be used as step 2 so that the algorithm works as intended?

A. Step 2: Each person writes their height, in centimeters, at the top of the card and writes the number 1 at the bottom of the card.

A video-streaming Web site keeps count of the number of times each video has been played since it was first added to the site. The count is updated each time a video is played and is displayed next to each video to show its popularity. At one time, the count for the most popular video was about two million. Sometime later, the same video displayed a seven-digit negative number as its count, while the counts for the other videos displayed correctly. Which of the following is the most likely explanation for the error?

A. The count for the video became larger than the maximum value allowed by the data type used to store the count.

A homework assignment consists of 10 questions. The assignment is graded as follows. Number of Correct Answers- Grade 9-10 - check plus 7-8 - check Under 7 - check minus Let numCorrect represent the number of correct answers for a particular student. The following code segment is intended to display the appropriate grade based onnumCorrect. The code segment does not work as intended in all cases. IF numCorrect > 7 (IF numCorrect >=9 DISPLAY "check plus" ELSE DISPLAY "check minus") ELSE DISPLAY "check" For which of the following values of numCorrect does the code segment NOT display the intended grade? Select two answers.

B. 8 D. 6

The following procedure is intended to return the value of x times y, where x and y are integers. Multiplication is implemented using repeated additions. PROCEDURE Multiply x,y count<-0 result<-0 REPEAT UNTIL count >- y result<-result+x count<-count+1 RETURN result For which of the following procedure calls does the procedure NOT return the intended value? Select two answers.

B. Multiply 2, -5 D. Multiply -2, -5

In a science experiment, result X is expected to occur 25% of the time and result Y is expected to occur the remaining 75% of the time. The following code segment is intended to simulate the experiment if there are 100 trials. Line 1: xCount ← 0 Line 2: yCount ← 0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM(1, 4) = 1) Line 6: { Line 7: xCount ← xCount + 1 Line 8: } Line 9: IF(RANDOM(1, 4) > 1) Line 10: { Line 11: yCount ← yCount + 1 Line 12: } Line 13: } Line 14: DISPLAY("Result X occurred") Line 15: DISPLAY(xCount) Line 16: DISPLAY("times and result Y occurred") Line 17: DISPLAY(yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed. Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials. Which of the following changes to the code segment will ensure a correct simulation of the experiment?

B. Replacing line 9 with ELSE

A code segment will be used to swap the values of the variables a and b using the temporary variable temp. Which of the following code segments correctly swaps the values of a and b ?

B. temp<-a a<-b b<-temp

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. A student wrote the following code for a guessing game. Line 1: secretNumber<- RANDOM (1,100) Line 2: win<-false Line 3: REPEAT UNTIL (win) Line 4: { Line 5: DISPLAY ("Guess a number") Line 6: guess<- INPUT () Line 7: IF (guess = secretNumber) Line 8: { Line 9: DISPLAY ("You got it right") Line 10: } Line 11: ELSE Line 12: { Line 13: IF (guess> secretNumber) Line 14: { Line 15: DISPLAY ("Your guess is too high") Line 16: } Line 17: ELSE Line 18: { Line 19: DISPLAY ("Your guess is too low") Line 20: } Line 21: } Line 22: } While debugging the code, the student realizes that the loop never terminates. The student plans to insert the instruction WIN <- TRUE somewhere in the code. Where could WIN <- TRUE be inserted so that the code segment works as intended?

B. Between line 9 and line 10

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case.​ The program below is intended to count the number of prime numbers in a list called NUMBERS and display the result. The program uses the procedure isPrime (n), which returns true if n is a prime number and false otherwise. The program does not work as intended. Line 1: count<-0 Line 2: FOR EACH value IN numbers Line 3: { Line 4: count<- 0 Line 5: IF (isPrime(value)) Line 6: { Line 7: count <- count + 1 Line 8: } Line 9: count <- count +1 Line 10: } Line 11: DISPLAY (count) Which two lines of code should be removed so that the program will work as intended? Select two answers.

B. Line 4 D. Line 9

In the following procedure, the parameter age represents a person's age. The procedure is intended to return the name of the age group associated with age. People who are under 18 are considered minors, people who are 65 and older are considered senior citizens, and all other people are considered adults. The procedure does not work as intended. Line 1: PROCEDURE ageGroup(age) Line 2: { Line 3: result ← "adult" Line 4: IF(age ≥ 65) Line 5: { Line 6: result ← "senior citizen" Line 7: } Line 8: RETURN(result) Line 9: Line 10: result ← "adult" Line 11: IF(age < 18) Line 12: { Line 13: result ← "minor" Line 14: } Line 15: RETURN(result) Line 16: } Removing which two lines of code will cause the procedure to work as intended? Select two answers.

B. Line 8 C. Line 10

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 4 - 17 5 - 24 6 - 35 7 - 50 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 n^2 steps to draw n shapes.

A student is creating an application that allows customers to order food for delivery from a local restaurant. Which of the following is LEAST likely to be an input provided by a customer using the application?

B. The cost of a food item currently available for order

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. Which of the following are benefits of using well-named variables in a computer program? Select two answers.

B. The program will be easier for people to read. D. The program will be easier to modify in the future.

Directions: For the question or incomplete statement below, two of the suggested answers are correct. For this question, you must select both correct choices to earn credit. No partial credit will be earned if only one correct choice is selected. Select the two that are best in each case. A program is created to perform arithmetic operations on positive and negative integers. The program contains the following incorrect procedure, which is intended to return the product of the integers x and y. PROCEDURE Multiply (x,y) { count<-0 result<-0 REPEAT UNTIL (count = y) { result <- result + x count<- count + 1 } RETURN )result) } A programmer suspects that an error in the program is caused by this procedure. Under which of the following conditions will the procedure NOT return the correct product? Select two answers.

B. When the values of x is positive and the value of y is negative. D. When the values of x and y are both negative.

The variable age is to be used to represent a person's age, in years. Which of the following is the most appropriate data type for age ?

B. number

A mobile application is used to display local traffic conditions. Which of the following features of the application best exemplifies the use of crowdsourcing?

C. Users can submit updates on local traffic conditions in real time.

A small team of wildlife researchers is working on a project that uses motion-activated field cameras to capture images of animals at study sites. The team is considering using a "citizen science" approach to analyze the images. Which of the following best explains why such an approach is considered useful for this project?

D. The image analysis is likely to take a longer time for the research team than for a distributed group of individuals.

Consider the following code segment. num1 <- 6 num2 <- 4 num3 <- 10 IF num1 < num2 num1 <- num2 ELSE num3 <- num2 IF num2 >= num3 num1<- num2 + num3 sum<- num1 + num2 + num3 What is the value of sum after the code segment is executed?

C. 16

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. Process - Execution Time on Either Processor X - 60 seconds Y - 30 seconds Z - 50 seconds Which of the following best approximates the minimum possible time to execute all three processes when the two processors are run in parallel?

C. 80 seconds

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Which of the following would be the best use of citizen science?

C. An experiment that requires data measurements to be taken in many different locations

The procedure below is intended to display the index in a list of unique names (nameList) where a particular name (targetName) is found. If targetName is not found in nameList, the code should display 0. PROCEDURE FindName (nameList, targetName) { index<-0 FOR EACH name IN nameList { index<-index + 1 IF (name = targetName) { foundIndex<- index } ELSE { foundIndex<-0 } } DISPLAY (foundIndex) } Which of the following procedure calls can be used to demonstrate that the procedure does NOT work as intended?

C. FindName (["Andrea", "Ben", "Chris"], "Ben")

Three students in different locations are collaborating on the development of an application. Which of the following strategies is LEAST likely to facilitate collaboration among the students?

C. Having all three students write code independently and then having one student combine the code into a program

Assume that the list of numbers nums has more than 10 elements. The program below is intended to compute and display the sum of the first 10 elements of nums. Line 1: i ← 1 Line 2: sum ← 0 Line 3: REPEAT UNTIL (i > 10) Line 4: { Line 5: i ← i + 1 Line 6: sum ← sum + nums[i] Line 7: } Line 8: DISPLAY (sum) Which change, if any, is needed for the program to work as intended?

C. Lines 5 and 6 should be interchanged.

A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Line 1: PROCEDURE isIncreasing(numberList) Line 2: { Line 3: count ← 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: { Line 6: IF(numberList[count] < numberList[count - 1]) Line 7: { Line 8: RETURN(true) Line 9: } Line 10: count ← count + 1 Line 11: } Line 12: RETURN(false) Line 13: } Which of the following changes is needed for the program to work as intended?

C. Lines 8 and 12 should be interchanged.

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The code segment below is intended to display all multiples of 5 between the values and END, inclusive. For example, if START has the value 35 and END has the value 50, the code segment should display the values 35,40, 45, and 50. Assume that START and END are multiples of 5 and that START is less than END . Line 1: i<-- start Line 2: REPEAT <MISSING EXPRESSION>TIMES Line 3: { Line 4: DISPLAY (i) Line 5: i<-I+5 Line 6: } Which of the following could replace ,MISSING EXPRESSION> in line 2 so that the code segment works as intended?

C. ((end-start) / 5) + 1

Consider the following code segment, which uses the variables r, s, and t. r ← 1 s ← 2 t ← 3 r ← s s ← t DISPLAY (r) DISPLAY (s) What is displayed as a result of running the code segment?

C. 2 3

In the following procedure, the parameters x and y are integers. PROCEDURE calculate x,y result <- x + y result <- result/x DISPLAY result Which of the following is the most appropriate documentation to appear with the calculate procedure?

C. C Displays the value of (x + y) / x.The value of the parameter x must not be 0.

Which of the following is NOT a benefit of collaborating to develop a computing innovation?

C. Collaboration eliminates the need to resolve differences of opinion.

The cost of a customer's electricity bill is based on the number of units of electricity the customer uses. For the first 25 units of electricity, the cost is $5 per unit. For units of electricity after the first 25, the cost is $7 per unit. Which of the following code segments correctly sets the value of the variablecost to the cost, in dollars, of using numUnits units of electricity?

C. IF numUnits <_ 25 cost <-- numUnits * 5 ELSE cost <--25 * 5 + (numUnits -25) *7

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.

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

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

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. The ticket prices at a movie theater are given below. TYPE OF TICKET - PRICE Regular - 12 Child (ages 12 and below) - 9 Senior (ages 60 and above) - 9 ADDITIONAL 5 fee for 3-D Movies A programmer is creating an algorithm to set the value of ticketPrice based on the information in the table. The programmer uses the integer variable age for the age of the moviegoer. The Boolean variable is3D is true when the movie is 3-D and false otherwise. Which of the following code segments correctly sets the value of ticketPrice?

C. tickerPrice <-12 IF (ages <= 12) OR (age >=60) ticketPrice <-9 IF is3D ticketPrice <- ticketPrice + 5

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.

Consider the following code segment. result <-- 2 REPEAR 3 TIMES result<-- result * 5 DISPLAY result Which of the following best describes the behavior of the code segment?

D. The code segment displays the value of 2(5^3) by initializing result to2 and then multiplying result by 5 a total of three times.

The program segment below is intended to move a robot in a grid to a gray square. The program segment uses the procedure GoalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. The robot in each grid is represented as a triangle and is initially facing left. The robot can move into a white or gray square but cannot move into a black region. REPEAT UNTIL (GoalReached ()) { IF (CAN_MOVE (forward)) { MOVE_FORWAR () } IF (CAN_MOVE (right)) { ROTATE_RIGHT() } IF (CAN_MOVE (left)) { ROTATE_LEFT () } } For which of the following grids does the program NOT correctly move the robot to the gray square?

D. Eww bwb wwb wbb wwS

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?

D. I, II, and III

Consider the following program code. i<-0 sum<-0 RPEAT UNTIL i=4 i<-1 sum<-sum + i I<-i +1 DISPLAY sum Which of the following best describes the result of running the program code?

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

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Consider the following program. count<-1 sum<-- REPEAT 10 TIMES sum<-sum + count count<- count + 2 DISPLAY SUM Which of the following describes the result of executing the program?

D. The program displays the sum of the odd integers from 1 to 19.

Which of the following statements is true?

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

Consider the following code segment. a<-true b<-false c<-true REPEAT UNTIL (a AND b) c<- NOT c b <- c DISPLAY a DISPLAY b DISPLAY c What is displayed as a result of executing the code segment

D. true true true

Which of the following applications is most likely to benefit from the use of crowdsourcing?

D. An application that allows users to view descriptions and photographs of local landmarks

A programmer is creating an algorithm that will be used to turn on the motor to open the gate in a parking garage. The specifications for the algorithm are as follows. The gate should not open when the time is outside of business hours. The motor should not turn on unless the gate sensor is activated. The motor should not turn on if the gate is already open. Which of the following algorithms can be used to open the gate under the appropriate conditions?

D. Check if the time is during business hours. If it is, check if the gate sensor is activated. If it is, check if the gate is open. If it is not, turn on the motor.

Which of the following actions are generally helpful in program development? 1. Consulting potential users of the program to identify their concerns 11. Writing and testing small code segments before adding them to the program 111. Collaborating with other individuals when developing a large program

D. I, II, and III

In the following code segment, score and penalty are initially positive integers. The code segment is intended to reduce the value of score by penalty. However, if doing so would cause score to be negative, score should be assigned the value 0. For example, if score is 20 and penalty is 5, the code segment should set score to15.If score is 20 and penalty is 30, score should be set to 0. The code segment does not work as intended. Line 1: IF(score - penalty < 0) Line 2: { Line 3: score ← score - penalty Line 4: } Line 5: ELSE Line 6: { Line 7: score ← 0 Line 8: } Which of the following changes can be made so that the code segment works as intended?

D. Interchanging lines 3 and 7

Directions: The question or incomplete statement below is followed by four suggested answers or completions. Select the one that is best in each case. Which of the following best describes one of the benefits of using an iterative and incremental process of program development?

D. It helps programmers identify errors as components are added to a working program.

The following grid contains a robot represented as a triangle, which is initially facing toward the top of the grid. The robot can move into a white or gray square but cannot move into a black region. bbbwwwS bbbwbbb Ewwwbbb Which of the following code segments can be used to move the robot to the gray square?

D. REPEAT 3 TIMES { MOVE_FORWARD() } ROTATE_LEFT() REPEAT 2 TIMES { MOVE_FORWARD() } ROTATE_RIGHT() REPEAT 3 TIMES { MOVE_FORWARD() }

The algorithm below is used to simulate the results of flipping a coin 4 times. Consider the goal of determining whether the simulation resulted in an equal number of heads and tails. Step 1: Initialize the variables heads_counter and flip_counter to 0. Step 2: A variable coin_flip is randomly assigned a value of either 0 or 1. If coin_flip has the value 0, the coin flip result is heads, so heads_counter is incremented by 1. Step 3: Increment the value of flip_counter by 1. Step 4: Repeat steps 2 and 3 until flip_counter equals 4. Following execution of the algorithm, which of the following expressions indicates that the simulation resulted in an equal number of heads and tails?

D. heads_counter = 2


Kaugnay na mga set ng pag-aaral

Chapter 29: Management of Patients with Nonmalignant Hematologic Disorders

View Set

Knewton Alta Lesson 6 Assignment

View Set

Unfair, Deceptive, or Abusive Acts or Practices (UDAAP)

View Set

HESI Neurocognitive Disorder (Advanced Alzheimer's Disease)

View Set

Microbiology The Diversity of Prokaryotic Organisms

View Set

Chapter 8 Diagrams from test bank, CH.8 human a and p, Chapter 7 Diagrams from test bank, Anatomy Test 3

View Set

Physical Geology Chapter 12: Earth's Interior

View Set

L9/C3: Role of an Agent in a Real Estate Transaction/Dual Agency

View Set

Ch 3: Planning for Contingencies

View Set