Beruflich Dokumente
Kultur Dokumente
Sample
Final Exam
Which of the following LinkedList methods will change the value of a location in an LinkedList?
A. add()
B. change()
C. get()
D. set()
E. None of these
QUESTION 2 xx
Which of the following LinkedList methods will insert a new value at a location in an LinkedList?
A. add()
B. insert()
C. get()
D. set()
E. None of these
QUESTION 3 xx
B. onetwo
C. onetwothree
D. twothree
E. None of these
QUESTION 4 xx
E. [two]
QUESTION 5 xx
E. [two]
QUESTION 6 xx
B. 1
C. 0
D. 4
E. 5
QUESTION 7 xx
B. 1
C. 0
D. 4
E. 5
dList.add("two");
dList.add(0,"three");
dList.add("four");
dList.add(1,"five");
out.println(dList.indexOf("three"));
QUESTION 8 xx
one
two
three
four
five
QUESTION 9 xx
one
two
three
four
five
QUESTION 10 xx
one
two
three
four
five
QUESTION 11 xx
charAt();
charAt(0);
substring(0);
substring(0,1);
substring(0,0);
QUESTION 12 xx
1
2
3
4
5
LinkedList<Integer> iList;
iList = new LinkedList<Integer>();
iList.add(0, 1);
iList.add(2);
iList.set(0,3);
iList.add(1,4);
iList.set(0,5);
out.println(iList.get(0));
QUESTION 13 xx
0
1
99
78
71
QUESTION 14 xx
[99 , 8
[78 , 8
[99, 78
[8 , 78
[8 , 99
]
]
]
]
]
class It
{
public It( ) { x = 99; }
public String toString(){
return x + "";
}
private int x = 78;
}
//code in main in some class
It itOne = new It();
System.out.println(itOne);
class At
{
public At( ) { x = 99; }
public At( int y ) { x = y; }
public String toString(){
return x + " ";
}
private int x = 78;
}
//code in main in some class
LinkedList atList = new LinkedList();
atList.add( new At(8));
atList.add( new At());
System.out.println(atList);
QUESTION 15 xx
QUESTION 16 xx
E. None of these
QUESTION 17 xx
LinkedList<String> words;
words = new LinkedList<String>();
words.add("at");
words.add("up");
words.add("or");
words.set(1, "33");
System.out.println(words);
E. [5, 6, 8]
QUESTION 19 x
LinkedList<String> stringList;
stringList = newLinkedList<String>();
stringList.add("z");
stringList.add("x");
stringList.add("x");
stringList.add("w");
stringList.add("x");
stringList.add("x");
stringList.add("x");
for(int i=0; i<stringList.size();i++)
{
if(stringList.get(i).equals("x"))
stringList.remove(i);
}
out.println(stringList);
QUESTION 20 x
LinkedList<String> wordList;
wordList = newLinkedList<String>();
wordList.add("z");
wordList.add("x");
wordList.add("x");
wordList.add("w");
wordList.add("x");
wordList.add("x");
wordList.add("e");
int i=0;
while(i<wordList.size())
{
if(wordList.get(i).equals("x"))
wordList.remove(i);
else i++;
}
out.println(wordList);
QUESTION 21xx
//line 2
out.println(aSet.size());
//line 3
QUESTION 23 xx
QUESTION 24 xx
B. 1
C. 2
D. no output error
E. None of these
QUESTION 25 xx
get()
A.
O(1)
O(N)
B.
O(1)
O(1)
C.
O(N)
O(log2N)
D.
O(log2N)
O(log2N)
E.
O(log2N)
O(N)
QUESTION
27x
Which of the following interfaces must be implemented by all Objects stored as keys in a TreeMap?
A. Locatable
QUESTION
B. Sortable
C. Treeable
D. Comparable
E. TreeMapable
28x
B. 23.1f
C. 345
D. A and B only
E. A, B, and C only
QUESTION 29xx
public Lines()
{
map = new TreeMap<String,Set<String>>();
}
public void setPerson(String pair)
{
B. new TreeSet<String>();
C. new TreeSet<>();
D. new Set();
E. new TreeSet<Integer>();
QUESTION 31xx
QUESTION 32xx
Set<String> s;
if( < *1 > ){
s = map.get(line);
s.add(person);
< *3 >
}
else{
s = < *2 >
s.add(person);
< *3 >
QUESTION 33 xx
Which of the following adds and removes items according to FIFO rules?
A. stack
B. queue
C. priority queue
D. binary tree
E.
array
D. binary tree
E.
array
QUESTION 34xx
Which of the following adds and removes items according to LIFO rules?
A. stack
B. queue
C. priority queue
QUESTION 35 xx
Which of the following adds and removes items according to comparisons made by the compareTo in the Objects being stored?
A. stack
B. queue
QUESTION 36xx
B. [7]
C. [5,7]
E. None of these
D. [7,5]
QUESTION 37xx
C. priority queue
D. binary tree
E.
array
//line 1
//line 2
B. [7]
C. [5,7]
D. [7,5]
E. None of these
QUESTION 38xx
Queue<Integer> c;
c = new LinkedList<Integer>();
c.add(5);
c.add(3);
c.add(9);
A. 4
out.println(c.remove());
A. 1
B. 3
C. 5
D. 9
E. -1
QUESTION 39 xx
B. 2
C. 5
D. 3
E. -1
//line 1
QUESTION 40 xx
B. false
C. 1
D. 0
E. -1
QUESTION 41 xx
c.add(17);
c.add(19);
out.println(c.peek());
out.println(c.isEmpty());
//line 2
//line 3
B. 3
C. 4
D. 5
E. 0
QUESTION 42xx
B. 23
C. 14
E. None of these
D. 11
QUESTION 43xx
B. 9 5
C. 53 9
E. None of these
D. 14 53
Queue<Integer> d;
d = new LinkedList<Integer>();
d.add(23);
d.add(78);
d.add(14);
out.println(d.remove());
Queue<Integer> e;
e = new LinkedList<Integer>();
e.add(14);
e.add(9);
e.add(53);
e.add(5);
out.print(e.remove()+" ");
out.println(e.remove());
QUESTION 44 xx
B. 76
C. 84
E. None of these
D. null
QUESTION 45 xx
B. [36,12]
C. [12]
E. None of these
D. [36]
QUESTION 46 xx
A. 12
B. 5
C. 7
E. 0
D. 9
A. 45 87
B. 45 34
C. 45
E. None of these
D. 87 45
QUESTION 47xx
QUESTION 48 xx
B. 1.6
C. 8.2
D. 5.2
E. 0.0
QUESTION 49 xx
B. 1.6
C. 8.2
D. 5.2
//line 1
k.push(5.2);
out.println(k.pop());
//line 2
E. 0.0
QUESTION 50xx
return
return
return
return
return
queue.remove();
queue.remove(0);
queue.erase(0);
queue[0].remove();
queue.set(0,0);
QUESTION 51xx
return
return
return
return
return
queue.get(0);
queue.get(queue.size()-1);
queue.get(1);
queue[0];
queue[queue.size()-1];
queue.add(x);
}
public String remove(){
QUESTION 52xx
<*1>
}
public String front(){
return
return
return
return
return
<*2>
queue.get(0);
queue.get(queue.size());
queue.get(queue.size()-1);
queue[0];
queue[queue.size()-1];
}
public String back(){
<*3>
}
public boolean isEmpty(){
<*4>
QUESTION 53xx
return
return
return
return
return
queue.length==0;
queue.size()==0;
queue.size==0;
queue.size;
queue.size()-1;
QUESTION 54 xx
B. a
C. w
E. z
D. r
QUESTION 55 xx
B. a
C. w
E. z
D. r
QUESTION 56 xx
B. a
C. w
E. z
D. r
PriorityQueue<String> pQ;
pQ = new PriorityQueue<String>();
pQ.add("z");
pQ.add("a");
out.println(pQ.remove());
pQ.add("w");
pQ.add("a");
//line 1
out.println(pQ.remove());
pQ.add("r");
//line 2
out.println(pQ.remove());
//line 3
QUESTION 57xx
If a complete tree has 3 levels, which of the following are possible node counts for the tree?
A. 9
B. 5
C. 3
D. 2
E. 11
D. 8
E. 9
QUESTION 58 xx
B. 6
C. 7
QUESTION 59 xx
QUESTION 60 xx
QUESTION 61xx
QUESTION 62xx
QUESTION 63 xx
QUESTION 64xx
A.
B.
20
C.
10
D.
25
E.
null
QUESTION 66 xx
B. 20
C. 10
D. 25
E. null
D. 25
E. null
QUESTION 67xx
B. 20
C. 10
QUESTION 68xx
Which of the following correctly instantiates a TreeNode with the value 99 and with both references set to null?
A.
B.
C.
D.
E.
TreeNode
TreeNode
TreeNode
TreeNode
TreeNode
x
x
x
x
x
=
=
=
=
=
TreeNode(99,null,null);
TreeNode(99,-1,-1);
new TreeNode(null,null,99);
new TreeNode(99,0,0);
new TreeNode(null,99,null);
QUESTION 69 xx
QUESTION 70x
Given a complete tree with 4 levels, how many leaves could this tree have?
I. 4
II. 5
III. 12
A. I only
B. II only
C. III only
D. I and II only
E. I and III only
QUESTION 71xx
A. 15
B. 16
C. 32
D. 31
E. 63
QUESTION 72 xx
Which of the following is true for a heap that stores the minimum priority value at the root?
A.
B.
C.
D.
E.
The root will be the item with the greatest value in the tree.
The nodes from the root down are in sorted order by level.
The root will be the item with the lowest value in the tree.
The nodes from the root down are in sorted order by branch.
none of these answers are correct.
QUESTION 73 xx
B. 200
C. 100
D. 99
E. 13
QUESTION 76 xx
B. 200
C. 100
D. 99
E. 13
QUESTION 77xx
If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees in
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these
QUESTION 78 xx
If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees pre
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these
QUESTION 79 xx
If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees post
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these
QUESTION 80 xx
If you insert the following numbers in the order listed into a binary search tree, which of the following represents the trees reverse
order traversal output?
Items inserted in the following order : 200 150 225 75 210 250
A. 250 225 210 200 150 75
C. 75 150 200 210 225 250
E. none of these
QUESTION 81xx
Assuming t does not equal null, which of the following blocks of code would fill // blank 1 so that method fun
would return the minimum value in the tree?
private Comparable fun(TreeNode t)
{
// blank 1
}
I.
II.
while(t!=null)
{
t=t.getLeft();
}
return t.getValue();
A.
B.
C.
D.
E.
while(t!=null&&t.getLeft()!=null)
{
t=t.getLeft();
}
return t.getValue();
III.
while(t!=null)
{
t=t.getLeft();
}
return t;
I
I and II
III only
II and III
II only
QUESTION 82xx
Assuming t does not equal null, which of the following blocks of code would fill // blank 1 so that method fun
would return the maximum value in the tree?
private Comparable fun(TreeNode t)
{
// blank 1
}
I.
II.
while(t!=null)
{
t=t.getRight();
}
return t;
A.
B.
C.
D.
E.
while(t!=null&&t.getRight()!=null)
{
t=t.getRight();
}
return t.getValue();
III.
while(t!=null)
{
t=t.getLeft();
}
return t.getValue();
I
I and II
II only
II and III
III only
QUESTION 83xx
QUESTION 84xx
How many leaves max could a full tree with 4 levels have?
A. 3
B. 4
C. 5
D. 6
E. 8
QUESTION 85xx
Assuming tree does not equal null, which of the following blocks of code would fill //blank 1 so that method go
would return a String containing all nodes in pre order?
private String go(TreeNode tree)
{
//blank 1
}
I.
if(tree==null)
return"";
return""+go(tree.getLeft())+""+tree.getValue()+""+go(tree.getRight());
II. if(tree==null)
return"";
return""+go(tree.getLeft())+go(tree.getRight())+tree.getValue()+"";
III. if(tree==null)
A.
B.
C.
D.
E.
return"";
return""+tree.getValue()+""+go(tree.getLeft())+go(tree.getRight());
I
I and II
II only
II and III
III only
QUESTION 86 xx
<*1>
so the default
public Matrix() {
<*1>
}
public Matrix(int rows, int cols){
<*2>
QUESTION 87 xx
QUESTION 88 xx
Which of the following statements must fill <*3> so that the size of
one and the size of the receiving row of mat will be the same?
A.
B.
C.
D.
E.
class Matrix
{
private int[][] mat;
setRowSize(r,one.size());
setRowSize(r,one.length);
setRowSize(one.size(),r);
setRowSize(r,one.length());
setRowSize(one.length,r);
QUESTION 89 xx
<*4>
r<mat[c].length
r<mat.length
r<mat.length()
r<mat.size()
r<mat[r].length
QUESTION 90 xx
After executing line 1, how many rows does instance variable mat
contain?
A. 3
B. 4
C. 5
D. 6
E. None of these
QUESTION 91 xx
3.0
B.
5.0
C.
7.0
D.
9.0
E.
1.0
QUESTION 92 xx
B.
7 7
C. 5 3
D.
5 7
E. 7 5
QUESTION 93 xx
B.
7 7 9
C. 5 5 3
D.
9 5 9
E. 7 5 9
QUESTION 94 xx
3.0
B.
5.0
C.
7.0
D.
9.0
E.
1.0
class Cat
{
private int x, y;
public Cat() {
x=y=5;
}
public void fun() {
x=7;
}
public double go() {
return x;
}
public void back() {
fun();
}
public String toString() {
return x + " " + y;
}
}
class Lion extends Cat
{
private int x;
public Lion() {
x=9;
}
public void fun() {
QUESTION 95 xx
B.
7 7 9
C. 5 5 3
D.
9 5 9
E. 7 5 9
x=3;
}
public double go() {
return x;
}
public void back() {
super.back();
}
public String toString() {
return super.toString() + " " + x;
}
QUESTION 96 xx
class Whale
{
private int x, y;
public static int c;
B. class Beluga 0 0 2
public Whale() {
c++;
}
public void fun() {
x = 6;
}
public int back() {
return 1;
}
public String toString() {
return x + " " + y + " " + c;
}
C. class Beluga 0 0 3
D. class Beluga 0 0 0
E. class Beluga 0 0 5
QUESTION 97 xx
}
class Beluga extends Whale
{
public void fun() {
1
2
3
4
5
System.out.println(back());
}
public int back() {
return 2;
}
public String toString() {
return "class Beluga " + super.toString();
}
QUESTION 98 xx
D. 6 0 4
E. 6 0 6
QUESTION 99 xx
What
1.
D is output by line 4?
26. D
A.
B.
27. D
2. A
3.
E
C. 3
D.
4. A4
28. A
E.
5. A5
30. B
6. D
31. C
7.
A. C
class Beluga 0 0 3
32. E
B. D
class Beluga 0 0 4
8.
33. B
29. E
QUESTION 100 xx
C. class Beluga 0 0 6
9. E
34. A
10.
D
E. class
Beluga 0 0 8
35. C
11. B
36. D
12. E
37. C
13. C
38. C
14. E
39. D
15. D
40. B
16. C
41. C
17. B
42. B
18. C
43. A
19. C
44. A
20. B
45. C
21. C
46. C
22. D
47. D
23. D
48. A
D. class Beluga 0 0 5
24. C
25. C
A+ Computer 49.
Science
Ifs/Strings Test www.apluscompsci.com
D
50. B
3
4
5
51. A
76. E
52. C
77. C
53. B
78. D
54. B
79. B
55. B
80. A
56. D
81. E
57. B
82. C
58. E
83. D
59. B
84. E
60. A
85. E
61. D
86. E
62. C
87. A
63. B
88. B
64. A
89. B
65. D
90. B
66. C
91. B
67. B
92. E
68. A
93. A
69. E
94. A
70. D
95. C
71. A
96. A
72. C
97. C
73. B
98. D
74. E
99. B
75. A
100. D