\( \newcommand{\blah}{blah-blah-blah} \newcommand{\eqb}[1]{\begin{eqnarray*}#1\end{eqnarray*}} \newcommand{\eqbn}[1]{\begin{eqnarray}#1\end{eqnarray}} \newcommand{\bb}[1]{\mathbf{#1}} \newcommand{\mat}[1]{\begin{bmatrix}#1\end{bmatrix}} \newcommand{\nchoose}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array}\right)} \newcommand{\defn}{\stackrel{\vartriangle}{=}} \newcommand{\rvectwo}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array}\right)} \newcommand{\rvecthree}[3]{\left(\begin{array}{r} #1 \\ #2\\ #3\end{array}\right)} \newcommand{\rvecdots}[3]{\left(\begin{array}{r} #1 \\ #2\\ \vdots\\ #3\end{array}\right)} \newcommand{\vectwo}[2]{\left[\begin{array}{r} #1\\#2\end{array}\right]} \newcommand{\vecthree}[3]{\left[\begin{array}{r} #1 \\ #2\\ #3\end{array}\right]} \newcommand{\vecfour}[4]{\left[\begin{array}{r} #1 \\ #2\\ #3\\ #4\end{array}\right]} \newcommand{\vecdots}[3]{\left[\begin{array}{r} #1 \\ #2\\ \vdots\\ #3\end{array}\right]} \newcommand{\eql}{\;\; = \;\;} \definecolor{dkblue}{RGB}{0,0,120} \definecolor{dkred}{RGB}{120,0,0} \definecolor{dkgreen}{RGB}{0,120,0} \newcommand{\bigsp}{\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;} \newcommand{\plss}{\;\;+\;\;} \newcommand{\miss}{\;\;-\;\;} \newcommand{\implies}{\Rightarrow\;\;\;\;\;\;\;\;\;\;\;\;} \newcommand{\prob}[1]{\mbox{Pr}\left[ #1 \right]} \newcommand{\exval}[1]{\mbox{E}\left[ #1 \right]} \newcommand{\variance}[1]{\mbox{Var}\left[ #1 \right]} \)


How to prep for the exam


 

About the exam:

 

How to prep:

 


Sample questions

 

One set of sample questions are the non-programming module exercises, or slightly modified versions of them.
 

Here are some others:

  1. Consider this snippet of code (without worrying about syntactic correctness):
      int[][] A = new int [n][];
      for (int i=0; i<n; i++) {
          if (i % 2 == 0) 
              A[i] = new int [n];
          else
              A[i] = new int [1];
      }
    
      for (int i=0; i<A.length; i++) 
          for (int j=0; j<A[i].length; j++) 
              sum = sum + A[i][j]; 
      
    It's running time is:
    1. \(O(n\log n\)
    2. \(O(n)\)
    3. \(O(n^2)\).
    4. \(O(\frac{n}{2})\)

  2. Suppose \(f(n) = 3n^3 + 2n^2 + n\). Consider these statements:
         I: \(f(n) = O(n^3)\).
         II: \(f(n) = O(n^4)\).
    1. Only I is true.
    2. Only II is true.
    3. I and II are both true.
    4. I and II are both false.

  3. The ratio of the running time of Bubble-Sort to that of Merge-Sort is:
    1. \(O(n\log n)\)
    2. \(O(\frac{n}{\log n})\)
    3. \(O(\log \frac{n^2}{\log n})\).
    4. \(O(1)\).

  4. Consider the following input with 10 keys (each is a letter) to QuickSort.
        K  G  I  K  N  V  S  S  W  Q
      
    Assume the leftmost element is the partitioning element. Show the array after the partitioning step is complete.

  5. Insert the bitstrings 100, 110, 011 and 010 into a simple trie. Show the trie at each step.

  6. Draw an NDFA for the regular expression C(AB)*(A|C)

  7. A ring is a connected undirected graph in which all the nodes form a ring (thus, each node has exactly two neighbors). The running time of Prim's algorithm, using an adjacency list, on this graph is:
    1. \(O(V \log V)\)
    2. \(O(V^2 \log V)\)
    3. \(O(V^2)\)
    4. \(O(V^3)\)

  8. Consider the following two statements about an undirected graph with n vertices:
         I: If every pair of vertices has an edge, there are exactly \(\frac{n(n+1)}{2}\) edges.
         II: If the graph has a spanning tree, the tree must have \(\Theta(n)\) edges.
    1. I and II are both true.
    2. Only I is true.
    3. Only II is true.
    4. I and II are both false.

  9. Suppose the shortest path from node i to node j goes through node k and that the cost of the subpath from i to k is \(D_{ik}\). Consider these two statements:
         I: Every shortest path from i to j must go through k.
         II: Every shortest path from i to k has cost \(D_{ik}\).
    1. I and II are both true.
    2. Only I is true.
    3. Only II is true.
    4. I and II are both false.

  10. Consider the following statements about NP-completeness:
         I: NP-completeness only applies to combinatorial optimization problems.
         II: An NP-complete problem cannot be solved in polynomial-time.
    1. I and II are both true.
    2. Only I is true.
    3. Only II is true.
    4. I and II are both false.
Note:
  • The above sample questions are only a guideline. Do NOT read anything into the particular topics selected above.
  • Answers to the above questions will not be provided, nor will the TAs do these in the lab. The idea is for you to develop confidence in answering the questions yourself.
  • The actual exam will have more than 10 questions.