70 likes | 211 Vues
CS-2852 Data Structures. Week 8, Class 1 Amortized ArrayList.add (). Not in outcomes. The material in these slides is not part of the course outcomes, and is provided only for the curious…. Amortized Analysis. Amortization
E N D
CS-2852Data Structures • Week 8, Class 1 • Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Not in outcomes • The material in these slides is not part of the course outcomes, and is provided only for the curious… CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Amortized Analysis • Amortization • “The paying off of debt in regular installments over a period of time.” – Investopedia • The average cost of an operations over multiple calls – Amortized analysis CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Amortized Analysis (2) • Is • Worst-case bound – just like Big-O we’ve discussed so far • Cost of a single call average over a special group of calls • Not • Random – not averaged over “possible events” • Single call – no bound provided for a single call CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Amortized AddHow we avoid O(1) add(E) • If we have enough capacity, this is easy! • [Draw on board] • Array with extra capacity • Then just stick in the extra element CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
Attempt 1: Add block of extra space • Draw out approach • Block of space CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick
CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick