Algorithms Final Exam

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

Suppose each operation takes 1 microsecond and the problem size n=1,000,000. A running time of 3n computes the result in _____.

3 seconds

Scalability refers to what quantity?

Input data size

A CPU can access memory cell 100 with the same speed as accessing memory cell 1,000,000.

True

Assigns x with y.

x <- y

If f(n)=2n+6n^2+4n then f(n) is _____.

O(n^2)

n^2+2n is OMEGA(n^2)

True

n^2+2n is THETA(n^2)

True

An experimental study could test all possible inputs for an algorithm that concatenates two strings.

False: [A string's length has no limit, so all possible pairs of strings cannot be generated. Thus all possible inputs cannot be tested by an experimental study.]

If f(n) = 2n + log n + 8 then f(n) is ____.

Linear

The _____ case analysis is commonly used as the standard for choosing a well-performing algorithm.

worst

If an algorithm has a logarithmic running time, the algorithm is asymptotically better than a THETA(n) algorithm.

True

Suppose an unordered list of employees is converted to a hierarchical management diagram. The hierarchical management diagram is a data structure.

True

The fractional knapsack problem can be solved in worst case O(n log n) time.

True

The greedy algorithm guarantees an optimal solution to the fractional knapsack problem.

True

Identifying an algorithm's _____ case is usually the most difficult.

average

The following four items are available: Item 1: 10 grams, $10 benefit Item 2: 20 grams, $40 benefit Item 3: 4 grams, $5 benefit Item 4: 12 grams, $6 benefit How will the greedy algorithm fill a 40 gram knapsack?

20 grams of item 2 4 grams of item 3 10 grams of item 1 6 grams of item 4

Which running time expression is in closed form?

T(n) = 7 + 2n/3

The following four items are available: Item 1: 10 grams, $10 benefit Item 2: 20 grams, $40 benefit Item 3: 4 grams, $5 benefit Item 4: 12 grams, $6 benefit Assuming a knapsack with positive capacity, when would the greedy algorithm not choose any of item 2?

The greedy algorithm always chooses item 2

Counting the number of primitive operations provides a good estimate of an algorithm's running time.

True

Refer to the animation above. 2) Using the fractional knapsack approach, how many green apples can fill the 22 ounce grocery bag?

2.75

An algorithm that takes theta(log n) time is faster than an algorithm that takes (Theta)(n) time.

False

An experimental study requires implementing and running the algorithm.

True

The following four items are available: Item 1: 10 grams, $10 benefit Item 2: 20 grams, $40 benefit Item 3: 4 grams, $5 benefit Item 4: 12 grams, $6 benefit Sorting items from highest value to lowest yields _____.

(item 2, item 3, item 1, item 4)

Refer to the animation above. 1) Assume a 0-1 knapsack problem where yellow apples are sold out. The greedy method chooses _____ to fill the 22 ounce grocery bag.

2 green apples and 3 red apples

Loop that starts with i=0 and goes up to i=n.

for i <- 0 to n do

The following four items are available: Item 1: 10 grams, $10 benefit Item 2: 20 grams, $40 benefit Item 3: 4 grams, $5 benefit Item 4: 12 grams, $6 benefit The value of _____ is $2 / gram.

item 2

What functions stay below 2,000,000 when n <= 50,000

n and n log n only

If an algorithm's best case does 15n+31 primitive operations, the algorithm's worst case may do _____ primitive operations.

n^2+100

Assume a 0-1 knapsack problem with a greedy method that makes choices that maximize the (cost / weight) ratio. Two apples exist: Red apples each cost $2 and weigh 5 ounces Green apples each cost $3 and weigh 6 ounces If maximizing just the cost for each choice, rather than the (cost / weight) ratio, the greedy method is _____.

not optimal for the 10 ounce bag

Assume a 0-1 knapsack problem with a greedy method that makes choices that maximize the (cost / weight) ratio. Two apples exist: Red apples each cost $2 and weigh 5 ounces Green apples each cost $3 and weigh 6 ounces The greedy method chooses _____ for a 10 ounce bag.

one green apple

A base case in a recursive algorithm is _____.

required

An algorithm is commonly scientifically characterized by _____.

running time

Assume a 0-1 knapsack problem with a greedy method that makes choices that maximize the (cost / weight) ratio. Two apples exist: Red apples each cost $2 and weigh 5 ounces Green apples each cost $3 and weigh 6 ounces The (cost / weight) ratio is _____ for a red apple and _____ for a green apple.

0.4, 0.5

Assume a 0-1 knapsack problem with a greedy method that makes choices that maximize the (cost / weight) ratio. Two apples exist: Red apples each cost $2 and weigh 5 ounces Green apples each cost $3 and weigh 6 ounces The greedy method makes the optimal choice for the 10 ounce bag.

False

If a CPU takes 2 microseconds to return from a method then the same CPU should also take 2 microseconds to index into an array.

False

An experimental study does 1,000,000 runs of an algorithm. Each is done in less than 5 milliseconds, implying that the algorithm is very fast for practical use.

False [The high number of runs and low runtime of each isn't enough to conclude that the algorithm is fast for practical use. Perhaps an input that wasn't used makes the algorithm take 900 milliseconds. Or maybe the computer running the tests is much faster than the average computer.]

A linearithmic's big-Oh notation is _____.

O(n log n)

Encloses parameters in a method declaration.

Parentheses: ()

An algorithm that calls itself two times in the non-base case can have a recurrence function that has two instances of T(n).

True

If f(n) is O(log n) then saying _____ is also mathematically correct.

f(n) subset O(log n)

An algorithm must _____.

finish in a finite amount of time


Ensembles d'études connexes

exs 15 exercises and joint action

View Set

Anthropology Test Questions Chapter 1

View Set

History 151 Final Section Review

View Set

Straighterline Macro Quiz Questions

View Set