Sunteți pe pagina 1din 9

Data Structure:

Data are simply values or sets of values. A data item refers to a single unit of values. Data
items that are divided into sub items are called group items, those that are not are called
elementary Items.
The term "information" is sometimes used for data with given attributes, or, in other
words, meaningful or processed data. The way that data are organized into the hierarchy
of fields, records and files reflects the relationship between attributes entities and entity
sets.
A data structure can be defined informally as an organized collection of values and a set
of operations on them. For the integer data structure, the operations are just addition,
multiplication, and so on; for a data base, the operations may include complex queries.
The simplest type of data structure is an array. An array has storage and retrieval via
subscripts.
Somewhat more formally, we define a data structure to have three components:
A set of function definitions: each function is an operation available to the rest of
the program.
A storage structure specifies classes of values, collections of variables, and
relations between variables as necessary to implement the functions.
A set of algorithms, one for each function: each algorithm examines and modifies
the storage structure to achieve the result defined for the corresponding function.
The function definitions separate the implementation of the data structure from the
construction of the rest of the program. They define the externally observable behavior of
the data structure, while the storage structures and algorithms are the internal details. The
latter can be changed without modifying routines that use these functions.
One simple example of a data structure is an array. The set of functions on array is
Store: Must be given a value and a subscript. Associates the value with that
particular subscript.
Retrieve: Must be given a subscript. Reports back the value most recently
associated with that subscript.
storage structure for array consisting of twenty real variables:
A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18,
A19, A20: real
With this storage structure the algorithm for store and retrieve:


The smallest, most primitive storage structure is the single bita unit so elementary that
a bit variable can have only two values. These are usually called zero and one or true and
false. Computer hardware does not usually operate on individual bit variables but instead
deals with groups of bits called words.
A word is a sequence of bitsthat is, a number of bits organized in a row. We can
picture a word like this:

where each little box contains one of the two possible values for a bit. Bits at the left are
called high-order, those at the right low-order. Usually a word value is written without
the boxes, simply as a string of values, such as
0101011101001000

Four types of interpretation of words are provided:
Logical: The value is a string of bits, each of which may be interpreted independently of
the others.
Integer: The values are treated according to the rules of the common arithmetic
operationsaddition, subtraction, multiplication, and division.
Floating Point:
As with integers, the operations are those of arithmetic. However, a portion of each word
is used to indicate the location of the decimal point.
Character: There is a translation between the bit value of each byte and a printed graphic
character. This translation is implemented in the hardware of peripheral devices, such as
terminals and printers.



DATA STRUCTURE OPERATIONS
The data appearing in our data structures are processed by means of certain operations. In
fact, the particular data structure that one chooses for a given situation depends largely on
the frequency with which specific operations are performed. The following four
operations play a major role in this text:
Traversing: Accessing each record' exactly once so that certain items in the
record may be processed. (This accessing and processing is sometimes called
"visiting" the record.)
Searching: Finding the location of ihe record with a given key value, or finding
the locations of all records which satisfy one or more conditions.
Inserting: Adding a new record to the structure.
Deleting: Removing a record from the structure.
Sometimes two or more of the operations may be used in a given situation; e.g., we may
want to delete the record with a given key, which may mean we first need to search for
the location of the record. The following two operations, which are used in special
situations, will also be considered:
(1) Sorting: Arranging the records in some logical order (e.g., alphabetically
according to some NAME key, or in numerical order according to some
NUMBER key, such as social security number or account number)
(2) Merging: Combining the records in two different sorted files into a single
sorted file Otheroperaticrts, e.g., copying and concatenation, will be discussed
later in the text.


Data structures are classified as either linear or nonlinear. A data structure is said to be
linear if its elements form a sequence or, in other words, a linear list. There are two basic
ways of representing such linear structures in memory. One way is to have the linear
relationship between the elements represented by means of sequential memory locations.
These linear structures are called arrays. The other way is to have linear relationship
between the elements represented by means of pointers or links. These linear structures
are called linked lists: Nonlinear structures such as trees and graphs are treated in later
chapters.
The operations one normally performs on any linear structure., whether it be an array or a
liked list include the following:
(a) Traversal: Processing each element in the list.
(b) Search: Finding the location of the element with a given value or the record with a
given key
(c) Insertion: Adding a new element to the list.
(d) Deletion: Removing an element from the list.
(e) Sorting: Arranging the elements in some type of order.
(f) Merging: Combining two lists into a single list.

