You are on page 1of 16

Data Structures

Dr Ahmed Rafat Abas


Computer Science Dept, Faculty of Computer and
Information, Zagazig University
arabas@zu.edu.eg
http://www.arsaliem.faculty.zu.edu.eg/
Data Structures and
Algorithms
Chapter 1
1.1 A Philosophy of Data Structures
1.1.1 The need for Data Structures

Representing information is fundamental to


computer science.
The majority of computer programs stores and
retrieves information.
To be practical in terms of storage space and
running time, these programs should organize
their information in a way that supports efficient
processing.
Therefore, the study of data structures and the
algorithms that manipulate them is at the heart
of computer science.
What is meant by a data
structure?
A data structure is a data representation and
its associated operations.

Examples:
integer numbers,
floating point numbers,
arrays of these numbers.
1.1.2 Costs and Benefits

Each data structure has associated costs and


benefits.
A data structure requires a certain amount of
space for each data item it stores,
time to perform a single basic operation,
programming effort.
Each problem has constraints on available
space and time.
The best data structure for a problem is the
one that allows the computer program to solve
the problem efficiently in terms of the required
storage and time.
1.2 Abstract Data Types and Data
Structures
Definitions:
A Type is a collection of values.
For example, the Boolean type consists of the
values True and False.
A Data type is a type together with a
collection of operations to manipulate the
type.
For example, an integer variable is a member of
the integer data type.
A Data item is a piece of information or a
record whose value is drawn from a type.

An Aggregate data item is a complex data


item that contains many data items, probably
their values are drawn from different data
types.
An Abstract data type (ADT) defines a data
type in terms of a type and a set of
operations on that type.
Each operation is defined by its inputs and
outputs.
An ADT definition does not specify how the data
type is implemented.

Encapsulation is the process of hiding


implementation details.
A Data structure is the physical
implementation of an ADT.
Each operation associated with the ADT is
implemented by one or more subroutines.
The term data structure often refers to data
stored in a computer's main memory.
Example:
the mathematical concept of integer, along
with operations that manipulate integers,
form an ADT.
The C++ int variable type is a physical
representation of the abstract integer.
A File structure refers to the organization
of data on peripheral storage, such as a
disk drive or magnetic tape.
Data items have both a logical and a
physical form.
The definition of the data item by an ADT is its
logical form,
the implementation of the data item within a
data structure is its physical form
Data Type
ADT
Type Data item
Operations Logical form

Data structure
Storage Data item
Subroutines Physical form

The relationship between data item, ADT and data structure.


The ADT defines the logical form of the data type, while the
data structure implements the physical form of the data type.
1.3 Problems, Algorithms and
Programs
Definitions
A Problem is a task to be performed.
It is best thought of as inputs and
corresponding outputs.
A problem definition should include
constraints on the resources that may be
used by an acceptable solution but it should
not include any constraints on how the
problem should be solved.
A Function is a matching between inputs
(the domain) and outputs (the range).
Values of the inputs are called the parameters
of the function.
Therefore, all problems are functions
according to this definition.
An Algorithm is a method or a process
adopted in order to solve a problem.
The algorithm takes the inputs of a certain
problem and transforms them to the
corresponding outputs of this problem.
It is possible to find several different algorithms
that can solve a certain problem.
Example: a certain sorting algorithm may be
preferred for small sets of numbers while
another algorithm may be preferred for
large sets of numbers.
A Program is an instance of an algorithm
in a certain programming language.
1.4 Algorithm Efficiency

The efficiency of an algorithm is defined as


how efficient this algorithm makes use of
the available computer resources.
It can be measured by a method called
algorithm analysis.

You might also like