Sample CSC263H1 questions
  1. Worst-Case and Average-Case Analysis · Short answer · 2 marks

    Prove from the definition that n2∉O(n)n^2\notin O(n).

    Show solution

    Suppose n2≤c nn^2\le c\,n for all n≥n0n\ge n_0, for some constants c,n0c,n_0. Dividing by n>0n>0 gives n≤cn\le c for all n≥n0n\ge n_0. But n=max⁡(n0,⌈c⌉+1)n=\max(n_0,\lceil c\rceil+1) violates this, a contradiction.

  2. Balanced and Augmented Search Trees · Short answer · 2 marks

    Let NhN_h be the fewest nodes in an AVL tree of height hh, with N0=1N_0=1, N1=2N_1=2 and Nh=Nh−1+Nh−2+1N_h=N_{h-1}+N_{h-2}+1.

    1. What is N7N_7? [1]

    2. What is the greatest possible height of an AVL tree with exactly 50 nodes? [1]

    Show solution
    1. The sequence N0,…,N7N_0,\dots,N_7 is 1,2,4,7,12,20,33,541,2,4,7,12,20,33,54, so N7=54N_7=54.

    2. Height 7 needs at least 54 nodes, which is more than 50, while N6=33≤50N_6=33\le 50. The greatest possible height is 66.

  3. Randomized Algorithms and Quicksort · Problem · 6 marks

    A permutation π\pi of {1,…,n}\{1,\dots,n\}, with n≥2n\ge2, is chosen uniformly at random. A 22-cycle is a pair {i,j}\{i,j\}, i≠ji\ne j, with π(i)=j\pi(i)=j and π(j)=i\pi(j)=i.

    1. Find the expected number of fixed points of π\pi (indices with π(i)=i\pi(i)=i). [1]

    2. Find the expected number of 22-cycles of π\pi. [2]

    3. Let YY be the number of indices ii with π(π(i))=i\pi(\pi(i))=i. Show that YY equals the number of fixed points plus twice the number of 22-cycles, and find E[Y]E[Y]. [3]

    Show solution

    (a) E[#fixed points]=n⋅1n=1E[\#\text{fixed points}]=n\cdot\frac1n=1, since Pr⁡[π(i)=i]=(n−1)!n!=1n\Pr[\pi(i)=i]=\frac{(n-1)!}{n!}=\frac1n.

    (b) For each unordered pair {i,j}\{i,j\} let Zij=I{π(i)=j and π(j)=i}Z_{ij}=I\{\pi(i)=j\text{ and }\pi(j)=i\}. Fixing two values of π\pi leaves (n−2)!(n-2)! permutations, so Pr⁡[Zij=1]=(n−2)!n!=1n(n−1)\Pr[Z_{ij}=1]=\frac{(n-2)!}{n!}=\frac1{n(n-1)}. Summing over the (n2)\binom n2 pairs gives (n2)⋅1n(n−1)=12\binom n2\cdot\frac1{n(n-1)}=\frac12.

    (c) π(π(i))=i\pi(\pi(i))=i holds iff π(i)=i\pi(i)=i, or π(i)=j≠i\pi(i)=j\ne i and π(j)=i\pi(j)=i, i.e. iff ii is a fixed point or belongs to a 22-cycle. Each 22-cycle contributes two such indices, so Y=#fixed points+2⋅# 2-cyclesY=\#\text{fixed points}+2\cdot\#\,2\text{-cycles} and E[Y]=1+2⋅12=2E[Y]=1+2\cdot\frac12=2. (Directly: Pr⁡[π(π(i))=i]=1n+(n−1)1n(n−1)=2n\Pr[\pi(\pi(i))=i]=\frac1n+(n-1)\frac1{n(n-1)}=\frac2n for each ii.)

  4. Disjoint Sets · Multiple choice · 1 mark

    A forest uses union by rank (no path compression). What is the smallest number of nodes that a tree of rank 55 can contain?

    1. 66

    2. 1111

    3. 1616

    4. 3232

    Show solution

    Answer: (D)

    The rank of a root grows only when two roots of equal rank are joined, so a tree of rank rr is the union of two trees of rank r−1r-1 (plus possibly more nodes attached later). Writing s(r)s(r) for the minimum size, s(0)=1s(0)=1 and s(r)=2 s(r−1)s(r)=2\,s(r-1), hence s(5)=25=32s(5)=2^5=32. The value 6=r+16=r+1 would be a path, 11=2r+111=2r+1 has no justification, and 16=2r−116=2^{r-1} is off by one level of doubling.

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

    A comparison-based algorithm sorts 44 distinct keys by asking questions of the form “is ai<aja_i<a_j?”. What is the largest lower bound that the decision-tree argument gives on its worst-case number of comparisons?

    1. 33

    2. 44

    3. 55

    4. 66

    Show solution

    Answer: (C)

    The tree must have a leaf for each of the 4!=244!=24 orderings, and a binary tree of height hh has at most 2h2^h leaves, so 2h≥242^h\ge 24 and h≥⌈log⁡224⌉=5h\ge\lceil\log_2 24\rceil=5. Using ⌊log⁡224⌋=4\lfloor\log_2 24\rfloor=4 (or n=4n=4) rounds down, 3=n−13=n-1 is the cost of finding the maximum, and 6=(42)6=\binom42 is the number of pairs, not a bound from the tree.

About CSC263H1 practice exams

CSC263H1 practice exams

Data Structures and Analysis · University of Toronto (UofT, U of T, UToronto) · also written CSC263, CSC 263

Make a free, printable CSC263H1 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 450 original questions and skips the ones you have already seen.

Looking for CSC263H1 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 CSC263H1 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
  • Amortized Analysis · 50 questions
  • Disjoint Sets · 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.