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

1. A list is a collection that __________. a. associates keys with elements b. a

ID: 652641 • Letter: 1

Question

1. A list is a collection that __________.

a. associates keys with elements

b. assigns an index to each of its elements

c. is implemented by the JList class

d. none of the above

2. In Java, the first (head) element of a list __________.

a. has a predecessor but no successor

b. has both a predecessor and a successor

c. has index 0 d. has index 1

3. To add an element e just after a node referenced by ref, you should use the statement __________.

a. add(ref);

b. ref.next = new Node(e);

c. ref.next = new Node(e, ref.next);

d. ref = new Node(e, ref.next);

4. In general, adding an element e in one step to a singly-linked list just before a node referenced by ref __________. a. cannot be done

b. can be done if you use a loop

c. can only be done when ref is the last node in the list

d. can be done if you check for exceptions

5. To remove a node that is not the head of a singly-linked list conveniently, you need to have a reference to __________.

a. the node that precedes it

b. the node that comes after it

c. the node itself

d. none of the above

6. To easily move from any node to its successor, and from any node to its predecessor, and from the first to the last node and from the last to the first node, you need __________.

a. a singly-linked list

b. a singly- and circularly-linked list

c. a doubly-linked list

d. a doubly- and circularly-linked list

7. A systematic method that starts at the beginning of the list and processes every node is called __________.

a. a walk down the list

b. a list processing function

c. a travesty of list processing

d. a traversal

8. A method for removing the element at an index k in a list throws an exception unless __________.

a. k is negative

b. k is nonnegative and less than the size of the list

c. k is nonnegative and less than or equal to the size of the list

d. k is positive and less than or equal to the size of the list

9. A method for adding an element at an index k in a list throws an exception unless __________.

a. k is negative

b. k is nonnegative and less than the size of the list

c. k is nonnegative and less than or equal to the size of the list

d. k is positive and less than or equal to the size of the list Review Questions and Exercises 1213

10. A method that determines if a list is empty in a consistently written linked list class that uses a reference first to point to the first element, and a reference last to point to the last element, can return the value __________.

a. first == null

b. last == null;

c. first == null || last == null

d. all of the above

11. True or False: A linked list is a recursive data structure.

12. True or False: A linked list is a looping data structure.

13. True or False: The head of a linked list is also a linked list.

14. True or False: The tail of a linked list is also a linked list.

15. True or False: The index of an element to be added to a list can be the same as the size of the list.

16. True or False: The index of an element to be removed from a list can be the same as the size of the list.

17. True or False: The statement myList = new Node("Zoe", myList); adds "Zoe" to the end of the linked list myList; 18. True or False: There is a natural way to write a recursive method to check whether a linked list is empty.

19. True or False: The last item in a doubly-linked list can sometimes have a successor.

20. True or False: The first item in a doubly-linked list can sometimes have a successor.

Explanation / Answer

1. b. assigns an index to each of its elements

2. c. has index 0

3. ref.next = new Node(e);

4. c. can only be done when ref is the last node in the list

5. c. the node itself

6. a doubly-linked lis

7. c. a travesty of list processing

8. k is negative

9. a. k is negative

10. first == null

11. True

12. True

13. True

14. False

15.True

16. False

17.True

18. True

19. True

20. True