Шукаєте відповіді та рішення тестів для ESTRUCTURA DE DATOS? Перегляньте нашу велику колекцію перевірених відповідей для ESTRUCTURA DE DATOS в online.upr.edu.
Отримайте миттєвий доступ до точних відповідей та детальних пояснень для питань вашого курсу. Наша платформа, створена спільнотою, допомагає студентам досягати успіху!
Suppose the following operations are made on a Stack<String> S:
Stack<String> S = new LinkedStack<>();
S.push("Bob");
S.push("Ned");
S.push("Jil");
S.push(S.top());
S.push("Jim");
S.push(S.pop());
S.push(S.top());
What will be the resulting stack? Assume that the first element is the top of the stack (e.g. S = {1,2,3,4,5}, where 1 is the top of the stack)
Engineer Sophia is working on implementing the following code for her enqueue() method on a DoublyLinkedQueue<E> where the front of the queue can be accessed via header.getNext(). There is a bug in her code that causes an assertion error every time she tries to test it with a unit test. The implementation is as follows:
@Override
public void enqueue(E e){
if(e == null)
throw new IllegalArgumentException("Parameter cannot be null");
Node<E> nextNode = trailer;
Node<E> prevNode = trailer.getPrev();
Node<E> newNode = new Node(e, nextNode, prevNode);
prevNode.setNext(newNode);
nextNode = newNode;
currentSize++;
}
Choose the answer that fixes said bug:
Consider a List L implemented with an Array List. Suppose the following operations are executed on the list:
List<String> L = new ArrayList<String>();
L.add(“Ned”);
L.add(0, “Jim”);
L.add(“Jim”);
L.add(1, “Kim”);
L.remove(0);
L.add(“Cal”);
L.remove(“Jim”);
After these statements, on which position is Jim located in the list L?
Given the formal definition for Big O complexity analysis:
f(x) \leq \ cg(x), \ \forall_x \geq k , where
k, c \in \mathbb{R}
What does this definition state?
Select all that apply:
Consider the following code fragment:
public static void runner(int n) {
int count = 0;
for(int i = 1; i * i < n; i++) {
System.out.println(count, i);
count++;
}
}
What is the time complexity of this code?
Consider the following code fragment:
public static void runner(int N) {
int sum;
for(int i = N; i > 0; i /= 2) {
for(int j = 1; j < N; j *= 2) {
for(int k = 0; k < N; k += 2) {
sum += (i + j * k);
}
}
}
}
What is the time complexity of this code?
Consider the following code fragment:
public static double runner(int data[]) {
int N = 2000;
int len = Math.min(data.length/10, N);
double total = 0.0; for (int i=0; i <len; ++i) {
total +=data[i];
for (int j=0; j < i; ++j) {
System.out.println(j);
}
}
return total;
}
What is the time complexity of this code?
Consider a List L implemented with an ArrayList. Suppose the following operations are executed on the list:
List<String> L = new ArrayList<E>();
L.add(“Ned”);
L.add(0, “Jim”);
L.add(“Jim”);
L.add("Rex");
L.add(0, “Kim”);
L.add(“Bob”);
L.remove(2);
L.add(0, “Rex”);
L.add("Rex");
L.remove(0);
L.add("Ned");
After these statements, what would L.lastIndex("Rex"); return?
If we had the following implementations:
public interface InterfaceA {
public void printLetter();
}
public class ClassB implements InterfaceA {
@Override public void printLetter() { System.out.println("B"); }
}
public class ClassC implements InterfaceA {
@Override public void printLetter() { System.out.println("C"); }
}
If we intialize the following variable:Interface a = new ClassB();ClassB b = new ClassB();ClassC c = new ClassC();Are these valid usage of casting?ClassB b2 = (ClassB) a;InterfaceA a2 = (InterfaceA) c;Consider the following alternate remove() implementation:
public boolean remove(E obj) {
int index = firstIndex(obj);
if(index != -1)
return remove(index);
return false;
}
Would this code work on every List implementation? (e.g. ArrayList, LinkedList, etc.)