cs-2852 data structures week 8, class 1 amortized arraylist.add() cs-2852 dr. josiah yoder slide...

Post on 13-Dec-2015

214 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

CS-2852Data Structures

Week 8, Class 1 Amortized ArrayList.add()

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick1

Not in outcomes

The material in these slides is not part of the course outcomes, and is provided only for the curious…

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick2

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-2852Dr. Josiah Yoder

Slide style: Dr. Hornick3

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 callsNot

Random – not averaged over “possible events” Single call – no bound provided for a single call

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick4

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-2852Dr. Josiah Yoder

Slide style: Dr. Hornick5

Attempt 1: Add block of extra space

Draw out approach Block of space

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick6

CS-2852 Dr. Josiah Yoder

Slide style: Dr. Hornick7

top related