Need of data structure
As application are getting complex and amount of data is increasing
day by day , they may arise the following problem.
Processor speed: to handle very large amount of data processor may
fail to deal with huge amount of data.
Data search : if we have 120 items in our store , if our application
need to search for a particular item , it need to traverse 120 items
every time.
Multiple request: if a thousand of users are searching the data
simultaneously on a web server , than there are the chance that a
very large server can be failed during that process.
To solve the above problems , data structure are used.
Advantage of data structure
Efficiency: efficiency of a program are depends upon the choice of
data structure.
Data structures allow us to organize and store data, while
algorithms allow us to process that data in a meaningful way.
Learning data structure and algorithms will help you become a
better programmer. You will be able to write code that is more
efficient and more reliable.
Data structure classification
Data structure can be classified into two categories :
1-primitive data structure : these are basic structure and are directly
operated by machine instruction.
Primitive data structure is predefined data structure. Like Int , Boolean,
float..
Integer is used to store numeric data (1-2-3-4-5)
Float is used to store decimal numbers (1.5 – 2.5 – 3.5)
Char is used to store the alphabets (a,b,c,d)
Non-primitive data structure
Non-primitive data structure is a collection of primitive data structure,
if the primitive data structures collected together it is called non-
primitive data structure. For example if some integers collected
together or char and int collected together or char and char collected
together it is called non-primitive data structure.
Non-Primitive data structure are derived from the primitive data
structure, or it is a collection of same type or different type of
primitive data structure.
and it is divided into two types.
1. Linear data structure
2. Non-linear data structure
Linear data structure:
a data structure is called linear if all of its elements are arranged in linear
order.
Linear data structure is which the data is stored in sequential order is
called linear data structure.
Example of linear data structure are as follow:
1. Array
2. Stack
3. Link list
4. Queue
Array data structure:
Array is from linear data structure types, an Array can be defined as an
infinite collection of homogeneous (similar type) elements.
array is a collection of similar types of data items and each data items is
called as element of the array.
Array can be store multiple value which can be referenced by a single name.
The elements of array share the same variable name but each one carries a
different index number known as subscript.
The array can be one dimensional, two dimensional or multidimensional.
One or single dimensional Array
Single Dimensional Arrays:- It is use only one Subscript { } to define
the element of array.
Single Dimensional array as a row where elements are stored one
after another.
Syntax is = Data type array name {size}
Example int a {5}
Multi-Dimensional Arrays
multi-Dimensional Array: it is an array that has more than one
Dimensional. It is an array of arrays.
Example
Data type array name {size}
a {3} {2}
Stack data structure:
Stack : it is a linear list in which insertion and deletion are allowed
only at one end called top.
A stack is an abstract data type (ADT), can be implemented in most of
the programming languages. It is named as stack because it behaves
like a real-world stack, for example: - piles of plates.
Example:- first in last out.
Linked List data structure:
Linked List: Linked list is a linear data structure which is used to
maintain a list in the memory. It can be seen as the collection of
nodes stored at non-contiguous memory locations. Each node of the
list contains a pointer to its adjacent node.
Each element is called a node which has two parts Info part which
stores the information and pointer which point to the next elements.
Queue data structure:
Queue: Queue is a linear list in which elements can be inserted only
at one end called rear and deleted only at the other end called front.
It is an abstract data structure, similar to stack. Queue is opened at
both end therefore it follows First-In-First-Out (FIFO) methodology for
storing the data items.
Int arr[6]
Linked list
array
Stack
Non-linear data structure
Non-linear data structure not store data in sequential order.
this data structure does not form a sequence , each items is
connected with one or more other items in a non-linear arrangement.
Ex:
Tree:
Graphs:
Trees data structure:
Trees are multilevel data structures with a hierarchical relationship
among its elements known as nodes. The bottommost nodes in the
hierarchy are called leaf node while the topmost node is called root
node. Each node contains pointers to point adjacent nodes.
Graphs data structure:
A Graph data structure is a non-linear kind of data structure made up
of nodes or vertices and edges. The edges connect any two nodes in
the graph, and the nodes are also known as vertices.