AP CSP CHAPTER 5

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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

C. as the size of the list grows, bucket sort will be faster than bubble sort.

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

C.Looking up a word in a Webster's dictionary. D. Looking up a phone number in the phone book given the person's full (unique) name.

Q-2: For searching a sorted list, which search algorithm is the better choice?

binary search

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

false

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

false

Q-1: For searching an unordered list, which search algorithm is the better choice?

linear search

AP 2021 Sample Question: A certain computer has two identical processors that are able to run in parallel. Each processor can run only one process at a time, and each process must be executed on a single processor. The following table indicates the amount of time it takes to execute each of three processes on a single processor. Assume that none of the processes are dependent on any of the other processes. ProcessExecution Time on Either Processor X60 seconds Y30 seconds Z50 seconds Which of the following best approximates the minimum possible time to execute all three processes when the two processors are run in parallel? A. 80 seconds B. 90 seconds C. 60 seconds D. 70 seconds

80 seconds

: 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. 17 B. -1 C. 5 D. 9 E. 16

A. 17

Q-12: There are 32 students standing in a classroom. Two different algorithms are given for findingthe average height of the students. Algorithm AStep 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 BStep 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 numberswritten on their cards and writes the result on one student's card; the other student isseated. 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. Both Algorithm A and Algorithm B always calculate the correct average. B. Algorithm A always calculates the correct average, but Algorithm B does not. C. Algorithm B always calculates the correct average, but Algorithm A does not. D. Neither Algorithm A nor Algorithm B calculates the correct average.

A. Both Algorithm A and Algorithm B always calculate the correct average.

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

A. More efficient than bubble sort. C. A linear algorithm

AP 2021 Sample Question: A sorted list of numbers contains 500 elements. Which of the following is closest to the maximum number of list elements that will be examined when performing a binary search for a value in the list? A. 10 B. 50 C. 500 D. 250

A.10

Consider an algorithm to solve a problem that takes 160 seconds to run on 1 processor. This algorithm can be divided among two processors to solve the same problem in 100 seconds. What is the speedup for this parallel algorithm? A. 2 B. 1.6 C. 1 D. .06

B 1.6

If you were using binary search to find the number 14 in the following list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], how many iterations would be required to find 14 in the list? A. 2 B. 3 C. 4 D. 14

B. 3

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

B. A comparison-based algorithm. C. An N2 algorithm.

For which of the problems would the bubble sort algorithm provide an appropriate solution. Choose all that apply. A. Looking up a name in the phone book. B. Arranging a deck of cards from the lowest to the highest value cards. 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.

B. Arranging a deck of cards from the lowest to the highest value cards. C. Sorting a stack of paper money into denominations -- i.e., $1, $5, $10 etc. E. Arranging books on a bookshelf by author's last name.

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. Intractable

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 word in a Webster's dictionary. C. Looking up a person's name in the phone book given the person's phone number. D. Guessing a secret number between 1 and 100. E. Looking up a phone number in the phone book given the person's full (unique) name.

B. Looking up a word in a Webster's dictionary. C. Looking up a person's name in the phone book given the person's phone number. D. Guessing a secret number between 1 and 100. E. Looking up a phone number in the phone book given the person's full (unique) name.

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. how long it takes to arrange the values in order. C. how many swaps are needed to sort the values .D. whether the algorithm correctly arranges the values in order. E. whether or not the algorithm contains a bug.

B. how long it takes to arrange the values in order.

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 cannot be solved in a reasonable time and an approximate solution is acceptable. C. When the problem can be solved in a reasonable time and an exact solution is needed. D. When the problem cannot be solved in a reasonable time and an exact solution is needed.

B.When the problem cannot be solved in a reasonable time and an approximate solution is acceptable.

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, squash, tomato, orange, papaya, pumpkin] B. [apple, banana, lemon, orange, papaya, pumpkin, tomato, squash] C. [apple, banana, lemon, orange, papaya, squash, tomato, pumpkin] D. [apple, banana, lemon, orange, papaya, pumpkin, squash, tomato] E. [apple, banana, lemon, tomato, orange, squash, papaya, pumpkin]

D. [apple, banana, lemon, orange, papaya, pumpkin, squash, tomato]

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

D. an undecidable problem.

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. pumpkin C. squash D. papaya E. tomato

E. tomato

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

For a deck of 13 cards, this version of bubble sorts makes 13 passes through the deck. On the last pass, there was only 1 card left in the unsorted deck, but we can still consider that a pass. There are different versions of bubble sort, some of which would say that N-1 passes are made through the deck to sort N cards.

For a list of 500 numbers, at most how many iterations would the loop in binary search run to find a number? For example, if this was a guessing game, at most how many guesses would it take using binary search to guess a secret number from 1-500, if after each guess you were told whether your guess was too high or too low or just right?

That's right! 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.


Ensembles d'études connexes

ตัวซี - หน้าฟิล์มผลิต

View Set

Chapter 13: Disorders of Red Blood Cells Prep U

View Set

MIS 431 REVIEW QUESTIONS TEXTBOOK

View Set

Exam 3: Adulthood Ch. 14, 16, 18, 19

View Set

Chapter 24: Asepsis and Infection Control PrepU

View Set

Foundations of Education test ch. 9-11

View Set

Introduction and Descriptive Statistics

View Set

PPME Block 2 The Culture of the Navy - Lawful and Unlawful Orders

View Set

Stats Ch. 2: Frequency Tables, Frequency Distributions, and Graphic Presentation

View Set