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

    Algorithm PP takes exactly n2n^2 steps on inputs of size nn and algorithm QQ takes exactly 16 nlog⁡2n16\,n\log_2 n steps. Among the powers of two n=2kn=2^k, what is the smallest nn for which QQ is strictly faster than PP?

    1. 1616

    2. 6464

    3. 256256

    4. 128128

    Show solution

    Answer: (D)

    QQ is faster when n2>16 nlog⁡2nn^2>16\,n\log_2 n, i.e. when n>16log⁡2nn>16\log_2 n, i.e. 2k>16k2^k>16k. For k=6k=6: 64>9664>96 is false; for k=7k=7: 128>112128>112 is true, and the inequality stays true for larger kk. So the answer is 27=1282^7=128. The value 1616 comes from treating log⁡2n\log_2 n as a constant ≈\approx 1, and 256256 from stopping one step too late.

  2. Randomized Algorithms and Quicksort · Multiple choice · 1 mark

    An array holds 4040 numbers, exactly 1010 of which are “good”. An algorithm repeats the following until it stops: choose an index uniformly at random (independently each time, with replacement) and read that entry, which costs 33 steps; stop as soon as the entry read is good. What is the expected total number of steps?

    1. 33

    2. 44

    3. 99

    4. 1212

    Show solution

    Answer: (D)

    (D). Each read is good with probability p=1040=14p=\tfrac{10}{40}=\tfrac14, so the number of reads is geometric with mean 1/p=41/p=4, and the expected cost is 4⋅3=124\cdot 3=12 steps. The value 44 counts reads rather than steps, 33 is the cost of a single read, and 99 counts only the expected 33 failed reads.

  3. Priority Queues and Heaps · Short answer · 2 marks

    The array A=[40,33,36,28,31,19,12,20,16,10]A=[40,33,36,28,31,19,12,20,16,10] is a max-heap with n=10n=10. Extract-Max returns A[1]A[1], moves A[10]A[10] to the root and sifts it down, always swapping with the larger child. Write the array that remains.

    Show solution

    The value 4040 is returned and 1010 becomes the root of the nine-key heap [10,33,36,28,31,19,12,20,16][10,33,36,28,31,19,12,20,16]. The children 33,3633,36: swap with 3636 (index 33). The children of index 33 are 19,1219,12: swap with 1919 (index 66). Index 66 has no children (12>912>9). The array is [36,33,19,28,31,10,12,20,16][36,33,19,28,31,10,12,20,16].

  4. Hashing · Short answer · 2 marks

    A table has m=7m=7 slots and uses double hashing with h1(k)=k mod 7h_1(k)=k \bmod 7, h2(k)=1+(k mod 5)h_2(k)=1+(k \bmod 5) and h(k,i)=(h1(k)+i h2(k)) mod 7h(k,i)=(h_1(k)+i\,h_2(k)) \bmod 7. The keys 1515, 2222, 88 are inserted, in this order, into the empty table. Write the final table (put −- in an empty slot).

    slot0123456
    key                     
    Show solution

    Answer: –; 15; –; –; 22; 8; –

    1515: h1=1h_1=1, slot 11 is empty. 2222: h1=1h_1=1 (occupied), h2=1+2=3h_2=1+2=3, next probe (1+3) mod 7=4(1+3) \bmod 7=4. 88: h1=1h_1=1 (occupied), h2=1+3=4h_2=1+3=4, next probe (1+4) mod 7=5(1+4) \bmod 7=5. The table has 1515 in slot 11, 2222 in slot 44, 88 in slot 55.

  5. Minimum Spanning Trees and Lower Bounds · Short answer · 2 marks

    The complete graph K8K_8 has vertices 1,2,…,81,2,\dots,8, and the edge {i,j}\{i,j\} has weight i+ji+j. What is the weight of a minimum spanning tree of this graph? Give the number and a one- or two-sentence reason.

    Show solution

    The weight is 4242. Root any spanning tree at vertex 11: each vertex j≥2j\ge2 has a parent edge {j,p}\{j,p\} of weight j+p≥j+1j+p\ge j+1, so the tree weighs at least ∑j=28(j+1)=3+4+⋯+9=42\sum_{j=2}^{8}(j+1)=3+4+\dots+9=42. The star centred at vertex 11 has exactly these edges, so it attains the bound.

About MIE245H1 practice exams

MIE245H1 practice exams

Data Structures and Algorithms · University of Toronto (UofT, U of T, UToronto) · also written MIE245, MIE 245

Make a free, printable MIE245H1 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 MIE245H1 past exams?

Start with the past exams and tests your instructor or the UofT library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh MIE245H1 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
  • Randomized Algorithms and Quicksort · 50 questions
  • Balanced and Augmented Search Trees · 50 questions
  • Priority Queues and Heaps · 50 questions
  • Hashing · 50 questions
  • Graphs, BFS and DFS · 50 questions
  • Minimum Spanning Trees and Lower Bounds · 50 questions

More UofT courses

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