Big Ideas 1 & 2 Flashcards

:,D (45 cards)

1
Q

Which of the following best describes the behavior of the code segment?

result <- 2
{
repeat 3 times
{result <- result *5}
}
Display result

A

The code segment displays the vale of 2(5^3) by intializing results to 2 and then multiplying result 5 by a total of three times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Assume that the parameter x is an integer.

procedure mystery [x]
y <- [x < 0]
{
if y
display [y]
}

A

It displays true if x is negative and displays nothing otherwise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which of the folloiwng best describes one of the benefits of using an iterative and incremental process of program development?

A

It helps programmers identify errors as components are added to a working program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which of the following actions are generally helpful in program development?

i. Consulting potential users of the program to identify their concerns

ii. Writing and testing small code segments before adding them to the program.

iii. Collaborating with other individuals when developing a large program

A

i, ii, and iii

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Central High School keeps a database of information about each student, including the numeric variabels numberOfAbsences and gradePointAverage. The expression below is used to determine whether a student is eligible to receive an academic award.

(numberofAbsences </= 5) AND (gradePointAverage > 3.5)

Which of the following pairs of values indicates that a student is eligible to receive an academic award?

A

numberOfAbsences = 5, gradePointAverage = 3.8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Assume that the list originalList contains integer values and that the list newList is initially empty. The following code segment is intended to copy all even numbers from originalList to newList so that the numbers in newList appear in the same relative order as in originalList. the code segment may or may not work as intended.

Line 1: FOR EACH number IN originalList
Line 2: {
Line 3: IF (number MOD 2 = 0)
Line 4: {
Line 5: INSERT (newList, 1, number)
Line 6: }
Line 7: }

Which of the following changes, if any, can be made so that the code segment works as intended?

A

Changing lline 5 to APPEND (newList, number)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A program is created to perform arithmetic operations on positive and negative integers. The program contains the following incorrect procedure, which is intended to return the product of the integers x and y.

PROCEDURE Multiply (x,y)
{count <- 0
result <- 0
REPEAT UNTIL (count = y)
{
result <- result + x
count <- count + 1
}
RETURN (result)
}

A programmers suspects that an error in the program is caused by this procedure.

Under which of the following condtions will procedure NOT return the correct product?

TWO ANSWERS

A

b. When the values of x is positive and the value of y is negative.

d. When the values of x and y are both negative.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

DineOutHelper is a mobile application that people can use to select a restaurant for a group meal. Each user creates a profile with a uique username and a list of food allergies or dietary restrictions. Each user can then build a contact list of other users of the app.

Which of the following data are needed for DineOutHelper to recommend a restaurant for the group?

i. Each group member’s list of food allergies or dietary restrictions.

ii. Alejandra’s geographic locations

iii. The usernames of the people on Brandon and Cynthia’s contact lists.

A

I and II only (list of food restrictions and Alejandra’s geographic locations)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following data is not provided by Alejandra but is necessary for DineOutHelper to recommend a restaurant for the group?

i. Brandon’s contact list

ii. Info about which restaurants Brandon and Cynthia have visited in the past

iii. Info about which food allergies and dietary restrictions can be accommodated at different restaurants near Alejandra

A

III only

(info about which food allergies and dietary restrictions can be accomodated at different restaurants near Alejandra)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the folloiwng data must be collected from a user’s smartphone in order for RunRoutr to suggest a running route?

A

The user’s geographic location

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Adriana uses RunRoutr to suggest a running route. All compatible users near Adriana receive a notification that shows her running route. Which of the following data is not obtained using data collected from Adrianna’s smartphone but necessary for RunRoutr to share Adrianna’s running route?

A

The current locations of other RunRoutr users.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

sum <- numList [1]
FOR EACH value IN numList
[sum <- sum + value]
DISPLAY [sum]

In order to test the program, the programmer initializes numList to [0,1,4,5]. The program displays 10, and the programmer concludes that the program works as intended.

Which of the following is true?

A

The conclusion is incorrect; using the test case [0,1,4,5] is not sufficient to conclude the program is correct.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

OG system: “start -> customers hears prerecorded message w/ answers to common questions -> customer hears list of departments and selects one using a phone keypad…”

