CSC 331 Review Game 1. Teams Katie, Mark, Alex Z, Dan B., Zane Dan C, Alex D, Dawn, Marshall, Zack...

Post on 20-Jan-2016

216 views 0 download

Transcript of CSC 331 Review Game 1. Teams Katie, Mark, Alex Z, Dan B., Zane Dan C, Alex D, Dawn, Marshall, Zack...

CSC 331 Review Game 1

Teams

• Katie, Mark, Alex Z, Dan B., Zane• Dan C, Alex D, Dawn, Marshall, Zack• Colby, Benjamin, Lisa, Riley, Andrew• Catharine, Ryan, Jerry, Z, Lawrence• Michelle, Jacapo, Rohan, Alexis, Jamie• Patrick, Matt, Emily, Alex H, Hugh

Individual Round

1. Θ, Ω, or O?

• log10n2 = ___(log2n)

2. Θ, Ω, or O?

• n! = ___(2n)

3. Θ, Ω, or O?

• lgn = ___(√n)

4. What’s the best running time?

• Given an array of n sorted Strings, find the first String that would occur after the word “Happy”.

5. What’s the best running time?

• Given an array of n numbers that are NOT sorted and an integer k, find the kth smallest number in the array.

6. What is the running time?

Alg first() is linearMYSTERY(A[1..n])

for i = 1 to n first(A[1..n])

7. What is the running time?

Alg first() is linearMYSTERY(A[1..n])

for i = 1 to 10 first(A[1..n])

8. What is the running time?

Alg first() is linear Alg second() is θ(nlgn)MYSTERY(A[1..n])

second(A[1..n])for i = 1 to n

for i = 1 to n/2first(A[1..n])

9. What does the algorithm do?

MYSTERY(A[left..right])if (left=right) return 1;x = MYSTERY(A[left..right-1])return x+1

10. What is the Recurrence Relation?

MYSTERY(A[left..right])if (left =right) return 1;x = MYSTERY(A[left..right-1])return x+1

11.

• What does ENIGMA(8) print?ENIGMA(integer n):

if n = 1 PRINT 1else:

ENIGMA(n/2)PRINT n

12.

• What is the recurrence relation?ENIGMA(integer n):

if n = 1 PRINT 1else:

ENIGMA(n/2)PRINT n

13.

What does the algorithm do?SECRET(A[1..n], k)

if k = 1 return A[1]else

return SECRET(A[2..n],k-1)

14.

What is the recurrence relation?SECRET(A[1..n], k)

if k = 1 return A[1]else

return SECRET(A[2..n],k-1)

15. Solve using Master’s

• T(n)= 2T(n/2) + n

16. Solve using Master’s

• T(n)= 3T(n/2) + n2

17.

What does it mean to partition your data?

18.

• A sort whose main operation is finding whether or not 2 elements are <, >, or = is called…

19.

What does it mean for a sort to be stable?

20.

What does it mean for a sort to be in-place?

21.

• What is the worst-case running time for Quicksort? When does it happen?

22.

• Give a time when you would prefer Insertion sort over Randomized Quicksort.

23.

• Which sort has its best case when it is in reverse order?

24.

• Quicksort’s recurrence relation is T(n) = 2T(n/2) + nWhere did that last n come from?

25.

• What algorithm do I use?I want to find the median of a set of

100,000,000 numbers

26.

What algorithm do I use?

I’m trying to find the record for “John Doe” from a set of records sorted by name.

27.

• What algorithm do I use?I’m trying to quickly sort 2 million 10-digit

numbers. I have plenty of space but want to save time.

28.

What is a heap?

29.

• I have a heap with n nodes. What is its depth?

30.

• What is the running time for heapsort?

All-Play

What is the running time?

Input Time1,000 2,0002,000 5,0003,000 10,0004,000 17,000

• Alg A has running time of 2n+5. Alg B has a running time of n2. For what values of n should you use Alg A and for what values should you use Alg B?

• Solve:T(n) = 2T(n-2)+1

• Write pseudocode for a divide-and-conquer algorithm for finding the number of negatives in an array.

Write an algorithm

An array A[1..n] has a majority element if one element occurs in more than half of the entries. Design an O(nlgn) algorithm to decide if the array has a majority element and if so, what the element is. You cannot sort the array, or ask if A[i]>A[j], since comparisons are not supported on the array type. (For example, if the array were of GIF files.) You can, however, ask if A[i] = A[j].