Reference no: EM131179407
Q1. Review the given code fragment from ArrayBag class below and answer the following:
a. Explain each line in your own words:
b. Write the header (signature) of the method that contains this code.
checkInitialization();
int index = getIndexof(anEntry);
T result = removeEntry(index);
return anEntry.equals(result);
Q2. For the LinkedBag class write the code for the method: "boolean add(T obj)".
Q3. Simplify the following running time functions as O "Big-O":
a. T(n) = log2(n8)+n2 +1024n
b. T(n) = n√n + 2048/n4 + n!
c. T(n) = n/256 + 64√n + 128n
Q4. Write the output of the following code:
String s = "CSIS210";
Stack stk = new Stack();
for(char c : s.toCharArray()){
stk.push(c);
}
for(int i=0; i<4; ++i) stk.peek();
for(int i=0; i<3; ++i) System.out.print(stk.pop());
for(int i=0; i<4; ++i) System.out.print(stk.pop());
Q5. Find and fix all errors in the following code.
public void pop(T obi) {
checkInitialization();
if (!isEmpty(Stack)) {
throw new EmptyStackException();
} else {
T top = stack[0];
Stack[topIndex] = 0;
++topIndex;
return top[0];
}
}