{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

midterm2Spring02 - Points off 1 2 3 4 5 6 Total off Net...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Points off 1 2 3 4 5 6 Total off Net Score CS 307 – Midterm 2 – Spring 2002 Name____________________________________ Last 4 digits of SSN / Student ID ______________ Class Unique ID ___________________________ Instructions: 1. There are 6 questions on this test. 2. You will have 2 hours to complete the test. 3. You may not use a calculator on the test. 4. When code is required, write Java code. 5. The style guide is not in effect. 6. Ensure your answers are legible. 7. When writing code you may not use any methods or classes from the Java Standard Library except as noted and the System.out.print, System.out.println, and the equals method. 1. (2 points each, 20 points total) Java Mechanics and theory. If an error would occur answer "syntax error" or "runtime error" depending on what type of error it would be. A. What is the average case Big O for inserting N items into an initially empty Linked List that is to be maintained in sorted order? _____________________________________________________________________________ B. What is the Big O for deleting a node from the end of a singly linked list that has a head and tail reference? _____________________________________________________________________________ CS 307 – Midterm 2 – Spring 2002 1
Background image of page 1

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

View Full Document Right Arrow Icon
C. Consider the following code from class M2: public static int stone(int n) { if(n <= 0) return 3; else return n + stone( n – 2); } What is printed out by the following code? System.out.println( M2.stone(8) ); _____________________________________________________________________________ D. Consider the following code from class M2: public static int mav(int m) { if(m <= 0) return 2; else return 2 + mav(m – 1) + mav(m – 2); } What is printed out by the following code? System.out.println( M2.mav(5) ); _____________________________________________________________________________ E. Given a positive integer N, what is the Big O of M2.mav( N ) from question 1.D? _____________________________________________________________________________ CS 307 – Midterm 2 – Spring 2002 2
Background image of page 2
F. Consider a queue of ints that uses a native array of ints, myContainer , to store the elements of the queue. myContainer starts with a capacity of 5. It is resized only when necessary. The queue uses wraparound as discussed in class. Draw myContainer and show its contents after the following code is executed. Be sure to clearly label the front and back elements of the queue . Queue q = new Queue(); q.enqueue( 12 ); q.enqueue( 9 ); q.dequeue(); q.enqueue( 73 ); q.enqueue( 81 ); q.dequeue(); q.enqueue( 55 ); q.dequeue(); q.enqueue( 10 ); _____________________________________________________________________________ G. Consider the following code: for( int i = 0; i < N; i++ ) for( int j = 1; j < N; j *= 2 ) west( i ); method west has a Big O of O( N ).
Background image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}