Sei sulla pagina 1di 12

Lecture 2: Abstract Data Types

Abstract Data Types

Mr. Shehreyar Rashid

1
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Some basic questions


• What is an integer?
– How an integer is represented?
– What are the operations that can be performed on
Integers?
– How the integer based operations are performed?

• What is a character?
– What are the operations that can be performed on
characters?
– …

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 2: Abstract Data Types

Abstract Data Types


• Abstract Data Type (ADT): a definition for a data type
solely in terms of
– a set of related data items ( or values)
– a set of operations on data

• Separation of logical properties from the implementation


details.
• Hide Implementation details (Encapsulation !)

• What not how is focus

3
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Abstract Data Types


• Whole numbers (integers)
– Operations
• Arithmetic operations (addition, subtraction, etc.)

• Flight reservation
– List of seats
– Operations
• Find empty seat
• Reserve a seat
• Cancel a seat assignment

4
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Abstract Data Types


• ADTs definition consists of:
– Storage structures (i.e. , data structures) to store data items
– Algorithms for basic operations

• Storage structures/ data structures used in the


implementation
• Provided in a language (primitive or build-in)
• Built from the language constructs (user-defined)

• Separation of a data type from its implementation

5
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Data Structure
• A data structure is the physical implementation of an
ADT.
– Each operation associated with the ADT is implemented by one
or more subroutines in the implementation.

• Data structure usually refers to an organization of data


in main memory.

• File structure is an organization for data on peripheral


storage, such as a disk drive.

6
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Data Type

ADT:
Data Items:
Type
Logical Form
Operations

Data Structure: Data Items:


Storage Space Physical Form
Subroutines

7
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

8
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

ADT’s for Primitive Data Types

9
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Boolean data
Data values: {false, true}

Operations: and &&


or ||
not !

&& 0 1 | | 0 1 x !x
0 0 0 0 0 1 0 1
1 0
1 0 1 1 1 1

FAST, National University of Computer and Emerging Sciences, Islamabad


Lecture 2: Abstract Data Types

Character Data
Store numeric codes (ASCII, Unicode)
1 byte for ASCII
2 bytes for Unicode
ASCII

Unicode

Basic Operations ,
- Comparison (equal, less than, greater)
- Use of numeric codes
FAST, National University of Computer and Emerging Sciences, Islamabad
Lecture 2: Abstract Data Types

Integer Data

Non-negative (unsigned) integer:


Store its base-two representation in a fixed number of bits
(e.g., 16 bits)

88 = 00000000010110002

Signed integer:
Store in a fixed number of bits using either of complement representations:

Operations: arithmetic operators for addition, subtraction,


multiplication and division

12
FAST, National University of Computer and Emerging Sciences, Islamabad

Potrebbero piacerti anche