The following procedures are available for string manipulation.
Procedure
CallExplanationsubstring(str, start, end)Returns a substring of consecutive characters of str starting with the character at position start and ending with the character at position end. The first character of str is considered position 1. For example, substring("delivery", 3, 6) returns "live".concat(str1, str2)Returns a single string consisting of str1
followed by str2. For example, concat("key", "board") returns "keyboard".len(str)Returns the number of characters in str. For example, len("key") returns 3.
A programmer wants to create a new string by removing the character in position n of the string oldStr. For example, if oldStr is "best" and n is 3, then the new string should be "bet". Assume that 1 < n < len(oldStr).
Which of the following code segments can be used to create the desired new string and store it in newStr
?
Select TWO answers.
A
left ←\leftarrow← substring (oldStr, 1, n - 1)
right ←\leftarrow← substring (oldStr, n + 1, len(oldStr))
newStr ←\leftarrow← concat (left, right)
B
left ←\leftarrow← substring (oldStr, 1, n + 1)
right ←\leftarrow← substring (oldStr, n - 1, len(oldStr))
newStr ←\leftarrow← concat (left, right)
C
newStr ←\leftarrow← substring (oldStr, 1, n - 1)
newStr ←\leftarrow← concat (newStr, substring (oldStr, n + 1, len (oldStr)))
D
newStr
←\leftarrow← substring (oldStr, n + 1, len (oldStr))
newStr ←\leftarrow← concat (newStr, substring (oldStr, 1, n - 1))
A
left ←\leftarrow← substring (oldStr, 1, n - 1)
right ←\leftarrow← substring (oldStr, n + 1, len(oldStr))
newStr ←\leftarrow← concat (left, right)
C
newStr ←\leftarrow← substring (oldStr, 1, n - 1)
newStr ←\leftarrow← concat (newStr, substring (oldStr, n + 1, len (oldStr)))
The following code segment is intended to remove all duplicate elements in the list myList. The procedure does not work as intended.
j \leftarrow← LENGTH (myList)
REPEAT UNTIL (j = 1)
{
IF (myList [j] = myList [j - 1])
{
REMOVE (myList, j)
}
j j - 1
}
For which of the following contents of myList will the procedure NOT produce the intended results?
Select TWO answers.
A
[10, 10, 20, 20, 10, 10]
B
[30, 30, 30, 10, 20, 20]
C
[30, 50,
40, 10, 20, 40]
D
[50, 50, 50, 50, 50, 50]
A
[10, 10, 20, 20, 10, 10]
C
[30, 50, 40, 10, 20, 40]
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?
A
len ←\leftarrow← LENGTH (utensils)
temp ←\leftarrow← utensils [len]
REMOVE (utensils, len)
APPEND (utensils, temp)
B
len ←\leftarrow← LENGTH (utensils)
REMOVE (utensils, len)
temp ←\leftarrow← utensils [len]
APPEND (utensils, temp)
C
len ←\leftarrow← LENGTH (utensils)
temp ←\leftarrow← utensils [len]
REMOVE (utensils, len)
INSERT
(utensils, 1, temp)
D
len ←\leftarrow← LENGTH (utensils)
REMOVE (utensils, len)
temp ←\leftarrow← utensils [len]
INSERT (utensils, 1, temp)
A large spreadsheet contains the following information about local restaurants. A sample portion of the spreadsheet is shown below.
ARestaurant Name
BPrice Range
CNumber of Customer Ratings
DAverage Customer Rating
EAccepts Credit Cards
1
Joey Calzone's
Pizzeria
lo
182
3.5
false
2
78th Street Bistro
med
41
4.5
false
3
Seaside Taqueria
med
214
4.5
true
4
Delicious Sub Shop II
lo
202
4.0
false
5
Rustic Farm Tavern
hi
116
4.5
true
6
ABC Downtown Diner
med
0
-1.0
true
In column B, the price range represents the typical cost of a meal, where "lo" indicates under $10, "med" indicates $11 to $30, and "hi" indicates over $30.
In column D, the
average customer rating is set to -1.0 for restaurants that have no customer ratings.
A student is developing an algorithm to determine which of the restaurants that accept credit cards has the greatest average customer rating. Restaurants that have not yet received any customer ratings and restaurants that do not accept credit card are to be ignored.
Once the algorithm is complete, the desired restaurant will appear in the first row of the spreadsheet. If there are multiple entries that fit the desired criteria, it does not matter which of them appears in the first row.
The student has the following actions available but is not sure of the order in which they should be executed.
Action
Explanation
Filter by number of ratings
Remove entries for restaurants with no customer ratings
Filter by payment type
Remove entries for restaurants that do not accept credit cards
Sort by rating
Sort the rows in the spreadsheet on column D from greatest to
least
Assume that applying either of the filters will not change the relative order of the rows remaining in the spreadsheet.
Which of the following sequences of steps can be used to identify the desired restaurant?
Filter by number of ratings, then filter by payment type, then sort by rating
Filter by number of ratings, then sort by rating, then filter by payment type
Sort by rating, then filter by number of ratings, then filter by payment type
A
1 and 2 only
B
1
and 3 only
C
2 and 3 only
D
1, 2, and 3