Final Exam, CSCI 385, Fall 2011

  1. [10 points] Argue that the following algorithm correctly sorts the array A.

      BubbleSort(A[1 ... n])
    1. for i <- 1 to length(A)
    2. for j <- length(A) downto i+1
    3. if A[j] < A[j-1]
    4. exchange (A[j],A[j-1])
  2. [10 points]
    1. Describe complexity classes P, NP and NP-Complete.

    2. For each representation in the picture below (A,B and C) Describe if the representation is possibly correct given the current state of knowledge of the complexity classes P, NP and NP-Complete. If it is not possible, state why.

  3. Algorithm Design Methods
    1. [10 points] Name and describe the problem solving paradigms encountered in this class.

    2. [5 points] For each algorithm, describe a sorting algorithm that matches that design method (if one was covered). Describe why the sorting algorithm matches the method. If no algorithm matches, state this as well.

  4. [5 ponts] Describe how manintaining a dynamic array can be done in constant time. Provide an informal argument that the performance is constant for insertion at the end of the array.

    Over

  5. TOPO-Sort
        TOPO-Sort(G=(V,E))
      1. DFS(G)
      2. As each vertex is marked in line 7, insert it into the front of a linked list.
        DFS(G=(V,E))
      1. mark each vertex with a 0
      2. count <- 0
      3. for each vertex in V do
      4. if v is marked with a 0
      5. dfs(v)
        dfs(v)
      1. count <- count + 1
      2. mark v with count
      3. for each vertex w in V adjacent to v do
      4. if w is marked with a 0
      5. dfs(w)
      6. count <- count + 1
      7. mark v with count
    1. [6 points] Trace TOPO-SORT with the given graph. When given a choce, select the vertex with the lowest letter value.
    2. [10 points] Provide a timing analysis for DFS and for TOPO-SORT
    3. [4 points] Describe the design patterns applied in each case.