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

Consider the following code implementing a singly-linked Node containing an int.

ID: 3621640 • Letter: C

Question

Consider the following code implementing a singly-linked Node containing an int.

We will use this code for this and the next three questions:

2) Code that inserts a new node at the head of this list is:

3) Code which adds a new node as the second node (that following the head) of this linked list is:

None of the other choices has code that creates a circular linked list.

5) T/F: The algorithm used in binary search works equally well in searching in both arrays and linked lists.

We need to find the nth node of the list, where n varies.

We have to sort the list.

We need to insert a new element at the front of the list.

None of the other choices are correct.

7) T/F: Assume we have a reference to the kth node of some singly-linked list. Then it is always much faster to exchange the kth and (k+1)th elements of an array storing the same data as this list, as opposed to exchanging the kth and (k+1)st nodes in this list.


8) The time complexity of reversing any singly-linked list of length n (where the last node becomes first, next-to-last becomes second, etc.) is:

O(1)

O(n)

O(n*log n)

O(n2)

9) Suppose you are given two references, each to the head node of a different singly-linked list of length n. You wish to concatenate the two lists together, so that the last node of the first points to the first node of the second.

Then the time complexity of this operation is:

O(1)

O(n)

O(log n)

O(n2)

10) Same situation as the previous problem, but now both are circular doubly-linked lists, implemented as described in Section 3.2.

If you still have only references to the head node of each respective list, then the time complexity of this concatenation operation is:

O(1)

O(n)

O(n*log n)

O(n2)

11) Suppose you have two references , each to the head node of a singly-linked list with n nodes, each node containing an int. Further, suppose that each list is sorted. That is, the head node of each is the smallest in its respective list, the next node in each is the next smallest, and so on.

Then the time complexity required to merge the two sorted lists, creating a new list containing all the nodes of both original lists, but not necessarily in sorted order, is:

O(1)

O(n)

O(n*log n)

O(n2)

12) Assume the same situation as the previous problem.

Then the time complexity of merging the two sorted lists, creating a new list containing the union of all the nodes of both original lists, but now requiring that the new list also be in sorted order, is:

O(1)

O(log n)

O(n*log n)

O(n)

13) Suppose we have two singly-linked lists of ints, each of equal length n. Also suppose we have a reference to each list's head node, and assume that both lists are sorted: the first node in each contains the smallest int in its list, the second node contains the next smallest in each, and so forth.

We want to check if the two lists are equal; that is, determine if the two lists are "clones" of each others. Then the worst-case time complexity of this operation is:

O(1)

O(log n)

O(n)

O(n2)

14) The Java collections class java.util.LinkedList:

Shares no common operations with java.util.ArrayList.

Has identical operations to java.util.ArrayList.

Shares no common superclass, direct or indirect, with java.util.ArrayList.

Does not share an immediate common superclass with java.util.ArrayList.

15) T/F: There is no single operation provided within java.util.LinkedList that will add all elements of one LinkedList to those of another.

Node n4 = new Node(); n1.next = n4;
Node n4 = new Node(); n4.next = n1;
Node n4 = new Node(); n3.next = n4;
Node n4 = new Node(); n4.next = n3

Explanation / Answer

1)Code that inserts a new node at the tail of this list is:

Node n4 = new Node(); n1.next = n4
Node n4 = new Node(); n4.next = n1;
Node n4 = new Node(); n3.next = n4;
Node n4 = new Node(); n4.next = n3;

2) Code that inserts a new node at the head of this list is:
Node n4 = new Node(); n1.next = n4;
Node n4 = new Node(); n4.next = n1;
Node n4 = new Node(); n3.next = n4;
Node n4 = new Node(); n4.next = n3

3) Code which adds a new node as the second node (that following the head) of this linked list is:
Node n4 = new Node(); n4.next = n2; n3.next = n4;
Node n4 = new Node(); n4.next = n2; n2.next = n4;
Node n4 = new Node(); n4.next = n3; n3.next = n2;
Node n4 = new Node(); n2.next = n4;

4) Code which creates a circular linked list is:
Node n4 = new Node(); n1.next = n4; n4.next = n3;
Node n4 = new Node(); n4.next = n1; n3.next = n4;
Node n4 = new Node(); n1.next = n4; n4.next = n2;
None of the other choices has code that creates a circular linked list.

5) T/F: The algorithm used in binary search works equally well in searching in both arrays and linked lists.
False

6) Linked lists are preferable to arrays, when:
We have to sort the list.
We have to sort the list.
We need to insert a new element at the front of the list.
None of the other choices are correct.

14) The Java collections class java.util.LinkedList:
Shares no common operations with java.util.ArrayList.
Has identical operations to java.util.ArrayList.
Shares no common superclass, direct or indirect, with java.util.ArrayList.
Does not share an immediate common superclass with java.util.ArrayList.

15) T/F: There is no single operation provided within java.util.LinkedList that will add all elements of one LinkedList to those of another.
True

Please post the other questions in other posts.

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