1 / 38

CSC 331 Review Game 1

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

piper
Download Presentation

CSC 331 Review Game 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 331 Review Game 1

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

  3. Individual Round

  4. 1. Θ, Ω, or O? • log10n2 = ___(log2n)

  5. 2. Θ, Ω, or O? • n!= ___(2n)

  6. 3. Θ, Ω, or O? • lgn= ___(√n)

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

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

  9. 6. What is the running time? Alg first() is linear MYSTERY(A[1..n]) for i = 1 to n first(A[1..n])

  10. 7. What is the running time? Alg first() is linear MYSTERY(A[1..n]) for i = 1 to 10 first(A[1..n])

  11. 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])

  12. 9. What does the algorithm do? MYSTERY(A[left..right]) if (left=right) return 1; x = MYSTERY(A[left..right-1]) return x+1

  13. 10. What is the Recurrence Relation? MYSTERY(A[left..right]) if (left =right) return 1; x = MYSTERY(A[left..right-1]) return x+1

  14. 11. • What does ENIGMA(8) print? ENIGMA(integer n): if n = 1 PRINT 1 else: ENIGMA(n/2) PRINT n

  15. 12. • What is the recurrence relation? ENIGMA(integer n): if n = 1 PRINT 1 else: ENIGMA(n/2) PRINT n

  16. 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)

  17. 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)

  18. 15. Solve using Master’s • T(n)= 2T(n/2) + n

  19. 16. Solve using Master’s • T(n)= 3T(n/2) + n2

  20. 17. Suppose a heap has 6 nodes. What is the height of the heap? (Remember the root is at height 0).

  21. 18. • Suppose you have a binary search tree with 6 nodes. What is the range of what the height of the tree may be?

  22. 19. Suppose that a hash table has 50 slots and only 10 keys. What is its load factor?

  23. 20. Give one pro of an array over a linked list and vice versa.

  24. 21. • When would you prefer to use a heap rather than a binary search tree?

  25. 22. • What data structure is implemented using a heap?

  26. 23. • What is the main operation supported by a heap?

  27. 24. • What is the main operation supported by a BST?

  28. 25. Could this be a heap? Why or why not? 18 12 10 9 8 3

  29. 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?

  30. 27. • What is the running time for sorting an array?

  31. 28. How is divide-and-conquer used when computing with a BST?

  32. All-Play

  33. What is the running time? Input Time 1,000 2,000 2,000 5,000 3,000 10,000 4,000 17,000

  34. 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?

  35. Solve: T(n) = 2T(n-2)+1

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

  37. 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?

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

More Related