Sample ECE 312 questions
  1. Linked Lists · Multiple choice · 2 marks

    Node* mystery(Node* h) {
        if (h == nullptr || h->next == nullptr)
            return h;
        Node* second = h->next;
        h->next = mystery(second->next);
        second->next = h;
        return second;
    }

    head points to the list 1→2→3→4→51 \to 2 \to 3 \to 4 \to 5. What is the list that mystery(head) returns?

    1. 2→1→4→3→52 \to 1 \to 4 \to 3 \to 5

    2. 2→1→3→4→52 \to 1 \to 3 \to 4 \to 5

    3. 1→3→2→5→41 \to 3 \to 2 \to 5 \to 4

    4. 5→4→3→2→15 \to 4 \to 3 \to 2 \to 1

    Show solution

    Answer: (A)

    (A). The function swaps each pair of neighbours and leaves a final unpaired node where it is. mystery(1,2,3,4,5) makes 2 the new front; 1 then points to the result of mystery(3,4,5), which is 4→3→54 \to 3 \to 5, because that call swaps 3 and 4 and then hits the base case at the lone 5.

  2. Recursion · Short answer · 2 marks

    The function below is intended for n >= 1, and the caller never passes a smaller value on purpose.

    int fact(int n) {
        if (n == 1) return 1;
        return n * fact(n - 1);
    }

    A user calls fact(0). What happens, and why? What one-character change to the condition makes the function safe for every n?

    Show solution

    The argument goes 0,−1,−2,…0, -1, -2, \ldots and never equals 11, so the base case is never reached: the recursion does not stop and eventually overflows the call stack (the program crashes). Changing the condition to n <= 1 fixes it; the base case now covers every argument that cannot be reduced further.

  3. Dynamic Memory, the Big Three and RAII · Multiple choice · 2 marks

    The class Buf defines a constructor Buf(int n), a copy constructor, a copy assignment operator and a destructor. Consider this code, with line numbers.

    void show(Buf b);
    
    Buf a(3);
    Buf b = a;
    Buf c(a);
    Buf d(2);
    d = a;
    show(a);

    On which lines is the copy constructor called?

    1. Lines 4, 5 and 8

    2. Lines 4 and 5 only

    3. Lines 4, 5, 7 and 8

    4. Lines 4, 5, 6 and 8

    Show solution

    Answer: (A)

    (A) Line 4 initialises a new object from an existing one, so it is a copy construction even though it uses =. Line 5 is the same. Line 7 assigns to an existing object, which calls the copy assignment operator. Line 8 passes a by value, so the parameter b is copy-constructed. Lines 3 and 6 call Buf(int).

  4. Binary Trees and Binary Search Trees · Short answer · 2 marks

    A binary search tree contains the keys 8, 3, 1, 6, 4, 7, 10, 14, 13, and its preorder traversal is exactly this sequence. If the root (8) is deleted, which two keys could take its place so that the result is still a binary search tree? Say which is the predecessor and which the successor.

    Show solution

    7 and 10. The preorder says 3, 1, 6, 4, 7 form the left subtree (all smaller than 8) and 10, 14, 13 the right subtree. The inorder predecessor is the largest key in the left subtree, 7 (go to 3, then right to 6, then right to 7); the inorder successor is the smallest key in the right subtree, 10 (the right child itself, as it has no left child).

  5. Big-O and Sorting · Predict the output · 2 marks

    What does this program print? Assume the needed headers and using namespace std;. Within each sort, no two words tie.

    bool byLength(const string& a, const string& b) {
        return a.size() < b.size();
    }
    
    bool byLastLetter(const string& a, const string& b) {
        return a.back() < b.back();
    }
    
    void show(const vector<string>& w) {
        int n = w.size();
        for (int i = 0; i < n; i++)
            cout << w[i] << (i + 1 < n ? " " : "\n");
    }
    
    int main() {
        vector<string> w = {"cherry", "fig", "bananas", "kiwi", "apple"};
        sort(w.begin(), w.end(), byLength);
        show(w);
        sort(w.begin(), w.end(), byLastLetter);
        show(w);
    }
    Show solution
    fig kiwi apple cherry bananas
    apple fig kiwi bananas cherry

    The first sort orders by length 3, 4, 5, 6, 7. The second sort ignores the first order completely and orders by last letter: e (apple), g (fig), i (kiwi), s (bananas), y (cherry).

About ECE 312 practice exams

ECE 312 practice exams

Software Design and Implementation I · The University of Texas at Austin (UT Austin, UT, UTexas) · also written ECE312

Make a free, printable ECE 312 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 ECE 312 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 ECE 312 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

  • Linked Lists · 50 questions
  • Stacks and Queues · 50 questions
  • Recursion · 50 questions
  • Classes, ADTs and Operator Overloading · 50 questions
  • Dynamic Memory, the Big Three and RAII · 50 questions
  • Templates, the STL and Iterators · 50 questions
  • Binary Trees and Binary Search Trees · 50 questions
  • Hash Tables · 50 questions
  • Big-O and Sorting · 50 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
  • C S 313E Elements of Software Design
  • 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
  • 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.