Computer Science

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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.

Consider the following code segment. firstList ←← ["guitar", "drums", "bass"] secondList ←← ["flute", "violin"] thirdList ←← [] thirdList ←← firstList firstList ←← secondList secondList ←← thirdList What are the contents of secondList after the code segment is executed?

["guitar", "drums", "bass"]

Consider the following procedures. PROCEDURE proc1(str) { DISPLAY(str) DISPLAY("happy") } PROCEDURE proc2(str1, str2) { proc1(str2) DISPLAY(str1) } What is displayed as a result of the procedure call proc2("birthday", "to you") ?

to you happy birthday

Consider the following code segment. x ←← 25 y ←← 50 z ←← 75 x ←← y y ←← z z ←← x Which of the variables have the value 50 after executing the code segment?

x and z only

Which of the following Boolean expressions are equivalent to the expression num=>15?

(num>15) or (num=15)

A store uses binary numbers to assign a unique binary sequence to each item in its inventory. What is the minimum number of bits required for each binary sequence if the store has between 75 and 100 items in its inventory?

7

An office uses an application to assign work to its staff members. The application uses a binary sequence to represent each of 100 staff members. What is the minimum number of bits needed to assign a unique bit sequence to each staff member?

7

A programmer notices the following two procedures in a library. The procedures do similar, but not identical, things. Procedure returns the value . Procedure returns the value . Which of the following procedures is a generalization of the procedures described above?

Procedure , which returns the value

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.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 of diff and display the result.

Let n be an integer value. Which of the following expressions evaluates to true if and only if n is a two-digit integer (i.e., in the range from 10 to 99, inclusive)?

(n < 10) AND (n ≥ 100)

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 Boolean expressions are equivalent to the expression ? Select two answers.

(num > 15) and (num=15)

The code fragment below is intended to display "odd" if the positive number num is odd. Which of the following can be used to replace <MISSING CONDITION> so that the code fragment will work as intended?

(num MOD 2) = 1

In the following procedure, the parameter str is a string and the parameter num is a number. PROCEDURE printArgs(str, num) { DISPLAY(num) DISPLAY(str) DISPLAY(num) } Consider the following code segment. printArgs("**", 1) printArgs("*", 2) What is displayed as a result of executing the code segment?

1 ** 1 2 * 2

An online store uses 6-bit binary sequences to identify each unique item for sale. The store plans to increase the number of items it sells and is considering using 7-bit binary sequences. Which of the following best describes the result of using 7-bit sequences instead of 6-bit sequences?

2 times as many items can be uniquely identified.

The list wordList contains a list of 10 string values. Which of the following is a valid index for the list?

4

Consider the following code segment. result ←← 1 IF(score1 > 500) { result ←← result + 1 IF(score2 > 500) { result ←← result + 1 } ELSE { result ←← result + 2 } } ELSE { result ←← result + 5 IF(score2 > 500) { result ←← result + 1 } ELSE { result ←← result - 1 } } If the value of score1 is 350 and the value of score2 is 210, what will be the value of result after the code segment is executed?

5

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?

8

A teacher is writing a code segment that will use variables to represent a student's name and whether or not the student is currently absent. Which of the following variables are most appropriate for the code segment?

A string variable named studentName and a Boolean variable named isAbsent

Consider the following code segment, which is intended to store ten consecutive even integers, beginning with 2, in the list evenList. Assume that evenList is initially empty. i ←← 1 REPEAT 10 TIMES { <MISSING CODE> } Which of the following can be used to replace <MISSING CODE> so that the code segment works as intended? A APPEND(evenList, i)

APPEND(evenList, 2 * i) i ←← i + 1

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?

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

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]

I, II, and III

Which of the following can be represented by a sequence of bits? An integer An alphanumeric character A machine language instruction

I, II, and III

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.

Line 3and Line 10

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?

Lines 5 and 6 should be interchanged.

The following procedure is intended to return the number of times the value val appears in the list myList. The procedure does not work as intended. Line 01: PROCEDURE countNumOccurences(myList, val) Line 02: { Line 03: FOR EACH item IN myList Line 04: { Line 05: count ←← 0 Line 06: IF(item = val) Line 07: { Line 08: count ←← count + 1 Line 09: } Line 10: } Line 11: RETURN(count) Line 12: } Which of the following changes can be made so that the procedure will work as intended?

Moving the statement in line 5 so that it appears between lines 2 and 3

A computer program contains code in several places that asks a user to enter an integer within a specified range of values. The code repeats the input request if the value that the user enters is not within the specified range. A programmer would like to create a procedure that will generalize this functionality and can be used throughout the program. The correct use of the procedure is shown below, where min is the least acceptable value, max is the greatest acceptable value, and promptString is the string that should be printed to prompt the user enter a value. inputVal ←← getRange(min, max, promptString) Which of the following is a correct implementation of the getRange procedure?

PROCEDURE getRange(min, max, promptString) { DISPLAY(promptString) x ←← INPUT() REPEAT UNTIL(x ≥ min AND x ≤ max) { DISPLAY(promptString) x ←← INPUT() } RETURN(x) }

In a certain science experiment, percent of trials are expected to be successful and 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 so that the simulation works as intended?

RANDOM (1,100) <= 75

Which of the following are benefits of using well-named variables in a computer program?

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

theList ←← [-2, -1, 0, 1, 2] count1 ←← 0 count2 ←← 0 FOR EACH value IN theList { IF(value > 0) { count1 ←← count1 + 1 } ELSE { count2 ←← count2 + 1 } } What are the values of count1 and count2 as a result of executing the code segment?

count1 = 2, count2 = 3

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?

counter > 0.5 * total

A code segment is intended to transform the list utensils so that the last element of the list is moved to the beginning of the list. For example, if utensils initially contains ["fork", "spoon", "tongs", "spatula", "whisk"], it should contain ["whisk", "fork", "spoon", "tongs", "spatula"] after executing the code segment. Which of the following code segments transforms the list as intended?

len ←← LENGTH(utensils) temp ←← utensils[len] REMOVE(utensils, len) INSERT(utensils, 1, temp)


Ensembles d'études connexes

Chapter 47: Caring for Clients with Disorders of the Liver, Gallbladder, or Pancreas

View Set

Chapter 62: Caring for Clients with Traumatic Musculoskeletal Injuries

View Set

Microeconomics Chapter 24: Monopoly

View Set

PEDs Chapt 4 Growth and Development of the Toddler

View Set

Abnormal Psychology Pract. Ch. 16

View Set

Chapter 5: Cultural Diversity PrepU

View Set

Corporate Finance Study Session 8 p2?

View Set