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

7
CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

Upload: clementine-wright

Post on 13-Dec-2015

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

CS-2852Data Structures

Week 8, Class 1 Amortized ArrayList.add()

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick1

Page 2: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

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

Page 3: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

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

Page 4: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

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

Page 5: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

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

Page 6: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

Attempt 1: Add block of extra space

Draw out approach Block of space

CS-2852Dr. Josiah Yoder

Slide style: Dr. Hornick6

Page 7: CS-2852 Data Structures Week 8, Class 1 Amortized ArrayList.add() CS-2852 Dr. Josiah Yoder Slide style: Dr. Hornick 1

CS-2852 Dr. Josiah Yoder

Slide style: Dr. Hornick7