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