Sample CMPUT 175 questions
  1. Classes, Encapsulation and Representation Invariants · Short answer · 2 marks

    The method below omits the isinstance test.

    class Point:
        def __init__(self, x: int, y: int) -> None:
            self.x = x
            self.y = y
    
        def __eq__(self, other: object) -> bool:
            return self.x == other.x and self.y == other.y

    Give an expression that shows why the test is needed, and say what happens when it runs.

    Show solution

    For example Point(1, 2) == 5 raises an AttributeError, because an int has no attribute x. With the isinstance test the comparison would simply evaluate to False.

  2. Inheritance, Abstract Classes and Polymorphism · Short answer · 2 marks

    For each pair of classes, write inheritance if the second should be a subclass of the first, or composition if an object of the first should hold an object of the second as an attribute.

    Account and SavingsAccount   
    Car and Wheel   
    Course and Instructor   
    Animal and Penguin   
    Show solution

    Answer: inheritance; composition; composition; inheritance

    A savings account is an account and a penguin is an animal. A car has wheels and a course has an instructor.

  3. Running Time and Big-Oh · Predict the output · 2 marks

    Write the output of the following code. If the code raises an error, write ERROR and stop.

    def steps(n: int) -> int:
        count = 0
        for i in range(n):
            for j in range(i, n):
                count = count + 1
        return count
    
    print(steps(1))
    print(steps(4))
    print(steps(10))
    Show solution
    1
    10
    55

    The inner loop runs n−in - i times, so the total is n+(n−1)+⋯+1=n(n+1)/2n + (n-1) + \cdots + 1 = n(n+1)/2.

  4. Linked Lists · Predict the output · 2 marks

    Write the output of the code below. “print(lst)” displays a LinkedList like [1 -> 2 -> 3].

    lst = LinkedList([5, 4, 3, 2, 1])
    curr = lst._first
    while curr is not None and curr.next is not None:
        curr.item = curr.item * 10
        curr = curr.next.next
    print(lst)
    print(curr.item)
    Show solution
    [50 -> 4 -> 30 -> 2 -> 1]
    1

    curr visits the 1st, 3rd and 5th nodes. At the 5th node curr.next is None, so the loop ends without changing it, and curr still refers to that node.

  5. Recursive Sorting · Multiple choice · 1 mark

    Using the course mergesort (halves of sizes len(lst) // 2 and the rest), how many calls to merge are made by mergesort([9, 4, 7, 1, 8, 2])?

    1. 3

    2. 5

    3. 6

    4. 11

    Show solution

    Answer: (B)

    (B). Every call on a list with 2 or more items makes exactly one call to merge. The tree of calls has 6 leaves (one per item) and therefore 5 internal nodes. (The whole tree has 11 calls to mergesort, option D.)

About CMPUT 175 practice exams

CMPUT 175 practice exams

Introduction to the Foundations of Computation II · University of Alberta (UAlberta, UofA, U of A) · also written CMPUT175

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

Looking for CMPUT 175 past exams?

Start with the past exams and tests your instructor or the UAlberta library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh CMPUT 175 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

  • Classes, Encapsulation and Representation Invariants · 100 questions
  • Inheritance, Abstract Classes and Polymorphism · 100 questions
  • Stacks, Queues and Exceptions · 100 questions
  • Running Time and Big-Oh · 100 questions
  • Linked Lists · 100 questions
  • Recursion and Nested Lists · 100 questions
  • Recursive Sorting · 100 questions

More UAlberta courses

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