Sample C S 313E questions
  1. Classes, Encapsulation and Representation Invariants · Predict the output · 3 marks

    Write the output of the code below. If the code raises an error, write its type on its own line and stop.

    class Shelf:
        """A shelf of books."""
    
        def __init__(self, books: list[str]) -> None:
            self._books = books
    
        def __len__(self) -> int:
            return len(self._books)
    
        def __contains__(self, title: str) -> bool:
            return title in self._books
    
        def __getitem__(self, i: int) -> str:
            return self._books[i]
    
    s = Shelf(['Emma', 'Dune', 'Kim'])
    print(len(s))
    print('Dune' in s, 'dune' in s)
    print(s[1], s[-1])
    for i in range(len(s)):
        print(s[i][0], end='')
    print()
    print(s[3])
    Show solution
    3
    True False
    Dune Kim
    EDK
    IndexError

    s[3] calls __getitem__(3), which indexes a list of length 3.

  2. Stacks, Queues and Exceptions · Write code · 3 marks

    Complete the function using one additional Stack and no lists.

    def remove_all(s: Stack, item: object) -> None:
        """Remove every occurrence of item from s. The other items remain in
        s in their original order.
    
        >>> s = Stack()
        >>> for x in [1, 2, 1, 3]:
        ...     s.push(x)
        >>> remove_all(s, 1)
        >>> s.pop()
        3
        >>> s.pop()
        2
        >>> s.is_empty()
        True
        """
    Show solution
        temp = Stack()
        while not s.is_empty():
            x = s.pop()
            if x != item:
                temp.push(x)
        while not temp.is_empty():
            s.push(temp.pop())
  3. Linked Lists · Predict the output · 3 marks

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

    lst = LinkedList([3, 1, 4, 1, 5])
    prev = lst._first
    curr = prev.next
    while curr is not None:
        if curr.item == 1:
            prev.next = curr.next
        else:
            prev = curr
        curr = curr.next
    print(lst)
    print(prev.item)
    Show solution
    [3 -> 4 -> 5]
    5

    Each removed node is skipped by prev.next, while prev only advances past nodes that are kept.

  4. Trees · Write code · 2 marks

    Implement the method below according to its docstring.

    class Tree:
        """A recursive tree.
    
        === Private Attributes ===
        _root: the item at the root, or None if empty
        _subtrees: the subtrees of this tree
        """
        _root: Any | None
        _subtrees: list[Tree]
    
        def count_leaves(self) -> int:
            """Return the number of leaves in this tree.
    
            >>> Tree(None, []).count_leaves()
            0
            >>> Tree(7, []).count_leaves()
            1
            >>> t = Tree(1, [Tree(2, [Tree(4, [])]), Tree(3, []), Tree(5, [])])
            >>> t.count_leaves()
            3
            """
    Show solution
    def count_leaves(self) -> int:
        if self.is_empty():
            return 0
        elif self._subtrees == []:
            return 1
        else:
            total = 0
            for subtree in self._subtrees:
                total += subtree.count_leaves()
            return total
  5. Recursive Sorting · Predict the output · 3 marks

    The following version of mergesort prints a line before and after its recursive work. Assume merge is the course function.

    def mergesort(lst: list) -> list:
        if len(lst) < 2:
            return lst[:]
        mid = len(lst) // 2
        print('split', lst[:mid], lst[mid:])
        left = mergesort(lst[:mid])
        right = mergesort(lst[mid:])
        result = merge(left, right)
        print('merged', result)
        return result
    
    mergesort([4, 7, 1, 3, 2])

    Write the output, in order, one line per print call.

    Show solution
    split [4, 7] [1, 3, 2]
    split [4] [7]
    merged [4, 7]
    split [1] [3, 2]
    split [3] [2]
    merged [2, 3]
    merged [1, 2, 3]
    merged [1, 2, 3, 4, 7]

    The left half is always completely sorted (all its splits and merges) before the right half starts.

About C S 313E practice exams

C S 313E practice exams

Elements of Software Design · The University of Texas at Austin (UT Austin, UT, UTexas) · also written CS313E

Make a free, printable C S 313E 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 900 original questions and skips the ones you have already seen.

Looking for C S 313E past exams?

Start with the past exams and tests your instructor or the UT Austin library shares: they show what your course actually asks. Most courses only have a few, so once you have worked through them, make fresh C S 313E 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
  • Trees · 100 questions
  • Binary Search Trees · 100 questions
  • Recursive Sorting · 100 questions

More UT Austin courses

  • M 408C Differential and Integral Calculus
  • M 408K Differential Calculus
  • M 408L Integral Calculus
  • M 408M Multivariable Calculus
  • M 340L Matrices and Matrix Calculations
  • M 362K Probability I
  • M 378K Introduction to Mathematical Statistics
  • SDS 301 Elementary Statistical Methods
  • SDS 302F Foundations of Data Analysis
  • C S 303E Elements of Computers and Programming
  • CH 301 Principles of Chemistry I
  • PHY 301 Mechanics
  • PHY 302K General Physics Technical Course: Mechanics, Heat, and Sound
  • BIO 311C Introductory Biology I
  • PSY 301 Introduction to Psychology
  • ECO 304K Introduction to Microeconomics
  • ECO 304L Introduction to Macroeconomics
  • ACC 311 Fundamentals of Financial Accounting
  • ACC 312 Fundamentals of Managerial Accounting
  • C S 312 Introduction to Programming
  • C S 314 Data Structures
  • ECE 312 Software Design and Implementation I
  • M 427L Advanced Calculus for Applications II
  • PHY 303K Engineering Physics I
  • SDS 321 Introduction to Probability and Statistics
  • C E 311S Probability and Statistics for Civil Engineers
  • M E 335 Engineering Statistics
  • BME 335 Engineering Probability and Statistics

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