DS Using C Material1
DS Using C Material1
Lists Files
Static structures are ones whose sizes and Dynamic structures are ones which expand
or shrink as required during.program execution
structures associated memory locations are
and their associated memory locations change.
fixed at compile time.
Example: Linked list created using pointers.
Example: Array
insertion of elements can be done only from one end, ' -=--
_..
=-
called the top ofstack (TOP). Due to this property it is
also cal led as last in first out .type of data structure
..
(LIFO). It could be thought ~fjust like a stack of plates
placed on table in a party, a guest always takes off~ Figure 1.10 Stack
fresh plate from the top, and the new plates are placed
onto the stack at the top,
When an element is inserted into a stack or removed from the stack, its base remains fixed
whereas the top of stack changes. Insertion of element into stack is called Pusli and Deletion
of element from stack is cal led Pop. The figure I; 10 shows how the operations take place on
a stack.
Queues are first in first out type of data structure (i.e. FIFO). In a queue, new elements are
added to the queue from one end called rear end, and the elements are always removed
from other end called the front end. The people standing in a railway reservation row are an
example of queue. Each new person comes and stands at the end of row (rear end of
queue), and persons getting their reservations confirmed, get out from the front erid. The
representation of queue is shown in Figure 1.11.
12 C ~~------------
.:·::o~•~D~a~ta~S~tr~uc~tu~r,::es~U~s~in~g~----=---
Queues can also be implemented in two ways:
i) Using arrays.
ii) Using pointer.
7 16
72 85
50 65 rear
front
Figure 1.11 Queue
1.5.6. Graph
Graph is a mathematical non-linear data structure capable of representing many kinds of
physical structures. It has found applications in diverse field like Geography, Chemistry and
Engineering Sciences.
Defining Graph
A graph G( V, E) is a set of vertices v and a set of edges e. An edge connects a pair of
vertices and many have weight such as length, cost or ~nother measurin.g instruments for
recording the graph Verti lntroduc:1/on lo Algorithrm • 1.2 I
· ces on the Ourapt1
drawn as arcs or line scomc 11 t Tl ate s11own as point or circles and edges are
· His on edg
0
for pro.cessing.
• string con~atenation
• string length
· • string compare
. . -
The basic idea is that the implementation of these operations is written once in the program,
and any other part of the program that needs to perform an operation on the ADT can do so
by_calling the appropriate· function. If for some reason ·implementation details need to be
changed, it should be easy to do so by merely changing the routines that perfo,rm the ADT
9peration. This change would be completely transparent to the rest of the program.
. .
There is no rule telling us which operations must be supported for eac~ ADT; this is a design
decision. Some data structures that we will study in this book are primarily examples of
ADT. We will see how each can be implemented, but if they are done correctly, the programs
that use them will not need to know which implementation was used.