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

Java Questions. 1. In the AList implementation, when an array-based list is empt

ID: 3599580 • Letter: J

Question

Java Questions.

1. In the AList implementation, when an array-based list is empty

A. the numberOfEntries field contains 0

B. the array is set to null

C. the array is re-sized to have no elements (meaning list.length = 0)

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

A. the numberOfEntries field contains 0

B. firstNode is set to null

C. firstNode.data is set to null

3. Which of the following are advantages of using linked nodes to implement bags and lists?

A. linked chains require shifting under certain conditions

B. linked lists only use as much memory as needed

C. linked nodes allow direct access to any element

D. adding an element to the front of a chain is easy

4. Refer to the following list for the question below:

list1: 49 -> 24 -> 37 -> null


To be clear, list1 contains 3 nodes and list1.firstNode.data==49;

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:

whatIsIt(list1.firstNode)?

5. 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==20;

public void insertIt (Node nodeA, Node nodeB) {

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

}


What will list1 contain after calling:

insertIt(list1.firstNode, list2.firstNode);

6. Refer to the following lists for the question below:

list1: 35 -> 49 -> 14 -> null

To be clear, list1 has 3 nodes and list1.firstNode.data == 35;

currentNode = list1.firstNode.next;

currentNode = currentNode.next;

What is the value of currentNode.data ?

A. 35

B. 49

C. 14

D. null

E. None of the above

7. Refer to the following lists for the question below:

list1: 35 -> 49 -> 14 -> null

To be clear, list1 has 3 nodes and list1.firstNode.data == 35;

currentNode = list1.firstNode;

currentNode.next = currentNode.next.next;

currentNode = currentNode.next;

What is the value of currentNode.data ?

A. 35

B. 49

C. 14

D. null

E. none of the above

8. What is the order of growth of T( n ) = 3n^2 + 4n^3 +3 n ?

9. What is the the order of growth for the following algorithm.

for(int i=1; i<=n; i++) {

statement1

for(int j=1; j<=n; j++) {

statement2

for(int k=1; k<=5; k++) {

statement3

}

statement4

}

statement5

}

statement6

10. What is the order of growth for the following algorithm.


statement1

for i=2 to n-1 {

if(condition1) {

for i=1 t n

statement3

} else {

statement3

}

statement5

}

statement6

11. It is always possible to convert an iterative algorithm to a recursive algorithm. True or False?

12. Which property of recursion does the following method violate?

public int callIt (Node r) {
if (r != null)

return r.next;

else

return r;

}

13. Which property of recursion does the following method violate?

public Node callIt(Node r) {
if (r != null)

return callIt(r.next);

else

return r;

}

A.13 -> 20 -> 29 -> null

Explanation / Answer

Hi, I have answered first 4 questions.

Please repost others in separate post.

1. In the AList implementation, when an array-based list is empty

Ans: A. the numberOfEntries field contains 0

We mentain number of elements in the list usign an variable "numberOfEntries", initially it set to 0;

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

Ans: B. firstNode is set to null

Basically we have "firstNode" (head node ) that is the starting point of the list.

If it is null, means list is empty

3. Which of the following are advantages of using linked nodes to implement bags and lists?

Ans: D. adding an element to the front of a chain is easy

To add an element at the begining (starting), we just need to point next of new node to head

and head will be updated with new node

4. list1: 49 -> 24 -> 37 -> null

public void whatIsIt(Node firstNode) {

Node currentNode = firstNode;

// we are iterating till before last node

while (currentNode.next != null) {

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

currentNode = currentNode.next;

}

}

Output: 49, 24

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote