Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In the LinkedBag implementation, when a bag implemented with linked nodes is

ID: 3733427 • Letter: 1

Question

1. In the LinkedBag implementation, when a bag implemented with linked nodes is empty, which of of the following is true? Select all that apply.

d/ the bag object itself is null

2. Which of the following are advantages of using linked nodes to implement bags and lists? Select all that apply.

d/ adding an element to the front of a chain is easy

3.

Refer to the following list for the question below:

list1: 14 -> 37 -> 12 -> null


To be clear, list1 contains 3 nodes and list1.firstNode.data is 14.

public void whatIsIt(Node firstNode) {

Node currentNode = firstNode;

while (currentNode.next != null) {

System.out.print(currentNode.next.data + " ");
currentNode = currentNode.next;

}

}

What gets printed after calling:

4.

Refer to the following lists for the question below:

list1: 20 -> 37 -> 45 -> null
list2: 13 -> 29 -> null

To be clear, list1 contains 3 nodes, list2 contains 2 nodes, andlist1.firstNode.data is 20.

public void insertIt (Node nodeA, Node nodeB) {

nodeB.next = nodeA.next;
nodeA.next = nodeB;

}


What will list1 contain after calling:

5.

Refer to the following lists for the question below:

list1: 14 -> 42 -> 19 -> null

To be clear, list1 has 3 nodes and list1.firstNode.data is 14.

What is the value of currentNode.data after invoking the following code?

6/

Refer to the following lists for the question below:

list1: 48 -> 35 -> 16 -> null

To be clear, list1 has 3 nodes and list1.firstNode.data is 48.

What is the value of currentNode.data after invoking the following code?

a/ the numberOfEntries field contains 0

Explanation / Answer

Ques 1. Answer : (A) , (B)

Ques 2. Answer : (b), (d)

Ques 3. Answer : 14 37

The program prints all elements except the last element due to the condition

while (currentNode.next != null)

When, currentNode points to the last node, the condition becomes false.

Ques 4. Answer : 20 -> 13 -> 37 -> 45 -> null

nodeB.next = nodeA.next;

After this operation, nodeB becomes

13 -> 37 -> 45 -> null

Now after appying this operation

nodeA.next = nodeB;

nodeA becomes

20 -> 13 -> 37 -> 45 -> null

Ques 5. Answer : 19

After this operation

After this operation

Ques 6. Answer : null

currentNode = list1.firstNode;

currentNode points to first node.

currentNode points to third node.

currentNode points to null.

So, the value of currentNode.data is null