Introduction to ADTs
Tom Kelliher, CS23
Feb. 26, 1996
Imagine:
- Large team project to create, prove, develop product
- Fiefdoms
- Proof of concept prototype
- Re-write for time/space efficiency before shipping
What can go wrong?
How can these problems be addressed?
- Procedural abstraction --- what, not how
- Information hiding
- Data abstraction
A collection of data together with a set of operations on that data.
- Simula68
- Objects
- Object oriented programming
Interface/Implementation (data structure)
ADT examples:
- Integers
- Complex numbers
- The factorial of a number
- Matrices
- A chair
- An automobile
- A CD collection (classical vs. rock)
A list is a collection of ordered items
- Head
- Tail
- Successor, predecessor
- Order
- Items
- Insertion/deletion semantics --- yield different ``lists:''
- Anywhere --- list
- Insert at tail, delete at head --- queue
- Insert, delete at head --- stack
- CreateList()
- DestroyList()
- ListIsEmpty()
- ListLength()
- ListInsert(newPosition, newItem, success)
- ListDelete(position, success)
- ListRetrieve(position, dataItem, success)
List Parameters???
Pre- Post-Conditions
Have we specified a data structure (implementation)?
Behavioral specification
Example:
List l;
dataItem d;
l.CreateList();
l.ListInsert(1, bread, success);
l.ListInsert(2, butter, success);
l.ListInsert(3, jam, success);
l.ListInsert(4, toaster, success);
l.ListRetrieve(2, d, success);
l.ListDelete(2, success);
Without knowledge of the implementation:
- Write a display function
- Write a multiple insert function
- Delete all items and destroy entire list
- Build other ADTs from ADT List:
- Sorted list
- queue
- stack
Example: ADT Sorted List Operations:
- CreateSortedList
- DestroySortedList
- SortedListIsEmpty
- SortedListLength
- SortedListInsert(newItem, success)
- SortedListDelete(item, success)
- SortedListRetrieve(position, dataItem, success)
- LocatePosition(anItem, position, success)
- Set
- Matrix
- String
- Terry Winograd developed a program called SHRDLU that was intended to
model a simple ``world'' consisting of children's blocks of various shapes
and colors. Among other things, SHRDLU was designed to simulate
manipulation of the blocks by picking them up and placing them elsewhere.
Design ADT block operations.
Thomas P. Kelliher
Mon Feb 24 15:09:03 EST 1997
Tom Kelliher