Data structures and algorithms
Data structures and algorithms
•
Program design= algorithm + data
g
g
g
•
Algorithm: is a logical sequence of steps that
describes a complete solution to a given
problem computable in a finite amount of time
problem computable in a finite amount of time.
•
Analysis of algorithms is used to predict the
efficiency of the algorithms in order to select
th b
t
the best one.
•
Analysis can be done on the:
1
Space (size)
1. Space (size)
2. Time (Speed)
Data
• Our world is full of DATA that need to be processed, so what is data?
• Data : are nouns of the programming world: the objects that are manipulated, the information that is processed by a computer program.
• Data: The representation of information in a manner suitable for • Data: The representation of information in a manner suitable for
communication or analysis by humans or machines
• In the context of a programming language, the term p g g g g
data
refers to the representation of such information, from the problem domain, by the data types available in the language.• Data from the computer point of view is just a collection of bits (1,0) • Data from the human beings point of view is numbers, names, lists
Data abstraction
Data abstraction
• Data abstraction: the separation of data type’s
p
yp
logical properties from its implementation.
• Ex. Integers can be physically represented as:
i
d
i
d BCD 2’
l
signed, unsigned, BCD, 2’s complement ….
• But As a programmer, however, you don’t
usually get involved at this level; you simply use
usually get involved at this level; you simply use
integers. All you need to know is how to declare
an int type variable and what operations are
Thinking
Thinking…
• In order to use the data in an efficient way we have to answer some questions such as :
questions such as :
• How to store data in a Computer Program? • How to organize the involved Data?
• How data are arranged in relation to each other?How data are arranged in relation to each other? • Which operations and parameters?
• Which data are kept in the memory? • Which are calculated when needed?
• Which are kept in files, and how the files are arranged? • Which method is more efficient?
• Which Programming Language?
Data Structures
Data Structures
• We need to organize our Data used in a program In data
g
p g
structures
• We need to specify such Data Structures
• Specification of Data Structures can be done through
what called an Abstract Data Types (ADT) that
describes:
describes:
• The Types of Data
Data Structures
• Data type A category of data characterized by the supported elements of the category and the supported operations on those elements
• Atomic or primitive typeAtomic or primitive type A data type whose elements are single none-A data type whose elements are single, none decomposable data items
• In effect, all the Java built-in types are ADTs (Abstract Data Types). A Java programmer can declare variables of those types without understanding the underlying implementation. The programmer can initialize, modify, and
u de y g p e e a o e p og a e ca a e, od y, a d
access the information held by the variables using the provided operations. • Abstract data type: is to define the domain and the structure of the data a
long with a collection of operations that access the data without implementation dependency
• Ex. Integer : N , { +, -,*, / }
Boolean: { true, false} , {and , or, not xor }
• Data structure A collection of data elements whose logical organization reflects a relationship among the elements. A data structure is characterized reflects a relationship among the elements. A data structure is characterized by accessing operations that are used to store and retrieve the individual data elements.
Data Levels
• In modeling data in a program, we must determine the
abstract properties of the data, choose the
representation of the data, and develop the operations
p
,
p
p
that encapsulate this arrangement. During this process,
we consider data from three different levels:
•
1.
Logical (or abstract) level:
An abstract view of the data
values (the domain) and the set of operations to
manipulate them. At this level, we define the ADT.
•
2.
Application (or user) level:
A way of modeling real-life
d t i
ifi
t
t
l
ll d th
bl
data in a specific context; also called the problem
domain. Here the application programmer uses the ADT
to solve a problem.
3
I
l
t ti
l
l
A
ifi
t ti
f th
Aims of studying Data structures
Aims of studying Data structures
1 analysis and tradeoffs (advantages
1. analysis and tradeoffs (advantages,
disadvantages).
2 time efficiency (organize data so that the
2. time efficiency (organize data so that the
algorithms used to access it are efficient in
time)
time).