Sample EECS 1516 questions
  1. Classes, Encapsulation and Representation Invariants · Multiple choice · 1 mark

    class Point:
        """A point."""
    
        def __init__(self, x: int, y: int) -> None:
            self.x = x
            self.y = y
    
    pts = [Point(1, 2), Point(3, 4)]

    Point does not define __eq__. Which expression evaluates to True?

    1. Point(1, 2) in pts

    2. pts.count(Point(3, 4)) == 1

    3. pts.index(pts[1]) == 1

    4. pts == [Point(1, 2), Point(3, 4)]

    Show solution

    Answer: (C)

    (C). Without __eq__, == (and therefore in, count and list equality) falls back to identity. Only pts[1] itself is the same object as an element of pts.

  2. Inheritance, Abstract Classes and Polymorphism · Predict the output · 2 marks

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

    class Shape:
        def __init__(self, name: str) -> None:
            print('Shape init', name)
            self.name = name
    
    class Polygon(Shape):
        def __init__(self, name: str, sides: int) -> None:
            print('Polygon init')
            super().__init__(name)
            self.sides = sides
            print('Polygon done')
    
    class Square(Polygon):
        def __init__(self, side: int) -> None:
            super().__init__('square', 4)
            print('Square init')
            self.side = side
    
    s = Square(3)
    print(s.name, s.sides, s.side)
    Show solution
    Polygon init
    Shape init square
    Polygon done
    Square init
    square 4 3

    Square.__init__ starts by calling Polygon.__init__, which prints, calls Shape.__init__, and only then finishes. Each print after a super().__init__ call runs after the parent’s body is finished.

  3. Stacks, Queues and Exceptions · Multiple choice · 2 marks

    A programmer writes pop for a stack that may hold any values, including None. When the stack is empty, her pop returns None instead of raising EmptyStackError. What is the main problem?

    1. Returning None is slower than raising an exception

    2. A function that returns None cannot be called from a try statement

    3. The caller cannot tell an empty stack from a stack whose top item is None

    4. Python does not allow a method to return None and a non-None value

    Show solution

    Answer: (C)

    (C). If None can be a legitimate item, the return value None is ambiguous. Raising an exception signals the error through a separate channel that cannot be confused with an item, and cannot be silently ignored.

  4. Linked Lists · Write code · 3 marks

    Implement the method below by exchanging the items stored in the nodes (do not relink nodes). In the examples, a LinkedList prints as [1 -> 2 -> 3] (and as [] when empty).

    class LinkedList:
        def swap_pairs(self) -> None:
            """Swap the items in positions 0 and 1, 2 and 3, and so on. If
            there is an odd number of items, the last item stays where it
            is.
    
            >>> lst = LinkedList([1, 2, 3, 4, 5])
            >>> lst.swap_pairs()
            >>> print(lst)
            [2 -> 1 -> 4 -> 3 -> 5]
            """
    Show solution
            curr = self._first
            while curr is not None and curr.next is not None:
                curr.item, curr.next.item = curr.next.item, curr.item
                curr = curr.next.next
  5. Running Time and Big-Oh · Multiple choice · 2 marks

    What is the running time of the following function in terms of nn?

    def f(n: int) -> int:
        count = 0
        for i in range(n):
            j = n
            while j > 1:
                j = j // 2
                count = count + 1
        return count
    1. O(log⁡n)O(\log n)

    2. O(n)O(n)

    3. O(nlog⁡n)O(n \log n)

    4. O(n2)O(n^2)

    Show solution

    Answer: (C)

    (C). The inner loop halves j each time, so it runs about log⁡2n\log_2 n times for every one of the nn iterations of the outer loop: nlog⁡2nn \log_2 n steps in all.

About EECS 1516 practice exams

EECS 1516 practice exams

Object Oriented Design and Principles using Python · York University (York, YorkU, York U) · also written EECS1516

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

Looking for EECS 1516 past exams?

Start with the past exams and tests your instructor or the York 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 1516 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
  • Linked Lists · 100 questions
  • Trees · 100 questions
  • Running Time and Big-Oh · 100 questions

More York courses

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