MC Corrections
All mc questions and answers for review
Q21: The following question uses a robot in a grid of squares. The robot is represented by a triangle, which is initially facing right. Consider the procedures below.Which of the following code segments will move the robot to the gray square?
A: Answer B This option is correct. This code segment moves the robot forward two squares, rotates it right three times so that the robot faces the top of the grid, and then moves the robot forward three squares to the gray square.
Q22: 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 true if the daily high temperature was at least 90 degrees for a majority of days in the month and return false otherwise. Which of the following can be used to replace missing code so that the procedure works as intended?
A: Answer B This option is correct. This Boolean expression evaluates to true when counter (the number of temperatures greater than or equal to 90) is greater than 50% of total (the number of entries in the list).
Q25: Byte pair encoding is a data encoding technique. The encoding algorithm looks for pairs of characters that appear in the string more than once and replaces each instance of that pair with a corresponding character that does not appear in the string. The algorithm saves a list containing the mapping of character pairs to their corresponding replacement characters. For example, the string Open quotation, THIS, underscore, IS, underscore, THE, underscore, BEST, underscore, WISH, close quotation can be encoded as Open quotation, percent, hash, underscore, hash, underscore, percent E, underscore, BEST, underscore, W, hash, H, close quotation by replacing all instances of Open quotation, T H, close quotation with Open quotation, percent, close quotationand replacing all instances of Open quotation, I S, close quotation with Open quotation, hash, close quotation. For which of the following strings is it NOT possible to use byte pair encoding to shorten the string’s length?
A: Answer B This option is correct. It is not possible to use byte pair encoding in the string Open quotation, LEVEL, underscore, UP, close quotationbecause no pair of characters appears in the string more than once.
Q26: The grid below contains a robot represented as a triangle, initially facing up. The robot can move into a white or gray square but cannot move into a black region. The code segment below uses the procedure One word, Goal Reached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. Which of the following replacements for missing code can be used to move the robot to the gray square?
A: Answer D This option is incorrect. This code segment moves the robot one square forward from its initial location and then rotates the robot right. From there, the robot cannot move forward and the body of the IF statement is never executed again.
Q30: 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 Analysis, open parenthesis, category, close parenthesis , which returns the number of unique users who viewed videos of a given category in the past year. The Analysis 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: Answer D This option is correct. Each call to the Analysis procedure requires one hour of program execution time. The procedure is called once before the loop, and then four times inside the loop (once for each of the four entries in One word, genre List). Therefore, the program will take approximately 5 hours to execute.
Q31: 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 One word, Goal Reached, which returns true if the robot is in the gray square and returns false otherwise. Which of the following statements is true?
A: Answer C This option is correct. Program I correctly moves the robot to the gray square by repeatedly moving the robot forward, rotating left, moving forward, and rotating right. Program II correctly moves the robot to the gray square by moving the robot forward to the upper-right corner of the grid, rotating left, and moving forward to the upper-left corner of the grid.
Q33: A flowchart is a way to visually represent an algorithm. The flowchart below is used by an apartment rental Web site to set the variable include to true for apartments that meet certain criteria. Which of the following statements is equivalent to the algorithm in the flowchart?
A: Answer A This option is correct. The flowchart sets include to true whenever floor is greater than 1 0 or bedrooms equal 3, and sets include to false otherwise. Therefore, the algorithm is equivalent to Include, left arrow, open parenthesis, floor greater than 10, close parenthesis, OR, open parenthesis, bedrooms equal 3, close parenthesis.
Q43: 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: Answer A This option is correct. The pattern in the table appears to indicate that there are n squared steps for a list containing n items. This number of steps is a polynomial and therefore the algorithm runs in reasonable time.
Q48: In a certain science experiment, 7 5 percent of trials are expected to be successful and 2 5 percent of trials are expected to be unsuccessful. The program below is intended to simulate the results of repeated trials of the experiment. Which of the following can be used to replace missing code so that the simulation works as intended?
A: Answer D This option is correct. This option causes the experiment to be successful when RANDOM, open parenthesis 1 comma 100, close parenthesis produces a result from 1 to 7 5, or 75% of the time.
Q52: A programmer is developing a word game. The programmer wants to create an algorithm that will take a list of words and return a list containing the first letter of all words that are palindromes (words that read the same backward or forward). The returned list should be in alphabetical order. For example, if the list contains the words Open bracket, open quotation, banana, close quotation, open quotation, kayak, close quotation, open quotation, mom, close quotation, open quotation, apple, close quotation, open quotation, level, close quotation, close bracket, the returned list would contain Open bracket, open quotation, k, close quotation, open quotation, l, close quotation, open quotation, m, close quotation, close bracket(because Open quotation, kayak, close quotation, Open quotation, level, close quotation, and Open quotation, mom, close quotationare palindromes). The programmer knows that the following steps are necessary for the algorithm but is not sure in which order they should be executed. Executing which of the following sequences of steps will enable the algorithm to work as intended? I. First shorten, then keep palindromes, then sort II. First keep palindromes, then shorten, then sort III. First sort, then keep palindromes, then shorten
A: Answer D This option is correct. Options II and III perform the steps in a correct order. In order to generate the desired list, the algorithm must perform the “shorten” step after the “keep palindromes” step, otherwise the “keep palindromes” step would not be able to determine whether the original word was a palindrome.