Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preliminaries Attendance sheets –I remembered! HW1 due tonight –progress report Stage 1 due on Friday –progress report.

Similar presentations


Presentation on theme: "Preliminaries Attendance sheets –I remembered! HW1 due tonight –progress report Stage 1 due on Friday –progress report."— Presentation transcript:

1

2

3 Preliminaries Attendance sheets –I remembered! HW1 due tonight –progress report Stage 1 due on Friday –progress report

4 Today Finish off discussion Bag’s iterator class –For-each loop: syntactic sugar Software design issues –In context of list definition Recursion –In context of list definition

5 Lists We’ve seen an array-based implementation of a Collection, the Bag. ArrayList is very much the same. –We’ll take a short tour of the code

6 Advantage of an array-based implementation: –fast access to a specific index –typically less space usage than other options Disadvantage of an array-based implementation: –can be expensive to insert items –resizing is an expensive operation

7 Amortization Resizing of array-based data structures involves a tradeoff: –many insertions (as in our Bag) are very efficient since no allocation of space is required (an array is allocated as a big block of memory) –some insertions (as in our Bag) are very expensive since resizing must take place

8 Linked List A linked list is a list implementation which spreads out the cost of space allocation evenly to all insertions. Each insertion involves allocation of space

9 Advantages/Disadvantages Advantages –predictable cost of insertion –efficient insertion at any point in structure Disadvantages –extra space required to store links –inefficient indexing

10 Comparison of storage A pair has a first and a second element When pairs are used to construct lists, the first is called the “head” or the “car” the second is called the “tail”, “rest” or “cdr” the pair is called a “cons cell” or simply a “cons”.


Download ppt "Preliminaries Attendance sheets –I remembered! HW1 due tonight –progress report Stage 1 due on Friday –progress report."

Similar presentations


Ads by Google