06: Linked Lists

Submit this homework using Gradescope. You can type up your answers, or write legibly and scan them. Do not attempt to submit a paper copy in class, as it will not be accepted.


A. (2.5 points) Assume you have List containing a million elements of type String. Would you generally expect the following operations be faster with an array-based implementation, or faster with a linked-list-based implementation (with only a head pointer, no other instance variables)? Assume the array-based implementation’s backing array is large enough to hold the new element (no enlarge() needed).

  1. calling size()
  2. adding an element to the end of the list (add(Marc))
  3. adding an element to the front of the list (add("Marc", 0))
  4. removing an element from the front of the list
  5. removing an element from the end of the list

B. (2 points) Write a public int indexOf(String s) method that searches the list for the first occurrence of a value equivalent to s, and returns its index. Return -1 if the value is not found. For this question, write the method assuming that it’s part of the LinkedStringList we started in lecture. (The notes are on the schedule page, if you missed class.)