Monday, February 11, 2008

DataStructures

DATA TYPE:
A method of interpreting a bit pattern.

ABSTRACT DATA TYPES:
Tool for specifying the logical properties of the datatype. Its java counterpart is interface. It declares the methods,but the implementation details are not mentioned and can be changed according to the context of the class that implements the interface. Hence here, it defines the logical properties abstractly.
Eg: For array,

ADT definitions:

abstract typedef <> array(ub,eltype);
condition type(ub) == int;

This specifies that array in C will have two arguments one is ub(upper bound) and the other is eltype(element type). Upper bound is specified to allocate that many number of contiguous memory locations. The element type specifies which type of element each mem. location is going to hold.
This can be extended to other language array representation with some details. For eg in Pascal, int arr[-3..10] specifies both upper bound and lower bound for the array along with eltype of int. Thus ADT would be sth like

abstract typedef <> array(lb,up,eletype);
condition type(ub) && type(lb) == int;

DATASTRUCTURES:

COMPOSITE OR STRUCTURED DATATYPES:
These are made up of simpler data structures. One such datatype is array.

ARRAY:
Array is a finite ordered set of homogeneous elements.

finite: Only finite no. of elements can be stored in an array.
ordered set: the elements are arranged.
homogeneous: may contain one datatype or the other but not the both.

we know in C, int a[10] declares a continuous memory locations starting from a till a+10*sizeof(int). The base (a) is a pointer to the starting location of the array. The disadvantage of the array is that it contains homogeneous elements. But it the simplest form of storing large value.
Another disadvantage interms of efficiency, while dealing with large number of inputs, the insertion and delete all are difficult or atleast will not be efficient.Mutlidimensional arrays are viewed as single dimensional arrays stacked together. The array can be represented as row-major representation where a[2][1] is represented as,

--------
|a[0][0] |
--------
|a[0][1] |
--------
|a[1][0] |
--------
|a[1][1] |
--------
|a[2][0] |
--------
|a[2][1] |
---------

No comments: