Вы находитесь на странице: 1из 7

Ds_tpx.

1 Data Structures
Overview

DEFINITION: Data Structures is an area of Computer


Science in which various methods, techniques, and styles for
ORGANIZING AND REPRESENTING “DATA” IN
STRUCTURAL FORMS AND PROCESSING OF THOSE
STRUCTURAL FORMS are studied. The extent of complexity
of the structural forms can vary from very simple to quite
complex.
One point must be made clear. Data Structures sparingly, if at all, deals
with the organization of massive amounts of data and its permanent
storage on secondary storage media such as hard disks, optical disks etc.
Such aspects of data are more deeply and appropriately studied in the
domain of “Database Systems”. Instead, Data Structures emphasizes on
how simple data can be REPRESENTED and ENCAPSULATED in
increasingly more complex forms IN ORDER TO MAKE ITS
PROCESSING RELATIVELY SIMPLER, EASIER, AND ERROR
FREE, ESPECIALLY FROM A PROGRAMMING POINT OF VIEW.

WHAT IS DATA?
In the MOST FUNDAMENTAL AND PRIMITIVE SENSE THE
VARIOUS PROPERTIES OR ATTRIBUTES ASSOCIATED WITH
SOME OBJECT, FACT OR ASSUMPTION OR WITH A
COLLECTION OF OBJECTS AND/OR FACTS AND/OR
ASSUMPTIONS IS CALEED “DATA”.

As an example, although, a “star” is actually a physical heavenly body


but when it is viewed (i.e. perceived) by a person, who is looking
upwards in the sky, the attributes immediately discovered by the viewer
such as round shape, luminosity, and very far distance can be
considered as data related to the star. On the other extreme, with
respect to physical size, a letter “X” written on a small piece of paper is
also an instance of data, when it is read by someone. In both cases, i.e.
star and piece of paper the data is associated with an object which is the
star or the piece of paper. How could data be associated with a fact?
Suppose someone is doing research in mathematics and he or she
Ds_tpx.2 discovers the fact that 32 + 42 = 52 i.e. the Pythogoran equation a2
+ b2 = c2 is being satisfied by the integers 3, 4, and 5. In this case the
satisfaction of the equation by 3,4, and 5 is the FACT which has the
values a=3, b= 4, and c = 5 for its attributes a, b, and c. In other words
we may say that the set of values 3, 4, and 5 is the data associated with
the fact 32 + 42 = 52. Definitely we would not call 32 + 42 = 52 an object
instead of a fact.

The same data may appear in different forms depending upon how and
when it is viewed by a human or machine. For example, signals
emanating from a network connection wire and entering a computer’s
port are an instance of data, because the signals (carrying email
messages, web pages etc.) are being electronically perceived by the
computer, and the physical characteristics (such as frequency,
amplitude etc.) of the signals would be used by the computer software to
extract more sophisticated data (web page contents, color, email
message text, networking protocol parameters etc.) from them.

THUS IT MAY BE CONCLUDED THAT THE SAME DATA CAN BE


VIEWED AT A VERY PRIMITIVE LEVEL (SIGNALS) AND ALSO
AT A VERY SOPHISTICATED LEVEL (WEB PAGES). THUS THE
SAME DATA MAY EXIST IN DIFFERENT FORMS DEPENDING
UPON THE LEVEL OF SOPHISTICATION OR COMPLEXITY AT
WHICH IT IS VIEWED.

What is meant by Data Structures?


In the area of computers or computer programming data, at a most
fundamental level is USUALLY a collection of symbols such as “A”,
“G”, “D”, “?”, “%”, “@”, or computer memory addresses or numeric
objects such as integers or real numbers etc. More complex types of
data may be built from one or more of these basic types of data. It is the
METHODS and TECHNIQUES OF BUILDING, REPRESENTING,
AND PROCESSING COMPLEX AND USEFUL GROUPINGS of data
from the fundamental types of data just mentioned which form the
essence of the domain of knowledge called “Data Structures”.
Ds_tpx.3
How can the C Language be used for building Data
Structures?
The C Programming Language has a number of built-in basic Data
Types for representing data at a Fundamental and Primitive level. For
example, in C, the int data type can be used to store and represent
numeric values of integers. Variations of the int data type are the long
data type for storing a larger range of integers, the short data type for
storing smaller integers, the unsigned int, unsigned long, and unsigned
short data type for storing unsigned integers (starting from 0 onwards).
Similarly the float, double, and long double data types can be used to
store floating-point (real numbers in exponential form) numbers with
increasing degrees of precision and ranges of storable values, reading
from left to right. The char data type in C is very special and different
from the numeric data types already mentioned. Although C is flexible
enough to allow the use (for example, in calculations) of the char data
type as a numeric data type for storing very small integers (-127 to
+128), however, the char data type is basically meant for storing
characters (or symbols) such as A,P,>,&,?,:,5,0,/,G,) etc. many of which
can be found on a computer’s keyboard. Up to 256 different symbols or
characters, some of which are non-printable, can be stored in the char
data type.

There is also a very special data type in C which is called the pointer
data type. The pointer data type can be used to store the addresses of
variables of the data types already mentioned in the memory of a
computer. Although a pointer data type contains an unsigned integer,
and is therefore numeric in nature, it must be used for the purpose of
storing memory addresses only.
Ds_tpx.4 IN C, A VALUE (NUMERIC OR CHARACTER) CANNOT BE
STORED IN A DATA TYPE UNTIL AND UNLESS THERE IS A
“VARIABLE” OF THAT DATA TYPE AVAILABLE. A VARIABLE
IS SIMPLY A “NAME” GIVEN TO SOME MEMORY LOCATION
WHERE THE VALUE TO BE STORED WILL BE STORED.
VRIABLES IN C CAN HAVE NAMES CONSISTING OF
ALPHANUMERIC CHARACTERS(capital or small letters, digits 0-9,
and the underscore _). THE FIRST CHARACTER IN THE NAME OF
A VARIABLE MUST BE A LETTER. EXAMPLES OF VRIABLE
NAMES ARE alpha45, total_amount, CustomerName, ABC_243 ETC.

