APCSP UNIT 5 MULTIPLE CHOICE

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

D

What shape would be drawn by this algorithm? Number from -- 1 to -- 5 by -- 1 do: call forward pixels -- 100 call turn degrees -- 72 A. A square with sides of length 100 pixels B. A triangle with sides of length 72 pixels C. A pentagon with sides of length 72 pixels D. A pentagon with sides of length 100 pixels

D

Which code below could be placed in the following loop to print out the item in a list that has the lowest (minimum) value? list ← 1, 0, 4, 2 x ← 99 FOR EACH item IN list { <MISSING CODE> } DISPLAY(x) A. IF (item > 99) x ← item B. IF (item > x) x ← item C. IF (item < 99) x ← item D. IF (item < x) x ← item

A,C

Which of the following characteristics is true of bubble sort? Choose all that apply. A. A comparison-based algorithm. B. Useful only for sorting numbers. C.An N2 algorithm. D. More efficient than bucket sort. E. Widely used to sort large data sets.

D,E

Which of the following characteristics is true of bucket sort? Choose all that apply. A. A comparison-based algorithm. B. Useful only for sorting numbers. C. An N2 algorithm. D. More efficient than bubble sort. E. A linear algorithm

A

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

A,D

A teacher uses the following program to adjust student grades on an assignment by adding 5 points to each student's original grade. However, if adding 5 points to a student's original grade causes the grade to exceed 100 points, the student will receive the maximum possible score of 100 points. The students' original grades are stored in the list gradeList, which is indexed from 1 to n. i ← 1 REPEAT n TIMES { <MISSING CODE> i ← i + 1 } The teacher has the following procedures available. Which of the following code segments can replace <MISSING CODE> so that the program works as intended? Select two answers. (A) gradeList[i] ← min (gradeList[i] + 5, 100) (B) gradeList[i] ← max (gradeList[i] + 5, 100) (C) gradeList[i] ← gradeList[i] + 5 IF (gradeList[i] > 100) { gradeList[i] ← gradeList[i] - 5 } (D) gradeList[i] ← gradeList[i] + 5 IF (gradeList[i] > 100) { gradeList[i] ← 100 }

9 (It would take at most 9 guesses because 2^9 equals 512, which is greater than 500. So you can divide the range 1 to 500 in half at most 9 times before running out of numbers.)

For a list of 500 numbers, at most how many guesses would it take using binary search to guess the secret number if after each guess you were told whether your guess was too high or too low or just right? Type your answer into the text box.

B

For searching a sorted list, which search algorithm is the better choice? A. Linear search B. Binary search

A

For searching an unordered list, which search algorithm is the better choice? A. Linear search B. Binary search

B,C,D,E

For which of the problems could the linear search algorithm be used? Choose all that apply. A. Arranging a deck of cards from the lowest to the highest value cards. B. Looking up a phone number in the phone book given the person's full (unique) name. C. Looking up a word in a dictionary. D. Looking up a person's name in the phone book given the person's phone number. E. Guessing a secret number between 1 and 100.

B,C

For which of the problems would the binary search algorithm be useful? Choose all that apply. A. Arranging a deck of cards from the lowest to the highest value cards. B. Looking up a phone number in the phone book given the person's full (unique) name. C. Looking up a word in a dictionary. D. Looking up a person's name in the phone book given the person's phone number. E. Finding the smallest number in a list of numbers arranged randomly.

A,C,E

For which of the problems would the bubble sort algorithm provide an appropriate solution. Choose all that apply. A. Arranging a deck of cards from the lowest to the highest value cards. B. Looking up a name in the phone book. C. Sorting a stack of paper money into denominations -- i.e., $1, $5, $10 etc. D. Sorting a basket of laundry into socks, shirts, shorts, and sheets. E. Arranging books on a bookshelf by author's last name.

D

In talking about sorting algorithms in general, a sort algorithm's efficiency refers to ______________________. A. how many comparisons are needed to sort the values. B. whether the algorithm correctly arranges the values in order. C. whether or not the algorithm contains a bug. D. how long it takes to arrange the values in order. E. how many swaps are needed to sort the values.

13 (because there are 13 cards)

In the bubble sort demo, 13 cards are being sorted. How many passes does this version of the algorithm require to sort the cards?

B

Is the following problem tractable (solvable in a reasonable amount of time) or intractable (cannot be solved in a reasonable amount of time)? For any length string of letters using any combination of the letters 'a' through 'z', write down all possible strings. a. Tractable B. Intractable

B

Suppose you are sorting the following list of numbers in ascending order using bubble sort: [16, 5, -1, 4, 12, 17, 3, 10, 5, 9]. After the first pass through the numbers, what value would appear on the right of the list? A. 16 B. 17 C. 9 D. -1 E. 5

