Professional Documents
Culture Documents
DEPARTMENT OF COMPUTER
SCIENCE
• Any computer system are based on three activities – storing, accessing, and
manipulating data in one form or the other
• Divided into major categories like Operating System, databases, Compilers, Artificial
Intelligence, etc.
• These fields will address the tasks of storing, accessing, and manipulating data
• Should they also need a course on Data Structures? Yes they need it.
Definitions
Types
Integers …,-4,-3,-2,-1,0,1,2,3,4,…
Data Type
The domain of values (type) and the operations that can be performed on these values
There are two types of definitions. They are structural definitions and behavioral definitions
Structural definition – the structure of the values is defined for examples, a fraction can be
defined as the one that has:
Behavioral definitions - do not impose any constraint on the structure. Use functions to
define the behaviors of the data type for examples, we can assume, that we have a function
create_fraction(N,D) that creates a fraction, given two integers N and D.
Struct Fraction {
Int nr,dr;
} f;
Implementation 2:
#define Nr 0
#define Dr 1
In the main program, you can have statements like the following for defining the fractions
and accessing their numerators and denominators:
Fraction f;
f[Nr] = 4;
f[Dr] = 5;
• An abstract data type(ADT) is a data type in which the members of the data type are
unknown to users of the type.
• Both the user and the implementor have to agree on type of the interface
• ADT stack can be defined as a list of elements in which the elements can be inserted
or deleted from one end of the collection. It refers to the ‘Last in First out’ list.
Create_fraction(N,D),get_Numerator(),get_Denominator()
Using these we can define functions like add, multiply, for specific operations.
• Supports encapsulation
3. No need to change the modules that use the ADT, when the implementation
change
Pre-and Post-conditions
Pre-conditions refers to the properties of the inputs assumed by the operation defined. This
defines the state of the program the client guarantees that will be true before calling a
function.
For example, in a Stack ( a last in first out list) an ‘insert operation’ assumes that there is
enough space to store the element and similarly the ’delete operation’ assumes that there is
atleast an element in the stack for deletion
Data Structures
It is a physical representation of an ADT. We indicate the data type and also suggest how
these could be stored on the computer system memory.
For example, an integer as a data structure can be defined as a integer data type stored on
consecutive memory bytes.
1. fixed length
2. variable length
Fixed Length - implementation, all strings will have the same amount of memory location
allocated
Variable Length – a terminating character such as NULL is used to terminate a String, this
eliminates the problem of memory wastage
• Also classified according to the ordering of the elements in them – Linear and
Nonlinear
• Linear data structures – elements have linear order in between them(1,2 3…)
• File Structures