Sample study questions Exam 1 (Friday Feb 6th)
Sample COP3530 questions for EXAM #1, Spring 1998
The following are sample exam problems for you to practice on.
Actual topics we covered from text are all of Ch3, Ch4, and Ch5
(except explicit discussion of the ADT Priority Queue.
THIS IS INTENDED AS A STARTING POINT TO HELP YOU STUDY FOR THE EXAM.
THERE IS NO GUARANTEE THAT THIS COVERS EVERY POSSIBLE TOPIC, BUT
IT WILL HELP GET YOU IMMERSED. NO SOLUTION WILL BE PROVIDED.
YOU ARE ENCOURAGED TO HELP EACH OTHER STUDY AND
TO DECIDE ANSWERS YOURSELVES. HAVE FUN!
PLEASE DO NOT ASK FOR A SOLUTION TO THIS EXERCISE.
================================================================
Draw a sketch showing data in boxes which demonstrate
the difference between primitive data and reference types of data.
Choose specific data types to illustrate the concept.
Explain what happens when the reserved word "new" is used in Java.
What types of data require the use of "new"?
What types of data do not require the use of "new"?
Why...why not?
If we want to create a String type variable and make it give it initially hold
"Go gators!", how can this be done without explicitly calling "new"
What is the difference between these two declarations:
int x ; Integer x ;
What is the difference between a primitive class and a wrapper class?
Consider these two declarations, double x ; and double[] y;
Draw a picture representing the difference betweenthis primitive type
variable and this reference type variable.
Briefly explain each picture.
Define a class of your own which
1) contains a main() method,
2) would compile and run,
3) uses an array of values of type Double
4) demonstrations the declaration and assignment of data values, and
5) shows that you know the syntax of a "for" loop.
What parts make up every Abstract Data Type (ADT)?
Make up a simple ADT and
a) show its declaration as a Java interface;
b) make up an implementation for it, and
c) write a short Test class which has a main()
in which you instantiate and test the capabilities
Implement the body of this procedure below, for our array-based
implementation of the Java interface "Sequence" (as introduced in Lab):
public Object remove(int position)
{ ......
...... you provide this code ........
}
(Background: This was presented in lecture and code was made available on the
web and in lecture. That implementation used two instance variables:
private Object[] listArray ; ...and private int numObjectsInList ;
You should use these in your code.)
DISCUSS THIS POSITION:
What's the use of defining an interface? After all, we can always just define a
class anyway we want to. They are not really necessary!
Draw box and pointer diagrams for these three declarations & initializations:
String F = "first";
String S = "second";
String X = F + S ;
Given this declaration: class Node {String s ; Node next ;}
1) Draw a sketch of an instantiation of Node.
2) Draw a box-and-pointer diagram for the situation after each of
these three lines of statements:
Node N = new Node ; N.s = "Go" ; N.next = null ;
N.next = new Node ; N.next.s = "Gators" ; N.next.next = null ;
Node T = N.next ; T.next = N ; N.next = null ;
Write a Java method to insert a Node at position N
in a linked list L with nodes that are of class
class Node { Object data; Node link; }
How would you write a procedure to delete a node at position 3
from a several linked lists of the type just described above?
Write a reasonable procedure to return a String from an entire
linked list of the type described above.
Assuming a linked implementation of a Sequence (such as you have used
in lab and in the hws) present a Java method for traversing the list,
removing all nodes that contain a given predefined data Object.)
Implement a method within a class declared as: factorial(Double n):
It must return the computed factorial of its nonnegative argument.
a) Present a Java class/method to return x^n, where x,n are positive integers.
( ^ denotes exponentiation)
b) What is the "efficiency" of your solution to the above x^n algorithm
expressed in terms of Big O?