Unit 5 APCSP

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

D

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 N^2 algorithm. D. More efficient than bubble sort. E. A linear algorithm

D, E

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

False

The Traveling Salesman Problem

Given a list of cities and the distances between them find the shortest path visiting each city once and returning to the start.

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 many operations it takes to arrange the values in order. E. how many swaps are needed to sort the values.

B

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

B

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? (Hint:the first time through the loop, 14 is compared with the middle element 8 and is higher, so you narrow down to items 9-15. Then, 14 is compared with 12, the middle element of the 9-15 range, and you narrow down to 13-15. Then, 14 is compared to 14 and you find the element in 3 iterations.) 5.7 A. 2 B. 3 C. 4 D. 14

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

B

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

There are 32 students standing in a classroom. Two different algorithms are given for finding the 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 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

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, 5, 4] C. [1, 3, 5, 4] D. [0, 3, 4, 5]

C

When do you use the linear search?

When the set of data is not sorted

When do you use the binary search?

When the set of data is sorted

Linear Search

a method for finding a target value within a list. It sequentially checks each element of the list for the target value until a match is found or until all the elements have been searched.

heuristic algorithm

a method of solving an optimization problem that is "fast" but does not guarantee an optimal answer to the problem

optimization problem

a problem with the goal of finding the best (optimal) solution among many

URL

abbreviation of uniform resource locator it is the global address of documents and other resources on the World Wide Web

What is a merge sort?

divide by 2, pass off; continue until 1 pass back in order; very efficient

Efficency

how well an algorithm uses time and memory/space resources, CPU and RAM

foreground

in multiprocessing systems, the process that is currently accepting input from the keyboard or other input device

background

multitasking computers are capable of executing several tasks, or programs, at the same time

Firewall

prevent unauthorized access to or from a private network

decidable problem

problem in which an algorithm can be constructed to answer "yes" or "no" for all inputs

decision problem

problem that has a yes or no answer

intractable problems

problems that is practically impossible to solve — i.e., there are known algorithmic solutions, but the algorithms are too inefficient to solve the problem when the number of inputs grows large

Semantic

puts code in correctly but it does not do what is supposed to do

brute force

solve by trial and error; trying every possible option

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?

500 numbers would take at most 9 guesses. That's because you can divide that range of numbers 9 times before getting down to 1 number. For example, if we use whole number division and round up, we would get: 250, 125, 63, 32, 16, 8, 4, 2, 1.

A sequential search algorithm would be classified as .... A. Linear C. Logarithmic B. Quadratic D. exponential

A

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

A

What is a bubble sort?

A Bubble sort puts a group of random numbers in order by face value

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 N^2 algorithm. D. More efficient than bucket sort. E. Widely used to sort large data sets.

A, C

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.

A, C, E

Binary Search Algorithm

An algorithm that searches for a target value in a sorted list by checking at the midpoint and then repeatedly cutting the search section in half.

Which of the following are true of intractable problems? A. Intractable problems have no solution. B. There is an algorithm to solve the problem but it is too inefficient to solve the problem as N grows large. C. The algorithm to solve an intractable problem takes exponential time. D. Some intractable problems can be solved by more efficient heuristic algorithms -- algorithms that usually work.

B

Which of the following is not true about algorithms? A. An algorithm is a sequence of precise instructions. B. Algorithms can be written to solve every problem. C. Algorithms are step-by-step procedures. D. Algorithms consist of sequences, selections, and repetitions.

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

B (largest)

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 Webster's dictionary. Looking up a person's name in the phone book given the person's phone number. Finding the smallest number in a list of numbers arranged randomly.

B, C

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 Webster's 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, D, E

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]

D

Binary Search

Looking for an item in an already sorted list by eliminating large portions of the data on each comparison

What is a bucket sort?

Ordering them into distinct buckets (groups) and collecting the group in order

What is radix sort?

Radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.

Linear Search Algorithm

Sequentially look for a data item in a list Return -1(or null) if reaches end

The Halting Problem

The unsolvable problem of writing a program that can tell whether a given program and its inputs will halt, without running the given program.

True or False: In computer programming, a bug is an error or defect that prevents the app from working the way it is supposed to. A. True B. False

True


Kaugnay na mga set ng pag-aaral

chapter 40 musculoskeletal prepu

View Set

ANCIENT CIVILIZATIONS STUDY GUIDE UNIT "8 & 9" ( QUESTIONS )

View Set

The Middle Ages: The Crusades 🏝👍

View Set

Principles of management: chapter 10 quiz

View Set

Prep U Practice Questions (Immunity)

View Set

week 14-phys 2 (Female reproductive system/menstrual cycle/pregnancy quizzes)

View Set

GMAT - Hard Quant - Number Properties

View Set

Chapter 16 Nervous System: Senses

View Set