The upgraded system uses a directory containing additional information not supplied by the customer. The directory is used to help direct calls effectively. Which of the following is LEAST likely to be included in the directory.

A

A list of computers the company owns and the computers’ corresponding IP addresses

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Og system: “start -> customers hears prerecorded message w/ answers to common questions -> customer hears list of departments and selects one using a phone keypad…”

To direct a call to the appropriate destination, which of the following input data is needed by the upgraded system that was NOT needed by the original system?

i. Audio signal of the customer’s voice

ii. The customer’s keypad selection

iii. The customer’s phone number

A

i only (audio signal of the customer’s voice)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

PROCEDURE printNums(max)
{
count <-1
REPEAT UNTIL (count > max)
{ DISPLAY (count)
count <- count + 2
}
}

Which of the following is the most appropriate documentation to appear with the printNums procedure?

A

B. Prints all positive odd integers that are less than or equal to max.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

PROCEDURE calculate [x,y]
result <- x + y
result <- result/x
DISPLAY result

A

C. Displays the value of (x+y)/x; the value of the parameter x must not be 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

PROCUEDURE swapListElements (numList, j, k)
{
newList <- numList
newL [j] <-numList[k]
newList [k] <- numList[j]
RETURN (newList)
}

Which of the following is the msot appropriate documentation to appear with the swapListElements procedure?

A

B. Returns a copy of numList with the elements at indices j and k interchanged.

The values of j and k must both be between 1 and Length(numList), inclusive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

A local router is configured to limit the bandwidth of guest users connecting to the Internet.

Which of the following best explains the result of this configuration as compared to a configuration in which the router does not limit the bandwidth?

A

D. Guest users will be restricted in the maximum amount of data that they can send and receive per second.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

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: }

A

B. Line 8
C. Line 10

20
Q

PROCEDURE AnyPairs (x, y, z)

{

IF (x = y)

{

RETURN (true)

}

ELSE

{

RETURN (y = z)

}

}

For which of the following procedure calls does the procedure NOT return the intended value?

A

C. AnyPairs (“bat”, “cat”, “bat”)

21
Q

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)

A

C. Line 5 and 6 should be interchanged.

22
Q

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: }

A

C. Moving the statement in line 5 (count <- 0) so that it appears between lines 2 (empty) and 3(FOR EACH item in myList).

23
Q

Line 1: PROCEDURE isIncreasing(numberList)

Line 2: {

Line 3: count <- 2

Line 4: REPEAT UNTIL(count > LENGTH(numberList))

Line 5: {

Line 6: IF(numberList[count] < numberList[count - 1])

Line 7: {

Line 8: RETURN(true)

Line 9: }

Line 10: count <- count + 1

Line 11: }

Line 12: RETURN(false)

Line 13: }

A

Lines 8 and 12 should be interchanged

24
Q

Line 1: currentNum <-start

Line 2: count <-0

Line 3: REPEAT UNTIL (currentNum > end)

Line 4: {

Line 5: count <-count + 1

Line 6: IF (IsPerfect (currentNum))

Line 7: {

Line 8: count <-count + 1

Line 9: currentNum <-currentNum + 1

Line 10: }

Line 11: currentNum <-currentNum + 1

Line 12: }

Line 13: DISPLAY (count)

Which two lines of code should be removed so that the program will work as intended? (Select 2 answers)

A

A. Line 5

C. Line 9

