apcsp: Unit 2 List Pt 2 - CB

Ace your homework & exams now with Quizwiz!

Assume that both lists and strings are indexed starting with index 1. The list wordList has the following contents. ["abc", "def", "ghi", "jkl"] Let myWord be the element at index 3 of wordList. Let myChar be the character at index 2 of myWord. What is the value of myChar ?

A. "e" B. "f" C. "h" --C is right-- D. "i"

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

A. -1 B. "hello" C. 2.5 D. 4 --D is right--

What is displayed as a result of executing the code segment? numlist = [100, 20, 300, 40, 500, 60] for each item IN numlist --> if (item => 90) ---> display (item)

A. 1 3 5 B. 5 3 1 C. 100 300 500 --C is right-- D. 500 300 100

What value is displayed as a result of executing the code segment? intlist = 4, 2, 5, 4, 2, 3, 1 result = 0 for each item in intlist --> result = result + (item mod 2) display (result)

A. 3 --A is right-- B. 4 C.9 D. 12

What is the value of RESULT after the code segment is executed? x = 0 result = 0 (repeat until (x > 5) result = result + x x = x + 1

A. 6 B. 10 C. 15 --C is right-- D. 21

The procedure below searches for the value in . It returns if is found and returns otherwise. procedure contains (list, target) for each element in list if element = target return (true) else return (false) Which of the following are true statements about the procedure? I. It implements a binary search. II. It implements a linear search. III. It only works as intended when list is sorted.

A. I only B. II only --B is right-- C. I and III D. II and III

Shoppers at a mall were asked whether they preferred wearing gloves or mittens in cold weather. Shoppers' preferences were stored in the list voteList as strings, with the string "Gloves" representing a preference for gloves and the string "Mittens" representing a preference for mittens. The following code segment is intended to traverse the list and display the number of shoppers who chose gloves and the number of shoppers who chose mittens. numGlovesVotes ← 0 numMittensVotes ← 0 <MISSING CODE> { IF(vote = "Gloves") { numGlovesVotes ← numGlovesVotes + 1 } ELSE { numMittensVotes ← numMittensVotes + 1 } } DISPLAY(numGlovesVotes) DISPLAY(" shoppers chose gloves and") DISPLAY(numMittensVotes) DISPLAY(" shoppers chose mittens.") Which of the following should replace <MISSING CODE> so that the code segment works as intended?

A. IF(vote ≤ LENGTH(voteList)) B. FOR EACH vote IN voteList --B is right-- C. REPEAT LENGTH(voteList) TIMES D. REPEAT UNTIL(vote > LENGTH(voteList))

Which of the following is a benefit of using a list as a data abstraction in a program?

A. Lists often allow their size to be easily updated to hold as many data values as needed. --A is right-- B. Lists convert all elements to strings so that they can be inspected character-by-character. C. Lists prevent duplicate data values from appearing in the list. D. Lists are used to store all input data so that there is a running record of all user input.

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 to target, 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 4Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to 2, display true. Otherwise, display false. --A is right-- B. Step 4Repeat steps 2 and 3 until the value of position is greater than n. Step 5 If count is greater than or equal to position, display true. Otherwise, display false. C. Step 4Repeat steps 2 and 3 until the value of count is greater than 2. Step 5 If position is greater than or equal to n, display true. Otherwise, display false. D. Step 4Repeat steps 2 and 3 until the value of count is greater than n. Step 5 If count is greater than or equal to 2, display true. Otherwise, display false.

Which of the following describes the result of executing the program? val = 0 sum = 0 (repeat 10 times) --> val = val + 2 --> sum = sum + val display (sum)

A. The program displays the sum of the even integers from 2 to 10. B. The program displays the sum of the even integers from 2 to 20. --B is right-- C. The program displays the sum of the odd integers from 1 to 9. D. The program displays the sum of the odd integers from 1 to 19.

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?

A. [ ] B. ["guitar", "drums", "bass"]--B is right-- C. ["flute", "violin"] D. ["flute", "violin", "guitar", "drums", "bass"]

Consider the following code segment. What are the contents of yourList after the code segment is executed? yourlist = 20, 40, 60, 80 mylist = 10, 30, 50, 70 yourlist = mylist

A. [10, 30, 50, 70] --A is right-- B. [20, 40, 60, 80] C. [10, 30, 50, 70, 20, 40, 60, 80] D. [20, 40, 60, 80, 10, 30, 50, 70]

Consider the following code segment. 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?

A. count1 = 2, count2 = 2 B. count1 = 2, count2 = 3m--B is right-- C. count1 = 3, count2 = 2 D. count1 = 5, count2 = 0

A summer camp offers a morning session and an afternoon session. The list morningList contains the names of all children attending the morning session, and the list afternoonList contains the names of all children attending the afternoon session. Only children who attend both sessions eat lunch at the camp. The camp director wants to create lunchList, which will contain the names of children attending both sessions. The following code segment is intended to create lunchList, which is initially empty. It uses the procedure IsFound (list, name), which returns true if name is found in list and returns false otherwise. for each child in morninglist <missing code> Which of the following could replace <MISSING CODE> so that the code segment works as intended?

A. if (isFound (afternoonlist, child)) { append (lunchlist, child) } --A is right-- B. if (isFound (lunchlist, child)) { append (afternoonlist, child) } C. if (isFound (morninglist, child)) { append (lunchlist, child) } D. if ((isFound (morninglist, child) or (isFound (afternoonlist, child))) { append (lunchlist, child) }

What is displayed as a result of executing the code segment? a = true b =false c = true repeat until (a and b) c = not c b = c display a display b display c

A. true false false B. true false true C. true true false D. true true true --D is right--


Related study sets

Dynamic questions/Fundies Book questions -BP/VS/Resp/ROS

View Set

Module 16 - Adulthood - Retrieval Practice & Review

View Set

Medical Terminology Chapter 11: Special Senses: The Eyes and Ears Learning Exercise

View Set

Key Ideas and Details Informational Text

View Set

Final Exam 476 (CHAPTER 3 RESEARCH)

View Set

Cybersecurity Quiz Sections 9.1.8, 9.2.7, 9.3.4, 9.4.6, 9.5.6, 9.6.7, 9.7.7, 9.8.7, 9.9.6

View Set