Data Structure
Data Structure
hen an
ment is inserted into a stack or
e l e m e n t
ent is done at the very first location of the queue, if Types of Linked List
last location of the queue is full. Basically, uwe can put linked lists into the followving four ype
Q[O] Q[1] 1. Singly linked list is one in which all nodes are
linked together in sbme sequential manner.
Hence, it is also called linear linked list.
Q 4] Clearly, it has the beginning and the end. The
problem with this list is that we cannot acces the
Q [3] predecessor of node from the current node. This
Circular queue can be overcome in
doubly linked lists.
ouble Ended Queue Start
also a elements in which
ior andnomogeneous list of performed from
Rerton -10 -20
Olh the e deletion operationsdouble-ended queue.
are
Start subtrees.
node 1 node 2 node 3 node 4 Strictly Binary Tree
10 20 0 40 G
Ifevery non-leaf node in a binary tree has non-emt
Circular linked list left and right subtrees, the tree is termed as stricti
binary tree.
4. Circular doubly linked list is one which has Total number of nodes in a strictly binary tree =(2n-1
both the successor pointer and perdecessor
pointer in circular manner. It is shown in figure. where, n is number of leafs.
nodes.
n a t aS t r u c t u r e
ure
means
traversal in many
non-linear data structure. A
mathematica A graph be needed
traversal may m e t h o d s for
a
is
is of vertices Vand a set of edges E.
set graph. Graph there may be many
G(V E) a pair of vertices and
Gaph
a
areas and
gaph
A ne d g e c o n n e c t s .
may have weight application
vertices of the graph.
gth, cost or another measuring instrument for visiting the
traversal methods
th graph. Vertices
on the
graph are shown as There are two graph
breadth first
traversal
ecording
are drawn line In
or
circles and edges as arcs or
B r e a d t h First
Traversal
a s the
start position.
point
Thus, an edge can be representing as node is selected unvisited nodes
ment. of a graph, one
then all
where, V and W are pair of vertices. The and marked, in
7, W) It is visited
node a r e visited
and marked
a n d W lie on E. Vertices may be considered as adjacent to the
next
the unvisited
nodes
arcs, ine segment as roads. order. Finally,
vertces
and
and edges, s o m e sequential a r e visited
to these nodes
idesa
are classified in thefollowing categories, immediately adjacent until the entire graph has
Thegraphs marked and s o forth, known a s Breadth
First
Directed Graph (ii) Non-directed Graph been traversed. It is also
and merging a r e
three related
which does not sorting
2. Undirected edge Any edge Searching,
make the job of
retrieval of data from
any direction specified. operations which and efficient.
the storage devices, easier, speedier
Vertices
two nodes joined by an edge are
called vertices.
Sorting of an Array of arranging the
Any of array is the technique
an
Sorting either in
Null Graph null array
elements in a specified order i.e.,
node is called
as
order.
which has no edge or
ascending or descending
Any graph
graph. Bubble Sorting
element is compared with
its
Digraph then it is
called as In bubble sort, each
first element is larger than the
the edges are
directed
adjacent element. If the
gTaph, all second one, then the position
of the elements are
diagraph. interchanged, otherwise it is
not changed. Then, next
element and the
Mixed Graph element is compared with its adjacent
some are
undirected,
same process is repeated
for all the elements in the array.
directed and
S o m e edges are
The s a m e process is repeated until
no m o r e elements are
then called mixed graph. left for comparison. Finally, the array is sorted
one.
Multigraph parallel
then it is
called as
Selection Sorting
fina agraph two edges are
The selection sort technique is based upon the extension
multigraph. of the minimum/maximum technique. By of a
nest of for loops, a pass through the array is made to
means
Loop at the
same
vertex is
locate the minimum value.
Any edge which starts
and ends
called loop.
Caller
74
Computer Awarenec
Once this found, it is placed in the first position of the largest key in the heap. This type of heap is uho
array (position 0). Another, the remaining elements is called descending heap or max heap, as the path fr
made to find the next smallest
element, which is placed the root node to a terminal node forms an ordered li
st of
in the second
position (position 1) and so on elements arranged in descending order.
Insertion Sort The follorwing fgure shows an example of max-ten
An insertion sort is 'one that sorts representation heap
a set of values by
inserting values into an existing sorted file. Suppose an
array a with n elements all, al2,. an is in memory.
The insertion sort algorithm scans a from all to aln,
inserting each element a[k| into its proper position in the
previously sorted sub array al, al2 ak-1
Quick Sort 50)
2 38 (48)
The quick sort algorithm works by partitioning the array
to be sorted and each partition is in turn sorted 65 43 54 26 3848 50
recursively. In partition, one of the array elements is Max-heap
chosen as a key value. This key value can be the first
element of an array. i.e., if a is an array then
key =a0 Searching of Array Element
and rest of the array elements are grouped into two
Searching is used to find the location where, element is
partitions. available or not.
Figure shows a key and partitions of element in an array
There are two types ofsearching techniques as given beloo
1. Linear sequential searching
2. Binary searching
Partition 1 Partition 2
Linear or Sequential Searching
In linear search, we access each element of an
array one
Value> key key Value > key by one sequentially and see whether it is desired element
or not. A search will be unsuccessful, if all the elements
One partition contains elements smaller than the key are accessed and the desired element is not found.
value.
Another partition contains elements larger than the Binary Searching
key value. Binary searching is an extremely efficient algorithm.
This search technique searches the given item in
Radix Sort
minimum possible comparisons. To do the
Bucket sort or radix sort is a method can be used to sort
binary
search, first we had to sort the array elements.
a list of names alphabetically, here the base or radix is Searched in 1st half Searched in 2nd
26, (the 26 letters of the alphabetic). of array Mid value half of array
Merge Sort
First value First +Last)/2 Last value
Merge sort is a sorting technique which divides the array
into sub-arrays of size 2 and merge adjacent pairs. We Binary search sketch diagram for middle value
then have approximately n/2
arrays of size 2. This The
process is repeated until there is only one array logic behind this technique is given below
remaining of size n. 1. First find the middle element of the array.
Heap Sort 2. Compare the mid element with an item.
A heap is defined as an almost 3. There are three cases which arises
complete binary tree of n
nodes such that the value of each node is less than or (a Ifit is a desired element then search is successtul.
equal to the value of the father. This implies that the root (b) If it is less than desired item then search ony
of the binary tree (i.e., the first
array element) has the the first half of the array, by
using the same step
75
ngta
Structure
ure
LET US Practice
data structure is linear data
6. Which of the following
c a n easily be converted into a 2-tree
1. A binary tree structure?
subtree a new internal node
by (b) Graphs
(a) by replacing each empty (a) Trees
None of these
an internal nodes for non-empty node (d)
(b) by inserting node
(c) Arrays
external nodes for non-empty to evaluate a postfix
(c) by inserting an subtree by a new external 7. The data structure required
(d) by replacing each empty expression is
(d) linked list
node
(a) queue
(b) stack (c) array
of
determining the efficiency of a n algorithm is
2. The time factor when of the average case
algorithm is measured by
8. The complexity than that of worst
much more complicated to analyse
(a)
(a) counting microseconds case
that of worst c a s e
(b) counting the number of key
operations
(b) much more simpler to analyse than
and s o m e other times
of statements more complicated
(C) cOunting the number (c) sometimes
(a) counting the kilobytes of algorithm simpler than that of worst case
condition
3. Which of the following is
not the required (d) None of the above
limitation of binary
for binary search algorithmn? 9. Which of the following is not
a
Answers
1. (d) . (b). 3. (c)
11 (a)
4. (6) 5. (c) 6 (c) 7. (b) 8.(a) 9. (a) 10. (C
12. (a) 13. (d) 14. (a) 15. (b) 16. (c) 17. (d) 18. (a) 19. (6) 20 ()
21. (b) 22. (a) 23. (c) 24. (d) 25. (a) 26. (d) 27. (c) 28. (b)