Font size
WorksheetsUnit 4 Written Assessment
Total questions: 10
Worksheet time: 19mins
32 teams qualified for the 2018 World Cup. If the names of the teams were arranged in sorted order in a list, how many items would a binary search have to examine to locate a particular team in the worst case?
At most, 1 team
At most, 32 teams
At most, 16 teams
At most, 6 teams
What is the best way to search for an item in the following list: [6, 2, 1, 0, 3, 19, 201, 33, 17]?
A linear search, because linear searches are most effective on sorted lists.
A binary search, because binary searches work best on sorted lists.
A linear search, because a linear search can be used on any list.
A binary search, because binary searches can be used on any list
Consider the lists:
I. list1 ← [2, 4, 5, 7, 11, 33]
II. list2 ← [-2, -1, 0, 1, 2, 3, 4, 5, ..., 900, 901, 902]
III. list3 ← [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 0]
For which of these lists would a binary search be more efficient than a linear search? Select all that apply.
List 1
List 2
List 3
None
Consider the following natural language algorithm:
1. Look at the middle card in your deck.
2. If correct, done—you have found what you are searching for.
3. If you are looking for a larger number, discard the lower half of the deck.
4. Else, discard the upper half of the deck.
5. Return to step 1.
This algorithm is an example of a (a) search. The deck must be (b) first.
What is the final value reported by this code segment?
-3.2
-0.1
-1
0.0
What are the primary programming structures of this code segment? Select all that apply.
Sequencing
Selection
Iteration
Abstraction
Explain how to complete the countPositiveValues procedure so that the computer will iterate through a list (like listZ) and return the total quantity of non‑negative numbers stored in the list. Do not use a for each loop in your solution.
Assume that you wrote a correct algorithm to search listZ for the target value −1.75 and return its location, or return false if it is not present. Explain the worst‑case scenario and clarify how many items would be evaluated before the algorithm returns false. Your explanation should include a clear definition of worst‑case scenario, not just a numeric value.
Select the correct method(s) for swapping the first two items in the list so that the words are arranged alphabetically. Select all that apply. The initial list is listZ ← [First, Finally, Second], and the goal is listZ ← [Finally, First, Second].
temp ← listZ[2]
listZ[2] ← listZ[1]
listZ[1] ← temp
listZ[2] ← listZ[1]
listZ[1] ← listZ[2]
temp ← listZ[1]
listZ[1] ← listZ[2]
listZ[2] ← temp
listZ[2] ← listZ[1]
listZ[1] ← temp
temp ← listZ[2]
Evaluate the list and code segment and determine the final values stored in the list after execution. Note: −1 MOD 2 = 1. The initial listY is [2, −1, −1, 1, −2, 2, −2, −2]. The code initializes i ← 1 and repeats until i > length of listY: if item i of listY mod 2 = 1 then delete item i of listY; then change i by 1. Which final list results?
2, −1, −2, −2, −2
2, −2, 2, −2, −2
2, −1, −2, 2, −2, −2
2, −1, −1, 1, −2, 2, −2, −2
