CSC234 - Exam 2


Read all questions before beginning. You will have until 1pm Monday to finish this exam. You are not allowed to use the internet in general for this exam, only what is linked from this page and the Java API. You may use your text and course notes. You are bound by the Honor Code for this exam, which you need to sign. Show your work on all problems for full credit.

Turn a sheet with Q1-Q5, your signature and the honor code for the whole exam.

Question 1

Draw the state of the memory in Java after executing the following commands with the ListNode class. You should do this by hand, not using the computer to find the answer. Show the state after each command for full credit.

ListNode front = new ListNode(4, null);
ListNode temp = front;
front = new ListNode(8, front);
front = new ListNode(16, front);
front.getNext().setNext(front.getNext());
front.getNext().getNext().getNext().getNext().setNext(new ListNode(23, null));
front.setNext(front.getNext().getNext());
temp.setNext(front);
front = temp;

Question 2

Use the following preorder and inorder traversal information to construct the correct binary tree. (note this is not a binary search tree, just a binary tree)

Question 3

What will be the state of the BinarySearchTree below after

Question 4

What is the best way to order the following Strings for insertion into a BinarySearchTree if you want to minimize height?

Question 5

What data structure (Queue, Stack, List, BinarySearchTree) we discussed in class would be the most efficient for you use in each situation below and why?