Preview

Mid Term 1 Solution

Satisfactory Essays
Open Document
Open Document
534 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Mid Term 1 Solution
COT5405 Analysis of Algorithms Midterm 1 Solution
Summer 2012 June 11 In all cases explain clearly and as succinctly as possible. Problem 1 10 Pts

Answer: n T (n) = 2T ( n ) + log n 2 2 n = 4T ( n ) + logn n + log n 4 2 2 2 n = 4T ( n ) + log nn−1 + log n 4 2 2 = ... ∑log2 n 1 = nT (1) + n i=1 i ∑n Since i=1 1 → ln n, T (n) ∈ Θ(n log log n) i

Problem 2

20 Pts

Answer: The general idea is to use the technique similar to quick sort, by doing partition on both lids and cups. First we pick a cup randomly, and use it to partition the lids into two subsets: those lids smaller than the size of that cup, and those larger than the size of the cup. We can also find the correspondent lid for that chosen cup. Second we use that lid to partition the cups and divide them into two sets. We keep on repeating this procedure on each subset of cups/lids until all the cups/lids are paired. The overall time complexity is O(n log n) (Worst case: O(n2 )).

Problem 3

20 Pts

Answer: In this problem we are more interested in finding the median instead of the minimum/maximum element. The ⌊ n ⌋th element in a min/max heap is not the median. 2 In this case, we should develop a new type of heap to adapt this problem.

Problem 3

2

The solution is to use two heaps: a min heap and a max heap. Suppose the total number of elements is n, we set the restriction that the max heap should contain ⌊ n ⌋ 2 elements. Correspondingly, the min heap contains n − ⌊ n ⌋ elements. 2 When we insert an element, we always insert it into the max heap. If the number of elements in the max heap exceeds ⌊ n ⌋, we remove the maximum element in the 2 max heap (the root), and insert it into the minimum heap. During this procedure, we need to do heapify to maintain the heap structure for both heaps. Under this setting, it is easy to see that all the elements in the max heap are less than those in the min heap, and the two elements at the root of both heaps represent the ⌊ n ⌋th 2 and (⌊ n ⌋ + 1)th

You May Also Find These Documents Helpful

  • Good Essays

    Selected Answer: One advantage of forming a corporation is that equity investors are usually exposed to less liability than in a regular partnership.…

    • 1806 Words
    • 8 Pages
    Good Essays
  • Satisfactory Essays

    chapter 5 solutions

    • 877 Words
    • 6 Pages

    5–5A.(a)Yes. Donner Company meets the test of having paid wages totaling more than $1,500 during any calendar quarter of the current year.…

    • 877 Words
    • 6 Pages
    Satisfactory Essays
  • Good Essays

    Nt1310 Unit 3

    • 3151 Words
    • 13 Pages

    where N is the smallest power of two that will ensure C' <= 1024 (so that least…

    • 3151 Words
    • 13 Pages
    Good Essays
  • Powerful Essays

    Solutions Chapter 7

    • 7531 Words
    • 30 Pages

    CHAPTER 7 CORPORATIONS: REORGANIZATIONS SOLUTIONS TO PROBLEM MATERIALS Status: Q/P Question/ Learning Present in Prior Problem Objective Topic Edition Edition 1 LO 1 IRS Letter Ruling Unchanged 1 2 LO 1 Reorganizations follow tax law Unchanged 2 3 LO 1 Types of reorganizations Unchanged 3 4 LO 2…

    • 7531 Words
    • 30 Pages
    Powerful Essays
  • Good Essays

    Midterm Exam Solution

    • 1543 Words
    • 7 Pages

    2) In a competitive market, the market demand is Qd = 60 - 6P and the market supply is Qs = 4P. A price ceiling of $3 will result in a…

    • 1543 Words
    • 7 Pages
    Good Essays
  • Satisfactory Essays

    Chapter 4 Solutions

    • 473 Words
    • 2 Pages

    (c) Labor utilization = labor content / (labor content + total idle time) = 270 sec / (270 + 15 + 30+…

    • 473 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Chapter 9 Solutions

    • 2205 Words
    • 10 Pages

    2) The economy has gone into a recession. You have majored in computer science and, because of the recession, have difficulty in finding a job. Should you go back to school and get a second major?…

    • 2205 Words
    • 10 Pages
    Good Essays
  • Satisfactory Essays

    ACCO 310 Chapter 2 Solutions

    • 10295 Words
    • 57 Pages

    Copyright © 2013 John Wiley & Sons Canada, Ltd. Unauthorized copying, distribution, or transmission of this page is strictly prohibited.…

    • 10295 Words
    • 57 Pages
    Satisfactory Essays
  • Good Essays

    Complexities! Good Fair Poor Searching Algorithm Data Structure Time Complexity Depth First Search (DFS) Graph of |V| vertices and |E| edges Graph of |V| vertices and |E| edges Sorted array of n elements Array - O(|E| + |V|) O(|V|) - O(|E| + |V|) O(|V|) O(log(n)) O(log(n))…

    • 990 Words
    • 18 Pages
    Good Essays
  • Powerful Essays

    Chapter 15 Solutions

    • 11109 Words
    • 54 Pages

    The process of creating legal entities differs by entity type. Business owners legally form corporations by filing articles of incorporation in the state of incorporation while business owners create limited liability companies by filing articles of organization in the state of organization. General partnerships may be formed either with or without written partnership agreements, and they typically can be formed without filing documents with the state. However, limited partnerships are usually organized by written agreement and must typically file a certificate of limited partnership to be recognized by the state.…

    • 11109 Words
    • 54 Pages
    Powerful Essays
  • Satisfactory Essays

    We can list its elements in the order (2,1), (3,1), (2,2), (3,2), (2,3), (3,3), ...…

    • 699 Words
    • 3 Pages
    Satisfactory Essays
  • Good Essays

    Eecs 203 W1 Exam Solutions

    • 1195 Words
    • 5 Pages

    Problem 1 [Ch 1.1 #22] Write each of these statements in the form “if p, then q” in English. a) If you get promoted, then you wash the boss’s car. b) If the winds are from the south, then there will be a spring thaw. c) If you bought the computer less than a year ago, then the warranty is good. d) If Willy cheats, then he gets caught. e) If you access the website, then you must pay a subscription fee. f) If you know the right people, then you will be elected. g) If Carol is on a boat, then she gets seasick.…

    • 1195 Words
    • 5 Pages
    Good Essays
  • Satisfactory Essays

    1 6. 1 7. 1 8. 1 9. 1 10. 2 11. 2 12. 2 13.…

    • 2040 Words
    • 9 Pages
    Satisfactory Essays
  • Satisfactory Essays

    ATILIM UNIVERSITY DEPARTMENT OF MATHEMATICS Math 211 - Discrete Mathematics with Applications 2010-2011 Fall Semester Problem Set I Prepared by Mehmet TURAN…

    • 453 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Chapter 4 solutions

    • 953 Words
    • 6 Pages

    In early 2003 Bristol-Myers Squibb announced that it would have to restate its financial statements as a result of stuffing as much as $3.35 billion worth of products into wholesalers’ warehouses from…

    • 953 Words
    • 6 Pages
    Good Essays