EECS 2101 Mock Final 1
15 questions · 37 points · 1 hour · Java · 3 attempts
A one-hour practice final for a second-year data structures course in Java. It covers stacks, queues, linked lists, binary search trees, heaps, hash tables and sorting, with multiple choice, short answer, written explanations and two 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
- Stacks and queues
- Circular array queues
- Singly linked lists
- Binary search trees and AVL trees
- Min-heaps
- Hash tables and linear probing
- Merge sort and stable sorting
- Abstract data types
- Big-O and counting loop steps
- Amortized running time
- Recursion on trees
What is inside
- Question 1Multiple choice · 2 pointsShown below
- Question 2Multiple choice · 2 points
- Question 3Multiple choice · 1 point
- Question 4Multiple choice · 1 point
- Question 5Multiple choice · 1 point
- Question 6Multiple choice · 1 point
- Question 7Multiple choice · 1 point
- Question 8Multiple choice · 1 point
- Question 9Short answer · Java · 2 points
- Question 10Short answer · 2 points
- Question 11Short answer · 2 points
- Question 12Long answer · 6 points
- Question 13Long answer · 5 pointsShown below
- Question 14Code (typed) · Java · 5 points
- Question 15Code (typed) · Java · 5 pointsShown below
Sample questions
These questions are from the exam itself, shown as you would read them while sitting it.
Question 1
An empty stack performs push(4), push(9), pop(), push(2), then peek(). What does peek() return?
Choose one answer.
- 4
- 9
- 2
- The stack is empty
Question 13
A queue uses two initially empty stacks named incoming and outgoing. Each stack push or pop takes O(1) time. Enqueue pushes onto incoming. Dequeue pops from outgoing; if outgoing is empty, it first moves every item from incoming to outgoing and then pops from outgoing. Assume dequeue is called only when the queue is nonempty.
Explain why this implementation returns items in FIFO order and why items should be transferred only when outgoing is empty. Explain how a single dequeue can take O(n) time, where n is the number of queued items, while the amortized time per queue operation over a sequence starting empty is O(1).
You write your answer in a few paragraphs.
Question 15
Implement countLeaves(TreeNode root) recursively. A leaf is a node whose left child and right child are both null. Return the total number of leaves in the tree. Return 0 when root is null.
The tree is finite and has no cycles or shared nodes. Do not modify the tree or use collections. Complete only the method in the starter code; no main method, input reading, or printing is required.
Examples: An empty tree returns 0. A tree containing only its root returns 1. A root with two children that are both leaves returns 2. A root with only a left child, where that child is a leaf, returns 1.
class TreeNode {
int key;
TreeNode left;
TreeNode right;
TreeNode(int key) {
this.key = key;
}
}
class Solution {
public int countLeaves(TreeNode root) {
// TODO: implement this method recursively.
return 0;
}
}You write the code in an editor. It is read and marked by hand.
The other 12 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