Data design and implementation
This presentation is the property of its rightful owner.
Sponsored Links
1 / 35

Abstract Data Types PowerPoint PPT Presentation


  • 95 Views
  • Uploaded on
  • Presentation posted in: General

Data Design and Implementation. Abstract Data Types. Definitions of Java TYPES. Atomic or primitive type A data type whose elements are single, non-decomposable data items - e.g , an int or a float variable Composite type :

Download Presentation

Abstract Data Types

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Data design and implementation

Data Design and Implementation

Abstract Data Types


Definitions of java types

Definitions of Java TYPES

Atomic or primitive type

A data type whose elements are single, non-decomposable data items - e.g, an int or a float variable

Composite type :

A data type whose elements are composed of multiple data items e.g. A CLASS


Structured composite type

Structured composite type

  • Structured composite type:

  • An organized collection of components . The organization determines how to access the components of the collection

  • E.g. An Array or A Tree


Atomic simple and composite data types

Atomic (Simple) and Composite Data Types


Java s built in types

Java’s Built-In Types


The java class construct

The Java Class Construct

  • is used to create composite, unstructured data types.

  • It is composed of :

  • 1. named data fields ( instance variables)

    2. methods.


An array differs from a class

An array differs from a class :

  • An array is ahomogenous structure, whereas

    classes are heterogeneous structures.

    E.g.

    an array of integers has only integers in it.

    A class has variables of different types and methods


Accessing components

Accessing components

  • A component of an array is accessed by its position in the array e.g.

    board[2] [3]


Arrays

Arrays

  • Because array components are accessed by position,

  • an array is a structured composite type.


Component of square

Component of square:

  • A component of a class is accessed by an identifier (the object created of it).

  • Square sq = new Square(10,20, 40, Color.Red);

    • int x = sq.getX();

    • We access the parts of the class with an object


Abstract data types

  • Because class components are accessed by creating an object,

  • an class is a unstructured composite type.


Definitions

Definitions

Data abstraction: The separation of a data type’s logical properties from its implementation

  • A doctor sees (abstracts) the person as patient.  E.g. name, height, weight of a person

  • An employer sees (abstracts) a person as Employee. E.g.name, age,  health, degree of study, of a person.  


Data encapsulation

Data encapsulation

  • We can abstract the important characteristics of Person

  • and store all the characteristics of a person in Person class

  • The Person class can be used by both the Doctor or Employer classes or ……..others


Abstract data type

Abstract Data Type

  • An abstract data type is an interface

  • a) it defines a collection of data e.g. an array of clients

  • b)and the particular operations that are allowed on that array

  • ( through methods )


Abstract data types

ABSTRACT DATA TYPES – ADT’ s

  • An ADT :

  • therefore has a name

  • E.G. A STACK, A QUEUE, An ARRAYLIST

  • A domain of values(data) - the elements in the stack, items stored in the array in the ArrayList

  • a set of operations that can be performed (methods) on the data


Collections details

Collections- Details

  • A collection is an object that serves as a repository for other objects.

  • MOST ADT are Collections - since they store the data they are operating on

  • The Java Collections Framework contains classes that represent collections of objects.


Collections adt s

Collections & ADT’s

  • In general, a collection refers to a class whose role is to:

  • provide methods to add, remove and

  • manage the elements that are in the collection.


Collections arraylist

Collections - ArrayList

  • The ArrayList classin the Collections Frameworkis implemented with an array.

  • There is also a SortedArrayList, which maintains the array in sorted order


Collections adt s1

Collections & ADT’s

  • Collections can be implemented in a variety of ways.

  • The ArrayListuses an Array

    and contains methodsthat perform operations on array.

    e.g.Adding or deleting items etc.


Adt s

ADT’s

  • ADT’scan be implemented with both

    e.g. arrays or linked lists.

  • The choice of an array or a linked listdepends upon the implementation


The arraylist class

The ArrayList Class

  • IS Part of the java.util package.

  • An ArrayList list can grow and shrinkdepending on need.

  • When the array is full, its size is doubled


Arraylist

ARRAYLIST

  • ArrayList class: you store variables of type Object.

  • Or now type T- a generic type built on class Object


Arraylist1

ArrayList

  • An ArrayList has a size() method - how many objects it is currently holding

  • It has other methods :

  • add, remove, find , isEmpty etc. See:

  • http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html


Arraylist operations

ArrayListOperations


Use arraylist unsorted when

Use Arraylist – unsorted - when:

  • The amount of space required may change from one execution of the program to the next.

  • The position of an element in the array list has no relevance to the application.

  • There is no order to the items stored


Abstract data types

Collection Interface & Map Interface


Abstract data types

LIST & SET INTERFACEs


Abstract data types

  • public interface List<E> extends Collection<E>

  • {

  • E get(int index);

  • E set(int index, E element);

  • boolean add(E element);

  • void add(int index, E element);

  • E remove(int index);

  • boolean addAll(int index, Collection<? extends E> c);

  • int indexOf(Object o);

  • int lastIndexOf(Object o);

  • ListIterator<E> listIterator(); ListIterator<E> listIterator(int index); }


Collection interface list inherits these methods

Collection Interface-List inherits these methods

  • public interface Collection<E> extends Iterable<E> {

  • int size();

  • boolean isEmpty();

  • boolean contains(Object element);

  • boolean add(E element);

  • boolean remove(Object element);

  • Iterator<E> iterator();

  • boolean containsAll(Collection<?> c);

  • boolean addAll(Collection<? extends E> c);

  • boolean removeAll(Collection<?> c);

  • boolean retainAll(Collection<?> c);

  • void clear();

  • public <T> T[] toArray(T[] a);


Designing adts this term

Designing ADTs this term

  • Determine the general purpose of your program.

  • List the specific types of operations the application program performs.


Designing an adt

DESIGNING AN ADT

  • Decide first which ADT to use:

  • an ArrayList , A Stack? Depends on the problem

  • Identify a set of public methods to be provided by the ADT class to perform the desired operations


Designing adts

Designing ADTs

  • Identify potential error situations and classify into

    • Those that are handled by throwing an exception

    • Those that are ignored.


Designing adts1

Designing ADTs

  • Define the needed exception classes.

  • Decide on a protection level for the identified data.

  • Implement the ADT. ( Using the ARRAYLIST OR STACK

  • Create a test driver and test your ADT.


Abstract data types

Analysis of List Implementations

  • In both array and linked implementations,

  • many operations are similar in efficiency

  • Most are O(1),

  • except when shifting or searching occurs, in which case they are order O(n)

35


  • Login