Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 CS162: Introduction to Computer Science II Abstract Data Types.

Similar presentations


Presentation on theme: "1 CS162: Introduction to Computer Science II Abstract Data Types."— Presentation transcript:

1 1 CS162: Introduction to Computer Science II Abstract Data Types

2 2 Abstract and Concrete Data Types Abstract data type: Defines the fundamental operations on and properties of the data but does not specify an implementation Concrete implementation of a list ADT, for example, determines whether we use a singly or a doubly linked list

3 3 Abstract Data Types An abstract list data type is an ordered sequence of items that can be traversed sequentially and that allows for efficient insertion and removal of elements at any position An abstract array data type is an ordered sequence of items with random access via an integer index

4 4 Specifications for the List ADT Operations on lists –Add new entry –Remove an item –Remove all items –Replace an entry –Look at any entry –Look for an entry of a specific value –Count how many entries –Check if list is empty, full –Display all the entries

5 5 Specifications for the Array ADT Operations on arrays –Get an item at a specific index –Set an item at a specific index –Get the length of the array

6 6 ADTs Note that these operations do not depend on the element type. Note that we have not specified how the data will be stored or how the operations will be implemented. An ADT is an abstraction of the data structure. Ordinarily, an ADT is described by an interface. –Remember interfaces are for describing behavior or operations!! Java has a List interface but not an Array interface (but we can still think of Arrays as an abstract data type)

7 7 Java Class Library: The List Interface The standard package contains a list interface – called List Methods provided: public boolean add(Object newEntry) public Object remove(Object anEntry) public void clear() public boolean contains(Object anEntry) public int size() // like getLength public boolean isEmpty()...

8 8 Java Class Library: The List Interface Note: The functions in the previous slide are the fundamental operations on lists The List interface provides additional methods such as those involving random access (although these are done very inefficiently): Some (such as Dr. Budd) would not include these in the list interface, but a separate Indexed interface. public void add(int index, Object newEntry) public Object remove(int index) public Object set(int index, Object anEntry) // like replace public Object get(int index) // like getEntry

9 9 How to use abstract data types When programming, figure out what operations you need to do on a data structure Then figure out the abstract data type that supports those operations (without thinking about the implementation details) Find an implementation of that ADT that is efficient


Download ppt "1 CS162: Introduction to Computer Science II Abstract Data Types."

Similar presentations


Ads by Google