Sp03Final

# Sp03Final - Points off 1 2 3 4 Admin Total off Net Score CS...

This preview shows pages 1–5. Sign up to view the full content.

Points off 1 2 3 4 Admin Total off Net Score CS 307 – Final Exam– Spring 2003 Name____________________________________ Last 4 digits of SSN / Student ID ______________ Section Leaders Name ___________________________ Instructions: 1. There are 4 questions on this test. Question 1 is worth 40 points; all others are worth 20 points each. 2. You have 3 hours to complete the test. 3. You may not use a calculator. 4. When code is required, write Java code. 5. You may not use any classes or methods from the Java Standard Library other than the ones specifically mentioned on each question. You may native / built in arrays on any and all questions if you wish. 6. The style guide is not in effect except where noted 7. Please make your answers legible. 1. Short answer questions. (2 points each) Write the answer to each question in the space provided. If code results in an error indicate if it is a compile error or runtime error. Recall that when asked for Big O your answer should be the most precise Big O function. For example Selection Sort has an average case Big O of O(N^2), but per the formal definition of Big O it is technically correct to say Selection Sort also has a Big O of O(N^3). On this test I want the most precise Big O function. (Closest without going under.) A. The following numbers are inserted in the order shown into a binary search tree with no checks to ensure or maintain balance. The tree is initially empty. Draw the resulting tree. 101 -12 59 37 91 201 CS 307 – Final Exam – Spring 2003 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
For parts B, C, and D consider the following binary tree. For each question assume when a node is processed the value in the node is printed out by the statement: System.out.print( currentNode.getData() + " " ); B. What is the output of a preorder traversal of the tree? ____________________________________________________ C. What is the output of an inorder traversal of the tree? ____________________________________________________ D. What is the output of a postorder traversal of the tree? ____________________________________________________ E. Is the tree on page 2 a binary search tree? CS 307 – Final Exam – Spring 2003 2 19 11 113 131 7 5 17 61 root of tree 151
______________________ For questions F and G consider the following Queue class public class Queue { // create an empty queue public Queue() // add this element to the back of the queue public void enqueue(int x) // access the front element of the queue public int front() // remove front element of queue public void dequeue() // returns number of items in queue public int size() } F. What is the output of the following code: Queue q = new Queue(); q.enqueue(12); q.enqueue(13); q.enqueue(q.front()); q.enqueue(q.front()); q.dequeue(); q.enqueue(25); for(int i = 0; i < 3; i++) { System.out.print( q.front() + " " ); q.dequeue(); } ________________________ CS 307 – Final Exam – Spring 2003 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
G. What is the output of the following code: Queue q = new Queue(); q.enqueue(3); for(int i = 1; i < 17; i *= 2)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/30/2010 for the course CS 307 taught by Professor Scott during the Spring '08 term at University of Texas.

### Page1 / 16

Sp03Final - Points off 1 2 3 4 Admin Total off Net Score CS...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online