How can a variable be made available for storing some value? The
answer is simple! By DECLARING the variable. For example 4
variables of the int data type may be declared as follows:

int myvar, x1;


int abc25, sum_total;

In the above example 4 different variables of the int data type have been
declared. The names of the variables are myvar, x1, abc25, and
sum_total. Each of these variables is now available for storing an integer
by using the assignment statement of C, as shown below:

myvar = 28;
x1 = 7 + 92;
abc25 = myvar + 13;

4 variables of the float data type may be declared as follows:


float fx1, fx2;
float amr, bulk_val;

The 4 float variables can now be used to store real numbers, as shown
below:
fx1 = 409.56201;
bulk_val = 0.5796;

Variables of other data types may be declared and used in a similar


way.
Ds_tpx.5
Two building blocks in C for building Data Structures

Two features of C language make it easy or convenient (or, in fact,


possible) to build complex data structures by combining and using these
features in various ways. Those two features of C are structures and
arrays. Structures and arrays may be used separately or in combination
to build data structures from basic data types (e.g. int, long, float, char
etc.). A structure or array has no significance by itself. Instead a
structure or array derives meaning and significance from the collection
of one or more data types it contains or is composed of. It is this
characteristic of “being composed of a collection of one or more simpler
data types” which enables an array or structure to be considered a data
structure in its own right.

One instance of using arrays and structures IN COMBINATION to


build a complex data structure occurs when, for example, A
STRUCTURE CONTAINS AN ARRAY AS ONE OF ITS
COMPONENTS IN ADDITION TO OTHER COMPONENTS WHICH
ARE USUALLY ONE OR MORE BASIC DATA TYPES (int, long,
char, float etc.). Another instance of combining arrays and structures
occurs when there is an array consisting of an ordered sequence of
structures, with each structure in the sequence having the same form
with respect to the data types it is composed of.

It is getting … Ah!... a bit late! So much has been mentioned about how
structures and arrays in C may be used to build data structures, but no
definition of what a structure or array is has been given!

A structure in C is simply a feature for combining or grouping ONE OR


MORE OCCURENCES OF DIFFERENT DATA TYPES (e.g. int, char,
long, float etc,) INTO ONE UNIT OR GROUP WHICH IS CALLED A
STRUCTURE. A structure is identified by the “struct” keyword in C.
Before any variable associated with a particular type of structure can be
declared and used in a C program, the structure must be defined. This
definition of the structure is the only way of telling the C program what
data types the structure is composed of! An example of a structure
definition is given below:
Ds_tpx.6 struct mystruct {
int a, b;
float x1, x2, x3;
float r;
int m1, m2, n, g;
char ch, abc;
};

In the above example a structure named mystruct has been defined.


mystruct consists of 6 variables or components of type int, 4 of type
float, and 2 of type char. Thus 12 variables of three different data types
have been combined or grouped into a single unit called mystruct.
IMPLICITLY A USER OR PROGRAMMER-DEFINED DATA TYPE
HAS BEEN CREATED. A variable in which a structure of type
mystruct may be stored can be declared as shown by the following
example:

struct mystruct st1, st2;

After this, values may be assigned to elements of st1 and st2 in the
following manner:

st1.a = 10;
st1.x3 = 2.46;
st2.ch = ‘B’;
st2.r = 67.9043;
st1.r = 9.00762;
st1.ch = ‘F’;


Thus, in order to access the elements of a variable representing a
structure, the “.” (i.e. dot) is used as shown in the above example.
So much for structures. Now what is an array? An array in C is simply
Ds_tpx.7 an ordered sequence of n (n = 1, 5, 8, 15, 50, 70, 100, 400, 1000 etc.)
elements of the SAME DATA TYPE. Each element of the array is
identified by the ARRAY NAME and an integer called its index which
increases by 1 for each successive element, starting from 0. The highest
index value is determined by the NUMBER OF ELEMENTS IN THE
ARRAY WHICH IS SPECIFIED AT THE TIME OF DECLARING
THE ARRAY AS A VARIABLE. If the number of elements in the
array is, for example, 60, the values of the array index would range
from 0 to 59. In order to use an array and assign values to its individual
elements, the array must first be declared. An array may be declared as
a variable as shown by the following example:

int abc[1300], test[40];


char name[30];
char address[100];

In the above example 2 arrays called abc and test consisting of 1300
and 40 integers, respectively, and 2 arrays called name and address,
consisting of 30 and 100 elements, respectively, of type char have been
declared.

The individual elements of arrays may be accessed and values may be


assigned to them as shown by the following example:

abc[0] = 3057;
abc[578] = 21984;
test[31] = 19820;
name[0] = ‘A’;
name[1] = ‘l’;
name[2] = ‘i’;
name[3] = ‘\0’;
strcpy(address, “A-496, 4th Street, Middletown, Cronton”);

One point must be clear! A STRUCTURE is used to group a collection


of DIFFERENT DATA TYPES into one unit while an ARRAY is used to
group a (usually long) sequence of the SAME DATA TYPE INTO ONE
UNIT.

Вам также может понравиться