--- tags: Setup-Summer21 --- # Lecture 12 Setup/Prep This lecture, we will continue with our `ArrayBasedList` implementation. We have a few tasks remaining: - Decide how much to grow the array when it runs out of space. Our goal is to improve on the worst-case linear run-time of doing so. - Figuring out how to implement `addFirst` without incurring linear run-time. - Figure out how to make per-element `for` loops work on our own data structure implementations (such as `LinkList`, `DoublyLinkedList`, and `ArrayBasedList`). We'll finish the first two and start on the third. ## Prep **Task 1:** So far, you've focused on the *worst-case* run-time of operations. `addLast` is worst-case linear time because when we run out of room we have to copy over the underlying array. What if that's the wrong measurement though? For `addLast`, we don't need linear time *every* time, just *some* times. What if we accounted for this by instead looking at the run-time *averaged* across multiple calls to `addLast`? Assume that when `addLast` finds the array is out of space it added **2** new slots instead of one? Assume you started with an underlying array with 4 slots. What would the average cost be to end up with 8 elements stored in the `ArrayBasedList`? **Task 2:** Grab your own copy of [these two slides](https://cs18-summer-2021.github.io/static/classes/12/12aux-slides-init.pptx) that Kathi will draw on/fill in during lecture (if you want to take your own notes in them).