Sample EECS 281 questions
  1. Worst-Case and Average-Case Analysis · Multiple choice · 1 mark

    The algorithm below returns the largest element of A[1…n]A[1\ldots n], n≥1n\ge1.

    FindMax(A, n)
        m = A[1]
        for i = 2 to n
            if A[i] > m
                m = A[i]
        return m

    Which statement is a loop invariant that is true at the start of every iteration of the for loop (including the first, with i=2i=2) and, together with the loop’s exit condition, proves the algorithm correct?

    1. m=max⁡{A[1],…,A[i−1]}m=\max\{A[1],\ldots,A[i-1]\}

    2. m=max⁡{A[1],…,A[i]}m=\max\{A[1],\ldots,A[i]\}

    3. m≥A[i]m\ge A[i]

    4. m=A[i−1]m=A[i-1]

    Show solution

    Answer: (A)

    Before the iteration with index ii, mm holds the maximum of the elements already examined, A[1],…,A[i−1]A[1],\ldots,A[i-1]. It holds at i=2i=2 because m=A[1]m=A[1], each iteration keeps it true, and when the loop ends with i=n+1i=n+1 it says m=max⁡A[1…n]m=\max A[1\ldots n]. The version that includes A[i]A[i] is false on entry to the iteration (m=A[1]m=A[1] need not equal max⁡{A[1],A[2]}\max\{A[1],A[2]\}); m≥A[i]m\ge A[i] is not maintained (a later element may be larger); m=A[i−1]m=A[i-1] fails whenever A[i−1]A[i-1] is not a new maximum.

  2. Priority Queues and Heaps · Multiple choice · 3 marks

    Extract-Max on a max-heap with 3131 keys removes A[1]A[1], moves A[31]A[31] to the root, and sifts it down in a heap of 3030 keys. At each level the sift-down compares the two children with each other (one comparison, none if there is only one child) and then compares the larger child with the moving key (one comparison); it stops when the moving key is at least as large as both children or has no child. What is the largest possible number of key comparisons this Extract-Max can use?

    1. 44

    2. 55

    3. 66

    4. 88

    Show solution

    Answer: (D)

    The heap left after the removal has 3030 keys, so its height is ⌊log⁡230⌋=4\lfloor\log_2 30\rfloor=4 and the moving key can descend at most four levels. Each level costs at most two comparisons, giving 2⋅4=82\cdot 4=8, and this is reached when the moving key is smaller than everything on its path (for instance the minimum moved from the end of a decreasing array). One comparison per level gives 44 but forgets the comparison between siblings; 6=2⋅36=2\cdot 3 uses the height of a 1515-key heap, and 55 is ⌈log⁡231⌉\lceil\log_2 31\rceil.

  3. Hashing · Multiple choice · 1 mark

    Which statement about quadratic probing, h(k,i)=(h′(k)+c1i+c2i2) mod mh(k,i)=(h'(k)+c_1 i+c_2 i^2) \bmod m, is correct?

    1. It avoids all clustering, because any two keys examine their slots in different orders.

    2. It suffers primary clustering exactly as linear probing does, since runs of occupied slots keep growing.

    3. It avoids primary clustering, but keys with the same h′(k)h'(k) follow the same probe sequence.

    4. It examines every slot for every choice of c1c_1, c2c_2 and mm, so insertion succeeds while α<1\alpha<1.

    Show solution

    Answer: (C)

    (C). Two keys with different starting slots follow different sequences whose gaps grow, so runs of consecutive occupied slots do not trap them (no primary clustering); but two keys with the same h′(k)h'(k) get identical sequences (secondary clustering), which contradicts the first option. The last option is false: with m=7m=7, c1=0c_1=0 and c2=1c_2=1 only the four slots 0,1,2,40,1,2,4 (relative to the start) are ever probed.

  4. Randomized Algorithms and Quicksort · Short answer · 2 marks

    The array A[1…9]A[1\ldots 9] holds a uniformly random permutation of {1,…,9}\{1,\dots,9\}. A descent is an index i∈{1,…,8}i\in\{1,\dots,8\} with A[i]>A[i+1]A[i]>A[i+1]. What is the expected number of descents?

    Show solution

    44. Let Di=I{A[i]>A[i+1]}D_i=I\{A[i]>A[i+1]\}. By symmetry the two values are equally likely to be in either order, so E[Di]=12E[D_i]=\tfrac12 and E[∑i=18Di]=8⋅12=4E\bigl[\sum_{i=1}^{8}D_i\bigr]=8\cdot\tfrac12=4.

  5. Minimum Spanning Trees and Lower Bounds · Multiple choice · 1 mark

    In a connected weighted graph GG, the edge ee is the unique heaviest edge on some cycle CC of GG. Which statement is true?

    1. ee belongs to every minimum spanning tree, because it connects its two endpoints directly.

    2. ee belongs to some minimum spanning tree, provided no other cycle of GG contains ee.

    3. ee is the heaviest edge of GG.

    4. ee belongs to no minimum spanning tree of GG.

    Show solution

    Answer: (D)

    This is the cycle property. If a spanning tree TT contained ee, then removing ee splits TT into two parts, and some other edge ff of CC crosses between them. Since w(f)<w(e)w(f)<w(e), the tree T−e+fT-e+f is strictly lighter, so TT is not minimum. Hence ee is in no MST. It need not be the heaviest edge of GG (a heavier edge may be a bridge), and the number of other cycles through ee is irrelevant.

About EECS 281 practice exams

EECS 281 practice exams

Data Structures and Algorithms · University of Michigan (Michigan, UMich, U of M) · also written EECS281

Make a free, printable EECS 281 practice exam: choose the topics, the length and the difficulty above, and get an exam-style PDF with a full answer key. Each paper draws on 350 original questions and skips the ones you have already seen.

Looking for EECS 281 past exams?

Start with the past exams and tests your instructor or the Michigan library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh EECS 281 practice exams here on the same topics, with full answer keys, as many as you need. The questions here are original, not copies of past exams.

Topics covered

  • Worst-Case and Average-Case Analysis · 50 questions
  • Priority Queues and Heaps · 50 questions
  • Balanced and Augmented Search Trees · 50 questions
  • Hashing · 50 questions
  • Randomized Algorithms and Quicksort · 50 questions
  • Graphs, BFS and DFS · 50 questions
  • Minimum Spanning Trees and Lower Bounds · 50 questions

More Michigan courses

questionbank.dev is independent and not affiliated with University of Michigan. Course codes only say which topics a paper covers; papers are original practice material, not past or upcoming exams.