Final Exam, CSCI 385, Fall 2014


  1. Sorting Freebie
    1. [4 points] Give the algorithm for any sort you programmed for this class. (You may not use GNOME_SORT, given below)
    2. [3 points] Develop a timing function for the worst case of your sort, simplify this function to closed form and give the complexity class for this algorithm.
    3. [3 points] State conditions where this sort is a logical choice for use.

  2. Algorithm Analysis
      GNOME_SORT(A[]) 
      // assume index values 0 to n-1
      
      1. pos ← 1
      2. while pos < n do
      3. if A[pos] ≥ A[pos-1] then
      4. pos ← pos + 1
      5. else
      6. SWAP(A[pos],A[pos-1]
      7. if pos > 1 then
      8. pos ← pos -1
      9. return
    1. [1 point] Trace this algorithm for A = {2, 5, 4, 1}
    2. [2 points] What would be the best possible input for this algorithm? Why?
    3. [2 points] What would be the worst possible input for this algorithm? Why?
    4. [2 points] How does the algorithm work?
    5. [1 point] What is the natural measurement of the input size. The answer "n" is wrong.
    6. [2 points] Provide a timing function for the best case performance for this algorithm.
    7. [2 points] Simplify the timing function and provide the complexity class.
       

    MORE ON BACK

  3. Given a collection B of k unique bolts, and a collection N, of k unique nuts. Your task is to match the nuts and bolts.
    1. Brute Force
      1. [4 points] Give a brute force algorithm to match all nuts to the corresponding bolts.
      2. [2 points] Describe how your algorithm works.
      3. [2 points] Provide a full timing analysis for the best case for this algorithm.
      4. [2 points] Provide a full timing analysis for the worst case of this algorithm.
    2. Divide and Conquer
      1. [4 points] Create a divide and conquer algorithm to match all nuts to the corresponding bolts.
      2. [2 points] Describe how your algorithm works.
      3. [4 points] Provide a full timing analysis for the average case of this algorithm.

  4. Computability
    1. [3 points] Give a definition for the classes P, NP and NP-Complete.
    2. [2 points] Describe the process to show that a problem is in class NP-Complete.
    3. [6 points] Draw a diagram for each of the three possible different relationships between P, NP and NPC. For each diagram state the result if the relationship were shown to be true.
    4. You have been offered a job packing Santa's sleigh. The maximum weight the sleigh can hold is known (W), as are the weight (w1,w2... wn) and relative importance (v1,v2... vn) of the n packages. Santa wishes to fill his sleigh as full as possible (maximum weight) with total importance of the packages as high as possible.
      1. [6 points] State two different conditions where you will accept this job. Explain why these conditions should be imposed and the relative time required to complete each job.
      2. [3 points] State one condition under which you should not take this job and why, include a relative time required to complete the job.

    Comments

    1. Question 1
      • The number of people who incorrectly present bubble sort supprises me.
      • Stating the bubble sort should never be used is not right, you were presented with one situation, sorting the verticies in a fill algorithm, where the positions of a few may change positions -> 2 passes through data
      • Magic in mathematical derivations are a problem.
    2. Question 2 - no major problems.
    3. Question 3
    4. If you are going to sort, you must describe how you will sort. This is not apparent.
    5. Futrthermore, presorting is transform and conquer, not divide and conquer.
    6. Question 4
      • Part C is not a good question. Should not have stated a number.
      • Part D, you really should remember, the 0-1 knapsack problem, and also the dynamic programming example. Each reduce the problem to a solvable problem.