0% found this document useful (0 votes)
35 views12 pages

Abstract Data Type

The document discusses abstract data types (ADTs) and how they are implemented using data structures. It defines an ADT as a collection of related data items and operations on those items, independent of implementation details. A data structure then provides the physical implementation of an ADT by defining storage structures for the data and algorithms for the operations. Some basic simple data types like Boolean, character, and integer data types are also described along with their common representations in memory.

Uploaded by

Shahzaib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views12 pages

Abstract Data Type

The document discusses abstract data types (ADTs) and how they are implemented using data structures. It defines an ADT as a collection of related data items and operations on those items, independent of implementation details. A data structure then provides the physical implementation of an ADT by defining storage structures for the data and algorithms for the operations. Some basic simple data types like Boolean, character, and integer data types are also described along with their common representations in memory.

Uploaded by

Shahzaib
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Data Structures & Algorithms

Abstract Data Type


Data Structures & Algorithms

Abstract Data Types

A definition for a data type solely in terms of a set of values and a


set of operations on that data type.

Each ADT operation is defined by its inputs and outputs.


Encapsulation:
Combine Data and
implementation Functions in a single entity to hide
details.
Data Structures & Algorithms

Abstract Data Types


Def. a collection of related data items together with
an associated set of operations

e.g. whole numbers (integers) and arithmetic operators for


addition, subtraction, multiplication and division.

e.g. Flight reservation


Basic operations: find empty seat, reserve a seat,
cancel a seat assignment
Why "abstract?"
Data, operations, and relations are studied
independent of implementation.

What, not how is the focus.


Data Structures & Algorithms

Abstract Data Types

Def. Consists of
storage structures (data structures)
to store the data items
and
algorithms for the basic operations.

The storage structures/data structures used in


implementations are provided in a language (primitive or built-
in) or are built from the language constructs (user-defined).

In either case, successful software design uses data


abstraction:

Separating the definition of a data type from its


implementation.
Data Structures & Algorithms

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.
Data Structures & Algorithms

Data Type

ADT:
Data Items:
Type
Logical
Operations Form

Data Structure: Data Items:


Storage Space Physical
Subroutines Form
Data Structures & Algorithms

Simple Data Types


Memory:
2-state devices « bits 0 and 1

Organized into bytes (8 bits) and


words (machine dependent — e.g., 2 bytes).

Each byte (or word) has an address making it possible to store and
retrieve contents of any given memory location.

Therefore:
the most basic form of data: sequences of bits
simple data types (values are atomic — can't be subdivided) are ADTs.
Implementations have:
» Storage structures: memory locations
» Algorithms: system hardware/software to do basic operations.
Data Structures & Algorithms

Boolean data

Data values: {false, true}

In C/C++: false = 0, true = 1 (or nonzero)

Operations: and &&


or ||
not !
&& 0 1 | | 0 1

0 0 0 x !x
0 0 1
1 0 1
0 1
1 1 1 1 0
Data Structures & Algorithms

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

Unicode

Basic operation: comparison to determine if Equal, Less than ,Greater


than, etc. use their numeric codes (i.e. use ordinal value)
Data Structures & Algorithms

Integer Data

Non-negative (unsigned) integer:


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

88 = 0000000001011000
2

Signed integer:
Store in a fixed number w of bits using one of the following representations:
Data Structures & Algorithms

Sign-magnitude representation

Save one bit (usually most significant) for sign


(0 = +, 1 = – )

Use base-two representation in the other bits.

88  0 _000000001011000


sign bit

–88 _000000001011000
1

Cumbersome for arithmetic computations


Data Structures & Algorithms

Two's complement representation


Same as
For nonnegative n: sign mag.
Use ordinary base-two representation with leading (sign) bit 0

For negative n (–n):


(1) Find w-bit base-2 representation of n
(2) Complement each bit.
(3) Add 1 (Flip all bits from rightmost 0 to the end)

Example: –88
1. 88 as a 16-bit base-two number 0000000001011000
2. Complement this bit string 1111111110100111
3. Add 1 1111111110101000

You might also like