| CIT
594 Exam Questions Spring 2007, David Matuszek |
I have added some questions to groups in bold. The new groups are
after the horizontal line. The first topic not covered in the midterm
exam is Backtracking.
Stack class extends the Vector class. Why
does your instructor think this is a bad design? class Line {
private double x1, y1; // first
point
private double x2, y2; // second
point
private double length; // length
of line
// assorted constructors, methods,
etc.
}'$' to the end
of the input string. Why?Subarray class, such as you might use in a Quicksort program.
Tell what constructors and methods you would supply. Do not write an actual
code.void method?void method whose purpose is to print
results? toString in almost every class you
write?Set s = new HashSet() generally preferable to HashSet
s = new HashSet() ? Stack class? Stack class?StackQueueDeque Queue methods add and offer? (Be sure
to tell which is which.)Queue methods
remove and poll? (Be sure to tell which is which.)Queue methods peek and element? (Be sure to tell which is which.) Stack methods empty and isEmpty?
(Be sure to tell which is which.)Stack methods peek and pop?
(Be sure to tell which is which.)Stack methods (excluding stack creation)?
Give complete method signatures.Stack methods empty() and isEmpty()?Deque class
extend ArrayList,
or just use an ArrayList as a field?
Defend your answer.Collection interface?Set, List, Map Set, List, MapSet but keeps elements in order?Map but keeps keys in order?Set interface extends what other interface?List interface extends what other interface?Collection method boolean add(E o) return
true?Collection method boolean remove(E o) return
true?List<String> list = new List<String>();List<String> list = new ArrayList<String>();ArrayList<String> list = new List<String>();ArrayList<String> list = new ArrayList<String>();Collection interface?
boolean add(E o) boolean addAll(Collection<? extends E> c) void add(int index, E element)Iterator<E> iterator() Set<E> toSet(Collection<E>) <T> T[] toArray(T[] a) return a new array?LinkedList<String> named list into
the array String[] strings. Collection interface:
addcontainscontainsAlliteratorsingletonCollection interface
are "optional." If you were implementing a Collection and
did not want to support an optional method, how would you do this? Collection interface? Arrays, TreeSets, TreeMaps,
ArrayLists, LinkedLists, Stacks.Stack into an array? List? Set extends Collection, or Set implements
Collection? shuffle() method? Iterator<E> interface.Iterator method void
remove()?Iterator method throw a ConcurrentModificationException? iterator() method.ListIterator interface that are not also in the
Iterator interface.for (Item item : items) {} is
syntactically legal, what interface
must the class of items implement? Set method that
implements it.
addAll |
difference | |
contains |
intersection | |
containsAll |
member | |
removeAll |
subset | |
retainAll |
union |
Set interface that are not in the Collection interface?Set set1 contains the strings "a", "b", "c", "d", "e" and Set
set2 contains the strings "a", "e", "i", "o", "u".
What value is returned by each of the following calls (if done separately)?
set1.addAll(set2)set1.contains(set2)set1.containsAll(set2)set1.removeAll(set2)set1.retainAll(set2)Set set1 contains the strings "a", "b", "c", "d", "e" and Set
set2 contains the strings "a", "e", "i", "o", "u".
What are the contents of set1 and set2 after each of the following calls (if done separately)?
Call set1 set2 set1.addAll(set2)set1.contains(set2)set1.containsAll(set2)set1.removeAll(set2)set1.retainAll(set2)
Set, but you shouldn't. Why not?Set interface.SortedSet?SortedSet interface
but not inherited from any superinterface.SortedSet named mySet.SortedSet named
mySet.SortedSet?Employee with fields String name and int age ,
and you put Employee objects into a SortedSet. Will the employees be sorted
by name, or by age?Employee with a field long
id ,
and you put Employee objects into a SortedSet. How
do you ensure that the employees are sorted by id?SortedSet interface? List interface.List interface extends what two other interfaces?List method must you call in order to obtain a ListIterator object? ListIterator lets you add, remove, and
replace elements in a List object.ListIterator let you move backwards through a list.
Give their complete signatures, including return types.List named list.LinkedList or an ArrayList, and why?List to implement a deque. Should you
use a LinkedList or an ArrayList, and why?numbers is an ArrayList<Double>, is the call numbers.add(3.33) syntactically
valid? Why or why not?list is a List<String>, and you call the method list.add("abc"), where
in list is "abc" added? ArrayList rather
than an array. Map interface.get and put methods of the Map interface.entrySet method of the Map interface.values() method of the Map interface?myMap,
one entry per line, as key = value.HashMap that uses Strings as keys and Doubles
as values.hm is a HashMap and tm is a TreeMap, how can you most easily test
whether they both have the same key-value pairs?keySet method of a Map returns a "view"? SortedMap keep in sorted order: keys, values,
or both?SortedMap?SortedMap interface?SortedMap?SortedMap? (Answer in
English, don't write code.) <small integer>, where
a "small integer" is a number in the range 0 to 99.<identifier>, where an "identifier" consists
of a letter followed by any number of letters and/or digits.return statement. You
can assume that any other nonterminals you need have already been defined.if statement.
You can assume that any other nonterminals you need have already been defined. while loop. You
can assume that any other nonterminals you need have already been defined.stuff as an ArrayList containing Strings. stuff as an ArrayList containing
a List of Strings.stuff as
an ArrayList that may contain any kind of Object. new ArrayList<Object>() and new ArrayList<?>() ?least that
takes a Set of values of type E and returns a
value of type E. boolean
addAll(Collection<?
extends E> c)?Stack variable that holds only String objects. list is declared as an ArrayList<List<String>>,
what kind of parameter can be given to list.add(parameter)? min to return the
smallest number in an array of doubles. sum to return sum
of an array of doubles.log that returns the
number of times its input int parameter must be divided by 2 in
order to get 0.int myArray[][] = new int[3][8] , what
is the type of myArray[1]?int myArray[][] = new int[3][8] ,
what value is in myArray[1]? int[][] array named ragged, having
100 rows, where the even-numbered rows all have 10 elements and the odd-numbered
rows all have five elements.int[][] array named ragged,
having 100 rows, where the number of elements in each row is the same as
its row number.obj is an Object, how can you test if it's an array? new String[10][]. Subarray ADT, what fields would it need? binarySearch methods? private?value field
in the nodes private?if statement as a tree, should the parentheses
be represented in the tree? Why or why not?O(3n4 - 6n2 + 1009). if (x % 2 == 1) x = x - 2;while (x % 2 == 1) x = x - 2;for (int i = 0; i < a.length; i++) a[i] = i * i;for (int i = 0; i < 100; i++) a[i] = i * i;if (x + y > 100) z = Math.max(x, y);if (x * y < factorial(y)) y = x;if (x < y) x = y; else x = factorial(y); O(log n), O(n log n), O(n),
O(1), O(2n), O(n2), O(n2 log n). r rows
and c columns, finds the minimum value in each column, and
returns the maximum of those minima. How long (Big-O notation) do you expect
this method to take?N by 2 before you get 1?N by 3.322, what
do you get? log2N = x, then N = _______.
Comparator rather than Comparable? compareTo method should
be "consistent with equals"?hashCode method
should be "consistent with equals"?Employee objects into a HashSet, the Employee class
must override both __________ and __________. Comparator class to compare Employee objects
by their public id fields.Employee objects.
Comparable, should you implement it in the Employee class, or in a separate class? Why?Comparator, should you implement it in the Employee class, or in a separate class? Why?SortedSet<Object>
set = new SortedSet<Object>(); int[] x;
and what are its initial contents?class MyList { int value; MyList next; ...} with
a constructor MyList(int value, MyList next) :
class MyList { int value; MyList left,
right; ...} with
a header cell MyList(0, first_element, lastElement).
Books into a HashTable,
what two methods must the Book class implement? (Give
complete signatures.)HashMap for inserting and looking up items?
(Give complete signatures.)remove method, how is the hash
table most likely implemented? Why? hashCode() method must satisfy in order
to be valid. hashCode() method should satisfy in
order to be a "good" hash code.hashCode() method? int hashCode() { return -1; } hashCode() method to return the same value for
a particular object every time the program is run?HashMap?Hashtable differ from a HashMap?
(Be sure to tell which is which.)boolean symbol(String s) as defined
in the Recognizer assignment.
boolean addOp() that will recognize a "+" or
a "-". boolean notEquals() that will recognize a "!" followed by a "=".boolean dots() that will recognize
a "." followed by an optional second ".". boolean dashes() that will recognize
one or more consecutive "-" symbols. false? partion method has already been written. f(N)
= g(N) + h(N) ,
what are N, g, h, and f? Dog fido = new Dog() ? N nodes and E edges, how many nodes and
edges are in a spanning tree of that graph?N nodes and N edges,
how many different spanning trees are there for that graph? (Hint:
give a range of values.)[This lecture was primarily intended as an example of using linked lists, so there's not much I want to ask.]
java.util.prefs.*.Preferences object behaves like what well-known
data structure?Preferences method get(key, xxx) , what is the second parameter
used for? Preferences objects for several different programs, how
does Java know which one to use?Preferences file stored? Preferences object,
then later ask for the value of that preference? Plex? Plex? Plex implements a node in a regular (non-hyper) graph, what are
the contents of each field of that Plex? | • any digit | • zero or more digits | • any letter |
| • any non-digit | • one or more digits | • any lowercase letter |
| • an optional digit | • two or more digits | • any non-letter |
| • an optional non-digit | • any character except a newline | • either "abc" or "xyz" |
| • any three-digit sequence | • the word "cat" in any mixture of uppercase and lowercase letters | • Any one character except a letter |
Cloneable interface?Cloneable? static in front of Random random
= new Random() . Why?javap command do?