380 likes | 493 Views
CSC 331 Review Game 1. Teams. James, Peter T, Matt B, Fritz Asher, Daniel S, Brian H, Alex D Kristen, Matt M, Peter D, Dillon Kaylin, Dan M, Emily, Spencer Brian S, Heather, Jerry, Gavan Seth, Colin, Rex, Chad Sam, Emma, George, Alex S. Individual Round. 1. Θ, Ω, or O?.
E N D
Teams • James, Peter T, Matt B, Fritz • Asher, Daniel S, Brian H, Alex D • Kristen, Matt M, Peter D, Dillon • Kaylin, Dan M, Emily, Spencer • Brian S, Heather, Jerry, Gavan • Seth, Colin, Rex, Chad • Sam, Emma, George, Alex S
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 linear MYSTERY(A[1..n]) for i = 1 to n first(A[1..n])
7. What is the running time? Alg first() is linear MYSTERY(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/2 first(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 1 else: ENIGMA(n/2) PRINT n
12. • What is the recurrence relation? ENIGMA(integer n): if n = 1 PRINT 1 else: 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. Suppose a heap has 6 nodes. What is the height of the heap? (Remember the root is at height 0).
18. • Suppose you have a binary search tree with 6 nodes. What is the range of what the height of the tree may be?
19. Suppose that a hash table has 50 slots and only 10 keys. What is its load factor?
20. Give one pro of an array over a linked list and vice versa.
21. • When would you prefer to use a heap rather than a binary search tree?
22. • What data structure is implemented using a heap?
23. • What is the main operation supported by a heap?
24. • What is the main operation supported by a BST?
25. Could this be a heap? Why or why not? 18 12 10 9 8 3
26. I’m going to empty a binary search tree by successively finding the smallest element, printing it, and then deleting it until the tree is empty. What’s the running time?
27. • What is the running time for sorting an array?
28. How is divide-and-conquer used when computing with a BST?
What is the running time? Input Time 1,000 2,000 2,000 5,000 3,000 10,000 4,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 pseudocode for finding the number of elements in a binary search tree less than some number, x, which is an element of the tree. You may assume that for any BST, you may ask for its size in O(1). What is the running time of your algorithm?
Write pseudocode for a O(lg(n)) algorithm that solves the following problem. • You are given 2 sorted arrays, X[1..n] and Y[1..n]. Find the median of the union of the two arrays. • For example, if X = [3,7,9,10] and Y=[2,6,12,14] then the median of [2,3,6,7,9,10,12,14] is (7+9)/2.