CJCoding With Joseph
15free / daySign inCreate account

← All mock exams

EECS 2101 Mock Final 2

25 questions · 64 points · 2 hours · Java · 3 attempts

A two-hour practice final for a second-year data structures course in Java, a step harder than Mock Final 1. It covers doubly linked lists, stacks, queues, heaps, AVL trees, hashing, sorting, recursion and proofs, with three Java coding questions.

Who it is for: Second-year data structures in Java, for example EECS 2101 at York University

Sit this exam and have Joseph mark it by hand, with feedback on every question.

Sitting mock exams and having them marked is part of every paid plan (Practice, Tutor, and Lock In), from $29 a month.

What it covers

  • Doubly linked lists and their invariants
  • Generic classes in Java
  • Stacks, queues and deques
  • Postfix evaluation with a stack
  • Circular array queues
  • Heaps and priority queues
  • Binary search trees and AVL trees
  • Hash tables with separate chaining
  • Quick sort and merge sort
  • Big-O proofs and loop invariants
  • Recursion and memoization
  • BFS and DFS

What is inside

  1. Question 1Multiple choice · 1 point
  2. Question 2Multiple choice · Java · 1 point
  3. Question 3Multiple choice · 1 point
  4. Question 4Multiple choice · 1 point
  5. Question 5Multiple choice · 2 pointsShown below
  6. Question 6Multiple choice · 1 point
  7. Question 7Multiple choice · 1 point
  8. Question 8Multiple choice · 1 point
  9. Question 9Multiple choice · 1 point
  10. Question 10Multiple choice · 1 point
  11. Question 11Multiple choice · 2 points
  12. Question 12Multiple choice · 1 point
  13. Question 13Short answer · Java · 2 points
  14. Question 14Short answer · 2 points
  15. Question 15Short answer · Java · 3 points
  16. Question 16Short answer · 3 pointsShown below
  17. Question 17Short answer · 3 points
  18. Question 18Short answer · 2 points
  19. Question 19Short answer · 2 points
  20. Question 20Long answer · Java · 6 points
  21. Question 21Long answer · 6 points
  22. Question 22Long answer · Java · 5 points
  23. Question 23Code (typed) · Java · 6 points
  24. Question 24Code (typed) · Java · 5 pointsShown below
  25. Question 25Code (typed) · Java · 5 points

Sample questions

These questions are from the exam itself, shown as you would read them while sitting it.

Question 5

Multiple choice · 2 points

A stack is used to evaluate the postfix expression 9 3 1 - 2 * -, reading it from left to right. Each number is pushed. Each operator pops two values, applies the operator, and pushes the result. What value is left on the stack at the end?

Choose one answer.

  • 5
  • 13
  • -5
  • -13

Question 16

Short answer · 3 points

A browser history uses two stacks, backStack and forwardStack, plus currentPage (null at first):

  • visit(url): if currentPage is not null, push it onto backStack; make url the current page; clear forwardStack.
  • back(): if backStack is not empty, push currentPage onto forwardStack and pop backStack into currentPage. Return currentPage.
  • forward(): if forwardStack is not empty, push currentPage onto backStack and pop forwardStack into currentPage. Return currentPage.

Run: visit("A"), visit("B"), visit("C"), back(), back(), forward(), visit("D"), back().

Give the value returned by each back() and forward() call, in order. Then give the final current page and the contents of both stacks (bottom to top).

You type a short answer.

Question 24

Code (typed) · Java · 5 points

Implement insert(TreeNode root, int key) recursively for a binary search tree with distinct keys: smaller keys go in the left subtree, larger keys in the right subtree. Return the root of the updated tree.

If the tree is empty (root is null), return a new node holding key. If key is already in the tree, leave the tree unchanged and return root. Do not use loops, collections, or a parent field. Complete only the method in the starter code; no main method, input reading, or printing is required.

Examples:

  • Empty tree, insert 8: return a new node holding 8.
  • Tree with only the root 8, insert 3: 3 becomes the left child of 8, and the method returns the node 8.
  • Tree 8 with left child 3, insert 5: 5 becomes the right child of 3.
  • Tree with only the root 8, insert 8: the tree is unchanged.
Your editor starts with
class TreeNode {
    int key;
    TreeNode left;
    TreeNode right;

    TreeNode(int key) {
        this.key = key;
    }
}

class Solution {
    public TreeNode insert(TreeNode root, int key) {
        // TODO: implement this method recursively.
        return root;
    }
}

You write the code in an editor. It is read and marked by hand.

The other 22 questions are for the sitting itself.

Sit this exam and have Joseph mark it by hand, with feedback on every question.

Sitting mock exams and having them marked is part of every paid plan (Practice, Tutor, and Lock In), from $29 a month.

How it is marked

Joseph marks every attempt by hand. You get your score, the points and written feedback for each question, and what to focus on next. How a mock exam works