This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: if the first item is removed in the AL, then rest shifts over basic op=write (n1) writes O(n) Big O Worst Case running times for Stack Operations, stack of length n 1. Constructor = O(1)  assuming array list creation is O(1) 2. Push = O(n)  every time the doubling happens, the big O is order n 3. Pop = O(1) 4. size = O(1) 5. empty = O(1) 6. clear = O(1) ArrayList is not a good choice because it keeps growing so the empty space in the front is wasted ArrayList running time best case: O(1) worst case: O(n) when autoexpanding  all n items are copied to new array redistribute/amortize (conceptually only!) the array writes. take away each write  except the lowest two  in a spike and give it to one of the adds in the subsequent group (until the next spike) amortized running time is O(1), adding n elements require O(n) time average = how the algorithm behaves over different inputs...
View
Full
Document
 Spring '07
 Sesh
 Data Structures

Click to edit the document details