25
PROCEDURE NumOccurence [wordList, targetWord] count <-0 FOR EACH word IN wordList count <- 0 IF word = targetWord count <- count 1 RETURN count For which of the following code segments will the call to NonOccurrences NOT return the intended value? (Select 2 answers)
A. treeList <- birch, maple, birch numOccurences treeList, birch B. treeList <- birch, maple, oak numOccurences treeList, maple
26
Line 1: IF(score - penalty < 0) Line 2: { Line 3: score <- score - penalty Line 4: } Line 5: ELSE Line 6: { Line 7: score <- 0 Line 8: }
D. Interchanging lines 3 (score <- score -penalty) and 7 (score <-0)
27
Line 1: xCount <-0 Line 2: yCount <-0 Line 3: REPEAT 100 TIMES Line 4: { Line 5: IF(RANDOM(1, 4) = 1) Line 6: { Line 7: xCount <-xCount + 1 Line 8: } Line 9: IF(RANDOM(1, 4) > 1) Line 10: { Line 11: yCount <-yCount + 1 Line 12: } Line 13: } Line 14: DISPLAY("Result X occurred") Line 15: DISPLAY(xCount) Line 16: DISPLAY("times and result Y occurred") Line 17: DISPLAY(yCount) Line 18: DISPLAY("times.") A programmer runs the code segment, and the following message is displayed: Result X occurred 24 times and result Y occurred 70 times. The result shows that 94 trials were counted, rather than the intended 100 trials.
B. Replacing line 9 (IF (RANDOM(1,4) > 1) with ELSE
28
PROCEDURE Multiply [x,y] count <- 0 result <- 0 REPEAT UNTIL count >= y result <- result + x count <- count + 1 RETURN result For which of the following procedure calls does the procedure NOT return the intended value? (Select 2 answers)
B. Multiply [2, - 5] D. Multiply [-2, -5]
29
While debugging the code, the student realizes that the loop never terMINAtes. The student plans to insert the instruction win<- true somewhere in the code. Where could win <- true be inserted so that the code segment works as intended?
B. Between line 9 (DISPLAY (You got it right!)) and line 10 ("}")
30
Line 1: index <- LENGTH (wordList) Line 2: REPEAT UNTIL (index < 1) Line 3: { Line 4: IF ((wordList[index] = "the") OR (wordList[index] = "a")) Line 5: { Line 6: REMOVE (wordList, index) Line 7: } Line 8: } While debugging the program, the student realizes that the loop never terMINAtes. Which of the following changes can be made so that the program works as intended?
D. Inserting index <- index -1 between lines 7 ("}") and line 8 ("}")
31
The code segment compares pairs of list elements, setting containsDuplicate to true if any two elements are found to be equal in value. Which of the following best describes the behavior of how pairs of elements are compared?
B. The code segment iterates through myList, comparing each element to all SUBSEQUENT elements in the list.
32
A student is creating an application that allows customers to order food for delivery from a local restaurant. Which of the following is LEAST likely to be an input provided by a customer using the application?
B. The cost of a food item currently available for order. ## Footnote While the cost of food item available for order is needed, this information isprovided by the restaurant, not by the customer.
33
If (x> y) AND (x>z) max <- x If (y>x) AND (y>z) [max <- y] ELSE [max <- z] Which of the following (Wotf) intials values for x, y, and z can be used to show that the code segment does not work as intended?
D. x = 3, y = 2, z = 1
34
35
*inflateable man bending forward. feet are gray. arm outstretched to the ground has the black triangle* The code segment below uses the procedure goalReached, which evaluates to true if the robot is in the gray square and evaluates to false otherwise. REPEAT UNTIL (goalReached()) { } Which of the following replacements for can be used to move the robot to the gray square?
C. If (CAN_MOVE(left) { ROTATE_LEFT() } MOVE_FORWARD()
36
A student is developing an algorithm to determine the name of the photographer who took the oldest photograph in the collection (desired entry). Photographs whose photographer or year are unknown are to be ignored. Wotf will get the desired entry?
B. Filter by photographer, then filter by year, then sort by year D. Sort by year, then filter by year, then filter by photographer ## Footnote B. photographer, filter year, sort year D. sort year, filter year, photographer
37
students wants to count the number of shows that meet both of the following criteria. Is a talk show. Is on Saturday or Sunday. For a given row in the spreadsheet, suppose **genre** contains the genre as a string and **day** contains the day as a string. Which of the following expressions will evaluate to *true* if the show should be counted and evaluates to *false* otherwise?
**B.** (genre = talk) *AND* ((day = Saturday) OR (day = Sunday)) ## Footnote **Answer for B** For a show to be counted, the value of genere must be talk and the value of day must be Saturday or Sunday
38
A hw assignment consists of 10 questions. The assignment is graded as follows. IF numCorrect > 7 { IF numCorrect >=9 { DISPLAY [check plus] ELSE {DISPLAY [check minus] } ELSE { DISPLAY [check] } For which of the following values of numCorrect does the code segment NOT display the intended grades? (Select 2 answers)
B. 8 D. 6 ## Footnote **Answer B: ** When numCorrect is 8, the condition numCorrect > 7 evaluates to true and the condition numCorrect ≥ 9 evaluates to false. Therefore "check minus" is displayed instead of the intended "check plus". **Answer D:** When numCorrect is 6, the condition numCorrect > 7 evaluates to false. Therefore "check" is displayed instead of the intended "check minus".
39
PROCEDURE Smallest (numbers) { min <- numbers [1] FOR EACH number IN numbers { IF (number < min) { RETURN (number) } } RETURN (min) } For which of the folloiwng values of **theList** will **Smallest** (theList) NOT return the intended value? (Select 2 answers)
C. theList <- [30, 40, 20,10] D. the List <- [40, 30, 20, 10] ## Footnote **Answer C:** The procedure returns the first number it encounters that is less than the first number in the list. For the list [30, 40, 20, 10], the procedure reutrns 20, which is not hte least value in the list . **Answer D: ** The procedure returns the first number it encounters that is less than the first number in the list. For the list [40, 30, 20, 10], the procedure returns 30, which is not the least value in the list.
40
Wotf is a true statement about program documentation?
D. Program documentation is useful during initial program development and also when modificaitons are made to existing programs. ## Footnote **Answer D:** During initial program development, documentation can allow the writier to organize his or her thinking, state assumptions about input, and explain the path of future development. When modifications are made to existing programs, documentation is used to record the changes or additions to an existing program.
41
PROCEDURE **allPositive**(myList) { index <-1 len <-LENGTH(myList) REPEAT len TIMES { IF(myList[index] > 0) { RETURN(true) } index <- index + 1 } RETURN(false) } For wotf contents of myList does the procedure NOT return the intended result?
C. [-1, 0, 1] ## Footnote **Answer C: ** [-1,0,1] The procedure traverses this list and eventually ecnounters the positive value 1. At this point, the procedure returns true when it should return false because the list does not contain only positive values.
42
Two grids are shown below. Each grid contains a robot represented as a triangle. Both robots are initially facing left. Each robot can move into a white or gray square, but cannot move into a black region. which program correctly moves the robot to the gray sq?
A. Grid i only ## Footnote **Answer A:** Grid 1 only In Grid i, the robot moves forward to the end of the bottom row, turn right twice, moves forward twice, turns right twice, moves forward until the end of the middle row, turns left twice, moves forward twice, turns left twice, and moves forward until **Goal_Reached** is true.
43
The preserve has 2 databases of info available to use for the exhibit. The first database contains info for each animal's name, classification, skin type, and thermoregulation. The second database contains info for each animal's name, lifestyle, average life span, and top speed. Wotf explains how the 2 databases can be used to develop the interactive exhibit?
C. Both databases are needed. Each database can be searched by animal name to find all info to be displayed. ## Footnote **Answer C: ** Both databases. The info to be displayed comes from bot databases. The animal name can be used search the first database to find the classification, skin type, and thermoregulation info. The naimal name can be used search the second database to find the lifestyle, average life span, and top speed info.
44
The program below is intended to count the number of prime numbers in a list called numbers and display the result. The program uses the procedure **isPrime(n)**, which returns *true* if n is a prime number and *false* otherwise. The program does not work as intended. Select 2 answers!
B. Line 4 (count <- 0) D. Line 9 (count <- count +1) ## Footnote **Answer B:** Line 4 If count is set to 0 repeatedly inside the loop, it will not provide an accurate count of the number of prime numbers in the list. **Answer D: **Line 9 If count is incremented outside the IF statement, it will increase for all entries in the list instead of just the prime entries.
45
The procedure below is intended to display the index in a list of unique names (nameList) where a particular name (targetName) is found. If targetNme is not foaund in nameList, the code should display 0. index <- 0 Procedure **FindName**(nameList, targetName)
C. **FindName ** ([Andrea, Ben,Chris] , Ben)