LINEAR ARRAYS
A linear array is a list of a finite number n of homogenous data elements (i.e., data
elements of the same type) such that:
(a) The elements of the array are referenced respectively by an index set consisting of n
consecutive numbers.
(b) The elements of the array are stored respectively in successive memory locations.
REPRESENTATION OF LINEAR ARRAYS IN
MEMORY
Let LA be a linear array in the memory of the computer. Recall that the memory of the
computer is simply a sequence of addressed locations as pictured in Figure below. Let us
use the notation
LOC(LA[K]) = address of the element LA[K] of the array LA
As previously noted, the elements of LA are stored in successive memory cells.
Accordingly, the computer does not need to keep track of the address of every element of
LA, but needs to keep track only of the address of the first element of LA, denoted by
Base( LA)
and called the base address of LA. Using this address Base(LA), the computer calculates
the address of any element of LA by the following formula:
LOC(LA[K]) = Base(LA) + w(K lower bound)
where w is the number of words per memory cell for the array LA. Observe that the time
to calculate LOC(LA[K]) is essentially the same for any value of K. Furthermore, given
any subscript K, one can locate and access the content of LA[K] without scanning any
other element of LA.






Traverse, Insert, Delete in a linear array:




Record
Just as an array is a sequence of elements all having the same type and size, a record or
structure is a sequence of elements having diverse types and sizes. The elements of a
record are called fields. For example, a record representing an entry in a phone directory
might contain fields for the name, address, and phone number of a listing, as shown in
Figure below. As in the Figure it is customary to draw records as rectangles with labeled
subrectangles for the fields. The differing sizes of the rectangles typically reflect the
different space requirements of the fields. The most frequently applied operation on
records is that of field selection. This operation accesses a specified field of a record in
order to find the field's value or to assign it a new value.


Linked list
the data elements of an array is reflected by the physical relationship of the data in
memory, not by any information contained in the data elements themselves. This makes it
easy to compute the address of an element in an array. On the other hand, arrays have
certain disadvantagese.g., it is relatively expensive to insert and delete elements in an
array. Also, since an array usually occupies a block of memory space, one cannot simply
double or triple the size of an array when additional space is required.
The inefficiency of inserting and deleting elements from a list that
is sequentially allocated in an array occurs because the order of the
list of elements is recorded implicitly. Adjacent records of the list
must be in adjacent memory locations, so a number of records may
have to be moved for an insertion or deletion. This movement can
be avoided if the order of the elements is recorded explicitly
instead of implicitly. In linked list order of elements is recorded
explicitly.
In linked list each element in the list contains a field, called a link or pointer, which
contains the address of the next element in the list. Thus successive elements in the list
need not occupy adjacent space in memory. This will make it easier to insert and delete
an elements in the list. Accordingly, if one were mainly interested in searching through
data for inserting and deleting, as in word processing, one would not store the data in an
array but rather in linked list.

The ease of insertion and deletion in linked lists is not without its disadvantages. Array
allows us to have immediate and direct access to any element of the list. In a linked list
access to list elements other than the first is indirect and inefficient. For instance, given
the length of a list, it is easy to find the middle element if the list is sequentially allocated
(Array) but relatively difficult if the list is linked. Furthermore, a price is paid in terms of
storage for the LINK fields.
Choosing between sequential and linked allocation for a particular application, we must
examine the types of operations that will be performed on the list and their relative
frequencies in order to make an intelligent decision. If the operations are largely
accessing random elements, searching for specific elements and sorting elements into
order, then sequential allocation (Array) is usually better. On the other hand, linked
allocation is preferable if the operations are largely inserting and/or deleting elements
and/or splitting lists.

A linked list. or one-way list, is a linear collection of data elements, called nodes, where
the linear order is given by means of pointer. That is each node is divided into two parts:
the first part contains address of the next node in the list. Figure below is a schematic
diagram of a linked list with 6 nodes, Each node is pictured with two parts. The left part
represents the information part of the node, which may contain an entire record of data
items (e.g., NAME, ADDRESS...). The right part represents the next pointer field of the
node, and there is an arrow drawn from it to the next node in the list. This follows the
usual practice of drawing an arrow from a field to a node when the address of the node
appears in the given field. The pointer of the last node contains a special value, called the
null pointer, which is any invalid values.

S-ar putea să vă placă și