D

Suppose you are sorting the following list of words in alphabetical order using bubble sort: [apple, banana, lemon, tomato, orange, squash, papaya, pumpkin]. Which of the following gives the correct order of the list after two passes through the list? A. [apple, banana, lemon, tomato, orange, squash, papaya, pumpkin] B. [apple, banana, lemon, squash, tomato, orange, papaya, pumpkin] C. [apple, banana, lemon, orange, papaya, pumpkin, tomato, squash] D. [apple, banana, lemon, orange, papaya, pumpkin, squash, tomato] E. [apple, banana, lemon, orange, papaya, squash, tomato, pumpkin]

C

Suppose you are sorting the following list of words into alphabetical order using bubble sort: [apple, orange, banana, papaya, lemon, pumpkin, squash, tomato]. After the first pass through the list, what word would appear on the right of the list? A. apple B. squash C. tomato D. pumpkin E. papaya

C

The Halting Problemis an example of A. an intractable problem. B. an exponential problem. C. an undecidable problem. D. a difficult problem.

B

The function shown in this graph is known as the base-2 logarithm function, y = log2(x). Which search algorithm behaves like this function? A.Sequential search B. Binary search

C

There are 32 students standing in a classroom. Two different algorithms are given for finding the average height of the students. Algorithm A Step 1: All students stand. Step 2: A randomly selected student writes his or her height on a card and is seated. Step 3: A randomly selected standing student adds his or her height to the value on the card, records the new value on the card, and is seated. The previous value on the card is erased. Step 4: Repeat step 3 until no students remain standing. Step 5: The sum on the card is divided by 32. The result is given to the teacher. Algorithm B Step 1: All students stand. Step 2: Each student is given a card. Each student writes his or her height on the card. Step 3: Standing students form random pairs at the same time. Each pair adds the numbers written on their cards and writes the result on one student's card; the other student is seated. The previous value on the card is erased. Step 4: Repeat step 3 until one student remains standing. Step 5: The sum on the last student's card is divided by 32. The result is given to the teacher. Which of the following statements is true? (A) Algorithm A always calculates the correct average, but Algorithm B does not. (B) Algorithm B always calculates the correct average, but Algorithm A does not. (C) Both Algorithm A and Algorithm B always calculate the correct average. (D) Neither Algorithm A nor Algorithm B calculates the correct average.

C

To "drawSquare" L do: Number from -- 1 to -- 4 by -- 1 do: call forward pixels -- 50 call turn degrees -- 90 You should be able to draw a square of any size with this procedure by calling it and specifying the parameter L. However, this procedure has a bug. What is the bug? A. The procedure draws a pentagon not a square B. The procedure draws a triangle not a square C. The procedure always draws a square with sides of size 50. The parameter L is ignored, D. The procedure parameter isn't specified correctly

B

To say that bucket sort is more efficient than bubble sort means that _________________. A. for any size list, bucket sort will always be faster than bubble sort. B. as the size of the list grows, bucket sort will be faster than bubble sort. C. bucket sort requires fewer comparisons than bubble sort. D. bucket sort requires fewer swaps than bubble sort.

B

True or False: An algorithm can be found for any computational problem whatsoever. A. True B. False

B

True or false: All intractable problems (that cannot be solved in a reasonable time) are bad. A. True B. False

C

Under which of the following conditions is it most beneficial to use a heuristic approach to solve a problem? (A) When the problem can be solved in a reasonable time and an approximate solution is acceptable. (B) When the problem can be solved in a reasonable time and an exact solution is needed. (C) When the problem cannot be solved in a reasonable time and an approximate solution is acceptable. (D) When the problem cannot be solved in a reasonable time and an exact solution is needed.

C

What are the values in the list after executing the following code: list ← [ 0, 3, 5 ] APPEND( list, 4 ) INSERT( list, 2, 1 ) REMOVE( list, 1 ) A. [1, 2, 3, 4] B. [0, 3, 4, 5] C. [1, 3, 5, 4] D. [0, 3, 5, 4]


संबंधित स्टडी सेट्स

Chapter 5 Routing Switching exam

View Set

Epithelial Tissues Characteristics & Functions (A&P)

View Set

Gastrointestinal (poop indications)

View Set

The Mentality of Consumerism and individualism

View Set

Clinical Psych Exam 3; Quiz questions

View Set

Chapter 38: Agents to Control Blood Glucose Levels #2

View Set

CH 17 - MONOMER LIQUID & POLYMER

View Set

Karch Focus on Pharmacology Chapter 51- Diuretic Agents

View Set

Forensics CTE Test Chapter 2: The Crime Scene

View Set