Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
UNIT-I
INTRODUCTION
TO
DATA STRUCTURES
DATA AND INFORMATION
INFORMATION AND ITS
STORAGE REPRESENTATION
• STORAGE OF INFORMATION
OPERATIONAL UNITS
STORAGE UNITS
Operational Unit:
Register: temporary storage
present in CPU
aids in arithmetic calculations
stores operands and results
Storage Units:
permanent storage
store instructions and data
main memory, secondary memory
Main memory : semiconductor memory
has voltage representation
stored in flip-flops(2-state device)
Secondary : magnetic core memory
DATA STRUCTURE
• the organization of data
Linear DS: traverses the data elements sequentially, in which only one data
element can directly be reached.
Non-linear DS: Every data item is attached to several other data items in a way
that is specific for reflecting relationships. The data items are not arranged in a
sequential structure.
CONCEPTS & TERMINOLOGY
FOR NON-PRIMITIVE DS
• Non-primitive DS: arrays, lists, files
• Array: ordered set of fixed no. of objects;
no insertion and deletion operation(no change in array size)
• List : ordered set of variable no.of elements, with
insertion, deletion, combine, split, copy, sort,
search operations
• File : large list stored in external memory of
computer
Obtaining address of an element:
• computed address :
• link/pointer address:
Example:
An array of integers to store age of students
An array of strings to store student names
TERMINOLOGY
• SIZE – no. of elements in an array
• TYPE – data type of elements
• BASE – address of memory location
where first element is stored
..
456
455
454
• Size of array : U – L + 1
• To get the size of array A[5]
• 4–0+1=5
array
MEMORY ALLOCATION
Physical representation of one-dimensional array
1000
A[0]
1004
A[1]
1008
Address ( A[i] ) = M + ( i – L ) * w .
where M = base address
.
i = index j
L = lower bound .
w = word length
.
Address of A[1]=
=1000 + (1 – 0 ) * 4 100
=1004
A[100]
MEMORY ALLOCATION ….
Address mapping between logical and physical views of an array
Address ( A[i]) = M + (i – L ) * w
Algorithm TRAVERSE_ARRAY( )
Input: An array A with elements
Output: According to PROCESS ( )
Data structure: Array A [ L … U ] // L = lower bound; U = Upper bound
Steps:
1. i = L
2. While i <= U do
1. PROCESS A[i] //procedure to perform an action Eg: display element on
screen
2. i=i+1
3. EndWhile
4. Stop
Sorting…This operation is used to arrange the elements in the
array in ascending or descending order
Algorithm SORT_ARRAY( )
Algorithm : SearchArray(KEY)
Algorithm DELETE(KEY)
m=rows
n=columns
-Example:
Rows = 3 ; columns = 4
Memory representation of a matrix
Uses:
- Wastage of memory if entire matrix is stored
-Triangular matrices
-Upper left, upper right, lower-left, lower-right
-Diagonal matrices
-Diagonal matrices
-Tridiagonal matrices
TRIANGULAR MATRICES
DIAGONAL MATRIX - a matrix having non-zero
elements only in the diagonal running from the upper left to the
lower right or upper right to lower left
TRIDIAGONAL MATRICES -hasnonzero
elements only on the main diagonal, the first diagonal below
this, and the first diagonal above the main diagonal
EXAMPLE :
αβ- BAND MATRIX : non-zero entries are
confined to a diagonal band, comprising the main
diagonal and zero or more diagonals on either side
POINTER ARRAYS
Pointer : holds address of memory variable or array
Maintains 3 arrays: