Data structure


 Definition:- Allocating of data elements in Computer memory and retrieving data elements from computer memory is called data structures.

  1. How many ways we can organise the data elements in Computer memory.
  2.  How many ways we can retrieve in the data elements (called retrieving )from computer memory.
  • Data Structure is a way of collection and organising data in such a way that we can perform operations on this data in an efficient way .So ,that verious operations can be performed on it easily.
→Data structure mainly classified into two types.

  •  Linear data structures 
  •  Non-linear data structures
1]Linear data structure :-

In this element formed in an organised sequence. i.e ,elements are organised in sequential order .

Ex:-Array,stock ,queue ,linked list

Arrays:-

An array is a data structure that contains a group of elements typically these elements are all of the same datatype . Such as an integer or string array are commonly used in computer programming to organise data. So, that related set of values can be easily sorted or searched. 

Types of Arrays

1.Single dimensions Array

Ex:-int num[3];

       char str[20];

2.Two dimensions Array

Ex:-int mat[2][3];

       char str[10][20];

3.Multi dimensions Array

Ex:-int marks[10][20][5];

     10->no.of section

     20->no.of Stu's in each section

      5->id|m1|m2|m3|sum|

Stack:- 

stack is a linear data structure it is a data structure which is based on array concept and it it is called FILO (first in last out) i.e  the data elements which are inserted first display last tour [OR] LIFO (last in first out )i.e the elements which inserted last display first.

 ⇒In stock insertion deletion will be healed in only one in called top of stock .

Ex:- int str[3];

push (11)

push (22)

push(33)

show ()

                    O/p

                    33

                    22

                    11

Ex:-keepting wishes,while washing time.

Queue :-

Queue is linear data structure . It is also static data structure which is based on array concept.

 Q is called FIFO( first in first out) i.e the elements which are inserted first displays first (or) LILO(last in last out )i.e the elements which are inserted last display (or) deleted at last .

  • In queue insertion, deletion will be held on both ends . 
  • Insertion held at one end called rear .
  • deletion will be held at another in end called front .
  • Example :-taking movie tickets in Q wise

Push(11)

Push(22)

Push(33)

Show():-

        O/P

         11

          22

          33

Linked list:-

It is linear Data Structure but it is a dynamic . Data Structure the i.e there is no limition of allocation data elements in a Computer memory .

In linked list data will be stored in form of node wise .

  • Each node contains two partions 
   i]Data    ii]Address of next node

  • When control reads address of next node as a 'null' it means end linked list.
Ex:-






11,22,33

Head (or) first


Head =100(Address )

Head->data=11(value)

Head->next=150(next node address)

  • To create node in linked list we using nested structure .

structu node


int data;
        structure node*next;     

     
}; 

 
Node
Data   *
 next 
Ex:-
Head
10   150 

Head=100
Head->data=10
Head->next=150
                      if(last ->next==null)
                      end list
In C++,linked list classifieds in 4type
1】single linked list
2】circule single linked list

If (last->next==head)
        100==100
end of circular single linked list
3】Double linked list


4】Circluar double linked list


Non-Linear Data Structure :-

Non-linear data structure in ds in which data items are not stared linear in the memory . So,there is no contiguous memory allocation of the data .
Ex:-Tree,Graph

Tree:-

A tree is a non linear data structure . In tree data elements will be organised in hierarchical structure .
->A tree consist on root node which may be may not, be left child node, and right child node again act'sas root node.
Allocation of data elements in tree
  15,19,7,24,11,16,12

Tree

Traversing Methods:-
1)In order
2)pre-order
3)post-order

Graph:-

Connection of two end points is called Graph.
->It is a non-linear , Dynamic data structure
->A graph a non linear Data Structure consisting of nodes and edges . There are some times also called as vertices and edges are linear or that can connect any two nodes in the graph.
 Ex:- Connected cities with roads.

Graph
   Cities->nodes or vertius

        Roads->edges 

Traversing Methods in Graph
   i). Depth-first-search
  ii). Breadth-first-search


Comments

Popular posts from this blog

History of C language

Lab programs of C

Algorithm Pseudopods Flow-chat