Suppose that an intermixed sequence of 10 enqueue and 10 dequeue operations are
ID: 3667945 • Letter: S
Question
Suppose that an intermixed sequence of 10 enqueue and 10 dequeue operations are performed on a FIFO queue. The enqueue operations add the values 0 through 9 to the data structure, in the order given; the dequeue operations delete and print out the return values. Which of the following output sequence could occur?
0 1 2 3 4 9 6 8 7 5
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 9 8 7
2.
Consider the following class:
Which of the following code snippets will correctly create an object of this class and display its information?
3.
Consider the following code snippet:
What is wrong with this code?
a.There must be a default constructor with no arguments.
b.The class instance variables must be initialized in the declaration statements.
c.The constructor declaration must have a return type of String.
d.The constructor declaration must not have any return type.
Which of the following id[] array(s) could be the result of running the weighted quick union algorithm on a set of 10 items? Check all that apply.
Recall that our weighted quick union algorithm uses union by size (number of nodes) and not union by height.
4.
Suppose that an intermixed sequence of 10 push and 10 pop operations are performed on a LIFO stack. The push operations add the values 0 through 9 to the stack, in the order given; the intermixed pop operations delete and print out the return values Which of the following output sequence could not occur?
a.1 0 3 4 6 2 5 7 9 8
b.3 2 1 5 8 9 7 6 4 0
c.2 1 8 7 9 6 5 4 3 0
d.2 1 0 3 4 5 6 7 8 9
5.
Consider an object of type GenericMysteryBox<Boolean> that stores N items of type Boolean in a generic array items[] of length N.
public class GenericMysteryBox<Item> {
private int N;
private Item[] items;
...
}
Using the 64-bit memory cost model from the lecture, how many bytes does it use as a function of N? Include all memory referenced by the object and use tilde notation to simplify your answer. For example, enter ~ 4N if the number of bytes as a function of N is 4N + 32.[A]
Hint: an object of the wrapper type Boolean uses 24 bytes
6.
7.
8.
Given the following definition of a MysteryBox object:
public class MysteryBox {
private final double x0, x1, x2;
private final boolean y0, y1;
private final long z0, z1, z2;
private final int[] a = new int[280];
...
}
Using the 64-bit memory cost model from lecture, how many bytes does each object of type MysteryBox use? Include all memory allocated when the client calls new MysteryBox().
9.
What will be the value stored in the variable x after the execution of the following code snippet?
1
The code has a syntax error
4
2
a.0 1 2 3 4 9 6 8 7 5
b.0 1 2 3 4 5 6 7 8 9
c.0 1 2 3 4 5 6 9 8 7
2.
Consider the following class:
public class Auto
{ private String make;
private String model;
private String year;
public Auto(String aMake, String aModel, String aYear)
{ make = aMake;
model = aModel;
year = aYear;
}
public String getInfo()
{ return year + " " + make + " " + model;
}
}
Which of the following code snippets will correctly create an object of this class and display its information?
a.myAuto = new Auto();
System.out.println(myAuto.getInfo());
b.Auto myAuto = new Auto();
System.out.println(myAuto.getInfo());
c.Auto myAuto = new Auto("Ford", "Focus", "2011"); System.out.println(myAuto.getInfo());
d.Auto myAuto = new Auto("2011", "Ford", "Focus"); System.out.println(myAuto.getInfo());
3.
Consider the following code snippet:
public class Vehicle
{ private String type;
private int numAxles;
public void Vehicle(String vehicleType, int VehicleAxles)
{ . . . } }
What is wrong with this code?
a.There must be a default constructor with no arguments.
b.The class instance variables must be initialized in the declaration statements.
c.The constructor declaration must have a return type of String.
d.The constructor declaration must not have any return type.
Which of the following id[] array(s) could be the result of running the weighted quick union algorithm on a set of 10 items? Check all that apply.
Recall that our weighted quick union algorithm uses union by size (number of nodes) and not union by height.
0 0 0 0 0 7 5 0 7 0
a.4 1 2 4 1 6 0 0 0 1
b.0 1 5 3 4 5 5 9 8 9
c.3 9 9 4 8 3 3 3 9 3
d.1 6 6 6 6 6 8 6 8 6
4.
Suppose that an intermixed sequence of 10 push and 10 pop operations are performed on a LIFO stack. The push operations add the values 0 through 9 to the stack, in the order given; the intermixed pop operations delete and print out the return values Which of the following output sequence could not occur?
a.1 0 3 4 6 2 5 7 9 8
b.3 2 1 5 8 9 7 6 4 0
c.2 1 8 7 9 6 5 4 3 0
d.2 1 0 3 4 5 6 7 8 9
5.
Consider an object of type GenericMysteryBox<Boolean> that stores N items of type Boolean in a generic array items[] of length N.
public class GenericMysteryBox<Item> {
private int N;
private Item[] items;
...
}
Using the 64-bit memory cost model from the lecture, how many bytes does it use as a function of N? Include all memory referenced by the object and use tilde notation to simplify your answer. For example, enter ~ 4N if the number of bytes as a function of N is 4N + 32.[A]
Hint: an object of the wrapper type Boolean uses 24 bytes
6.
Give the id[] array that results from the following sequence of 6 union operations on a set of 10 items using the quick-find algorithm. 4-2 4-9 0-2 5-8 4-3 1-3 Your answer should be a sequence of 10 integers, separated by whitespace. Recall: our quick-find convention for the union operation p-q is to change id[p] (and perhaps some other entries) but not id[q].
7.
Give the id[] array that results from the following sequence of 9 union operations on a set of 10 items using the weighted quick-union algorithm from lecture. 0-8
6-3
4-2
9-1
0-9
3-2
3-5
4-7
0-4 Your answer should be a sequence of 10 integers, separated by whitespace. Recall: when joining two trees of equal size, our weighted quick union convention is to make the root of the second tree point to the root of the first tree. Also, our weighted quick union algorithm performs union by size (number of nodes) - not union by height - and does not do path compression.
8.
Given the following definition of a MysteryBox object:
public class MysteryBox {
private final double x0, x1, x2;
private final boolean y0, y1;
private final long z0, z1, z2;
private final int[] a = new int[280];
...
}
Using the 64-bit memory cost model from lecture, how many bytes does each object of type MysteryBox use? Include all memory allocated when the client calls new MysteryBox().
9.
What will be the value stored in the variable x after the execution of the following code snippet?
int a = 10;
int b = 20;
int c = 2;
int x = b / a /*c*/;A.
1
B.The code has a syntax error
C.4
D.2
Explanation / Answer
Answer:)
1. b
2. c
3. b
4. a
5. 4bytes
6.
7.
8.) 3 * 8 + 2*1 + 6*2 + 2*6 = 50
9. c
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.