Csa HTML
Csa HTML
htm
Question 1
Examine the following code snippet:
(A) 0 1 2 3 4 0 1 2 3 4
(B) 4 2 9 7 3 4 2 9 7 3
(C) 14 12 19 17 13 0 1 2 3 4
(D) 14 12 19 17 13 4 2 9 7 3
(E) 14 12 19 17 13 14 12 19 17 13
Question 2
Consider the following method:
int x = num;
while (x > 0) {
if (x / 10 % 2 == 0)
return x;
x = x / 10;
}
return x;
}
(A) 4
(B) 10
(C) 34
(D) 103
(E) 1034
Question 3
Study the following method:
else
return y;
}
What is the result of the method call pick(false, pick(true, 0, 1), pick(true, 6, 7))?
(A) 0
(B) 1
(C) 3
(D) 6
(E) 7
Question 4
Analyze the following class hierarchy and code:
return "First";
}
}
}
@Override
public String name() {
return "Second";
}
}
return "Third";
}
}
(A) First rules but Second is even betterFirst rules but Second is even better
(B) First rules but Second is even betterFirst rules but Third is even better
(C) First rules but Second is even betterSecond rules but Second is even better
(D) First rules but Second is even betterSecond rules but Third is even better
(E) Second rules but Second is even betterSecond rules but Second is even better
Question 5
Consider the code below:
varA.whoRules();
varB.whoRules();
Which type declarations for SomeType1 and SomeType2 will allow the code to compile
without errors?I. First and ThirdII. Second and SecondIII. Third and Third
(A) I only
(B) II only
(D) I and II
Question 6
Review the following class definitions and statement:
}
}
public class Derived extends Base {
public Derived() {
System.out.print("Derived ");
}
(B) Base
(C) Derived
Question 7
The following method merges two queues:
result.add(b.remove());
}
return result;
Which condition ensures the merge works correctly (maintaining non-decreasing order)?
Question 8
Examine the following method:
int product = 1;
for (int number = 1; number < n; number++) {
if (number % 2 == 0)
product *= number;
}
return product;
}
(A) 48
(B) 105
(C) 384
(D) 5040
(E) 40320
Question 9
Consider the code that transforms an array:
row++;
if (row % 3 == 0) {
col++;
row = 0;
}
}
System.out.println(newArray[0][2]);
(A) 3
(B) 4
(C) 5
(D) 7
(E) 8
Question 10
Analyze the ArrayList operations:
nums.add(37);
nums.add(0);
nums.add(3);
nums.add(1, 2);
nums.set(0, 1);
nums.remove(2);
System.out.println(nums);
(A) [1, 2, 0]
(B) [1, 3, 0]
(C) [1, 3, 2]
(E) [37, 0, 0]
Question 11
Given boolean variables a, b, c, d, which expression is equivalent to !(!(a && b) || (c || !d))?
Question 12
Consider the class hierarchy:
public class A {
private int x;
public A() { x = 0; }
public A(int y) { x = y; }
}
public class B extends A {
private int y;
public B() {
/* missing code */
}
Which code initializes both x and y to 0 when new B() is called?I. y = 0;II. super(0); y =
0;III. x = 0; y = 0;
(A) I only
(B) II only
Question 13
Study the recursive method:
if (b < 10)
return b;
else
return 0;
else
return surprise(b / 10);
}
}
(A) I only
(B) II only
Question 14
The goal is to check if an array is in strictly decreasing order. Which loop correctly
implements this?I.
return false;
return true;
II.
return false;
return true;
III.
return false;
else
return true;
}
return true;
(A) I only
(B) II only
Question 15
Given a binary tree referenced by TreeNode t, the method funny is defined as:
funny(p.getLeft());
else if (p.getRight() != null)
funny(p.getRight());
else
System.out.print(p.getValue() + ".");
}
(A) how.now.brown.cow.this.is.only.a.test.
(B) how.now.cow.brown.this.only.a.is.test.
(C) cow.only.a.test.
(D) cow.
Question 16
Which data structure best supports a web browser's "back" functionality, where the most
recent site is returned first?
(A) Stack
(B) Queue
(C) PriorityQueue
(D) TreeNode
(E) TreeMap
Question 17
The TemperatureReading class implements Comparable. Which
compareTo implementations correctly order by increasing temperature?I.
II.
return -1;
else if (temperature == other.temperature)
return 0;
else
return 1;
III.
(A) II only
Question 18
Consider the recursive string manipulation method:
return "";
if (str.length() == 1)
return str;
(A) cepi
(B) epci
(C) iecp
(D) iepc
(E) ipce
Question 19
Analyze the stack operations:
stackOne.push(k);
while (!stackOne.isEmpty())
stackTwo.push(stackOne.pop());
What is printed?
(A) 0 1 2 3 4 5 6 7 8 9
(B) 0 1 2 3 4 9 8 7 6 5
(C) 5 6 7 8 9 0 1 2 3 4
(D) 9 8 7 6 5 0 1 2 3 4
(E) 9 8 7 6 5 4 3 2 1 0
Question 20
Consider the recursive function:
if (n == 1)
return 2;
return addFun(n - 1) + addFun(n - 2);
(A) 10
(B) 12
(C) 16
(D) 26
(E) 32
Question 21
A CornerBug turns at 90-degree angles instead of 45 degrees. What is the best design
approach?
Question 22
For LeftTurningBug (a subclass of Bug), which code turns the bug 90 degrees left?I.
setDirection(Location.LEFT);II. setDirection(getDirection() + Location.LEFT);III.
setDirection(Location.HALF_LEFT + Location.HALF_LEFT);
(A) I only
(B) II only
Question 23
The MysteryBug class:
public MysteryBug() {
setDirection(Location.NORTHEAST);
count = 0;
}
public void act() {
if (count < 3 && canMove()) {
move();
count++;
} else {
turn();
count = 0;
}
}
}
Question 24
A PouncingCritter moves to a random occupied location. Which methods need overriding?
I. getMoveLocationsII. makeMoveIII. selectMoveLocation
(A) I only
(B) II only
Question 25
The method to move an actor to a new grid:
Which code correctly moves the actor while maintaining grid consistency?(A)
anActor.putSelfInGrid(newGrid, loc); anActor.removeSelfFromGrid();
Question 26
The fillQ method constructs a queue:
if (count == 1)
intQ.add(y);
else {
intQ.add(y);
intQ.add(t);
for (int k = 2; k < count; k++) {
x = y + t - k;
y = t;
t = x + k;
intQ.add(t);
}
}
return intQ;
}
Question 27
In the fillQ method, what does the value added at Point A represent?
Question 28
if (t.getRight() != null)
rightKeep = mystery(t.getRight());
if (keep >= leftKeep) keep = leftKeep;
What does this method return for a non-empty tree?(A) The smallest integer in the tree.(B)
The largest integer in the tree.(C) The value of the root node.(D) The value of the
rightmost leaf.(E) The value of the leftmost leaf.
Question 29
The ListNodeIterator class:
current = current.getNext();
return value;
}
Question 30
The removeName method aims to delete all occurrences of a name from a list. Which
implementations work?I.
II.
III.
(A) I only
(B) II only
Question 31
Given the inorder traversal TCLSONAD and preorder traversal SCTLOAND of a binary
tree, what is the right child of the root?
(A) A
(B) L
(C) N
(D) O
(E) S
Question 32
The linked list sum method:
if (nums.getNext() == null)
return 0;
else
For which linked lists does this method return the correct sum?I. A list with one node.II. A
list with two nodes.III. A list with three nodes.
(A) I only
Question 33
To print all entries in empMap (a TreeMap), which code works?I.
II.
III.
(A) I only
(B) II only
(D) I and II
Question 34
The boolean expression (a && (b || !a)) == (a && b) is true when:
Question 35
Mergesort takes 45 time units for 5,000 items. Approximate time for 20,000 items?
(A) 90
(B) 150
(C) 220
(D) 500
(E) 720
Question 36
Inserting TRULYBASIC into a binary search tree. What is the preorder traversal?(A)
ABCILRSTUY(B) ACIBLSRYUT(C) TRLBAICSUY(D) TRULSYBAIC(E) YUSCIA BLRT
Question 37
After linking firstList and secondList with:
firstList.getNext().setNext(secondList.getNext());
secondList.setNext(firstList.getNext());
firstList.setNext(secondList);
secondList = null;
(A) [1, 2]
(B) [1, 3, 4]
(C) [1, 3, 2, 4]
(D) [1, 3, 2, 3, 4]
(E) [1, 2, 3, 4]
Question 38
The PriorityQueue operations:
(A) to to or not be be
(B) to be or not to be
(C) be to not or be to
(D) be not or to
(E) be be not or to to
Question 39
The computeSum method's time complexity:
}
return sum;
}
(A) O(\log n)
(C) O(n)
(E) O(n^2)
Question 40
The TreeSet operations:
System.out.println(cities);
What is printed?