Posts

Showing posts with the label Data structure in C

Bubble sort

Image
Sorting Sorting is a process in which we arrange the data of  any list in any particular order  such as ascending order and descending order.

Searching

Image
Searching Searching is a operation in which any particular data is search in the list.The search is said to be successful or unsuccessful depending on whether searching is found or not. there are two  method to search element- linear search and Binary search. Linear search This is simple method of searching. In this method,the element is searched in sequence order as one by one.This method can applied on sorted or an unsorted list 10 30 50 60 20 40 80 70 100 90 The array shown in figure consist 10 number.Suppose  the element 60 is searched, so 60 is compared with starting with 0th position and searching process is ends either when 60 is found or the list ends. The number of comparisons in linear searching is 0(n). void linear_searching( int a[], int size,int svalue) {     int i, flag=0;     for(i=0;i<size;i++)     {         if(a[i]==svalue) ...

Level of tree, General tree and Binary tee

Image
Level of tree The level of tree is representes level of tree which must be started with zero. The level nuber of root node is zero. Height of tree The height of tree is equivalent to the maximum number of level+1. The height of tree=Level of tree+1 The  height of above tree is=3+1=4 General tree In this tree any node can have more than two child. Binary tree In binary tree each node can have maximum two children .In other words in case of binary tree any node consist of zero ,one or two children. Property of binary tree In binary tree each nod can have maximum two children. In binary tree total edges equivalent of number of (node-1).    Total edges= Number of node-1   Total edges=8-1=7     (see above figure binary tree)   In this tree maximum number of node are 2 h -1     where h= height of tree                Height of tree=level+1 ...

What is tree?

Image
Tree It is a non linear data structure which ids used  to represent data in hierarchy format. Its main objective to implement hierarchy database in DBMS.In other word tree can be define as-                          It is a collection of vertices and edges. It is similar to graph but tree does not contain any cycle so we can say that all tree are graph but all graph are not tree. A tree is said to be a non cyclic graph because it does not contain any cycle. Tree Terminolgy Node:- An element of tree is called node.It is also called vertex. Parent node:- Those node that have child node called  child node. Child node:- Those node that have parent  node called child node. Leaf node:- Those node that have no any child node called leaf node.It is also  know as terminal node. Left subtree:- The entired node at left side area called left subtree. Right subtree:- The entire...

Circular Queue

Image
Circular queue We know that  major drow back of linear queue is that we can not insert on the deleted position but in case of circular queue new element can be inserted on the deleted position in this case rear goes back to zero if rear is equivalent to size-1 . circular queue implementation through program. #include<stdio.h> #include<conio.h> #include<process.h> #include<stdlib.h> void cqinsert(); void cqdisplay(); void cqdelet(); int cqueue[50],front=-1,rear=-1,size;  int main()  {      int choice;      printf("enter the size of queue");          scanf("%d",&size);      do      {          system("cls");          printf("====SELECT YOUR CHOICE=====\n press 1 for insertinon-\n press 2 for display the element-\n press 3 for delete-----\n  enter choice=");       ...

linear queue using linked list

Image
linear queue using linked list linear queue using linked list linear queue using linked list linear queue using linked list linear queue using linked list linear queue using linked list  In this representation we  can store unlimited  values in queue because linked list support dynamic memory allocation.In this case the concept of overflow will not be accrued. In underflow condition front and rear will be NULL. Implementation Queue using linked list #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<process.h> struct node {     int info;     struct node *link; }; struct node *front=NULL,*rear=NULL; void insertion(); void deletion(); void display();  int main()  {      int choice;      do      {          system("cls");          printf("====SEL...

linear queue using array

Image
linear queue using array linear queue using array linear queue using array linear queue using array linear queue using array linear queue using array linear queue using array linear queue using array linear queue using array In this representation we take one variable array type to contain elements of queue,other side we use to variable as name FRONT and REAR which represent index value of array. A queue is called underflow if both FRONT and REAR must be assigned with -1. It is called overflow if rare is equivalent to(size-1) Implementation Queue using Array #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<process.h> int queue[50],size,front=-1,rear=-1; void insertion();//function prototype void deletion(); void show();  main() {     int choice;     printf("enter the sixe of queue-");     scanf("%d",&size);     prin...

what is queue

Image
what is queue? It is a linear data structure which works in FIFO order. in this queue insertion and deletion are perform from both direction end. One is called FRONT and second is called REAR. Insertion and Deletion operation are performed from REAR and FRONT respectively. Its main objective to implement CPU scheduling algorithm in operating system. eg:- ticket booking at cinema hall etc. Types of Queue. 1. linear queue 2.circular queue. 3 priority queue. 4. Deque/Dequeue  linear queue. In this queue we can not insert/ store new element on deleted  position, so in this case memory is westage but it can be avoided with the help of circular queue. circular queue. We know that major  drawback of linear queue is that we can not insert element on deleted position but in case of circular queue new element can be inserted on the deleted position. In this case rear goes back zero if rear is equivalent to size-1. Priority queue ...

Stack

Image
  What is Stack? Stack is a linear data structure which ids used to store in LIFO order (LAST IN FIRST OUT) In this data structure insertion and deletion are performed only one position called TOP. its main objective to evaluate mathematical expression in different notation as prefix, postfix and infix. These are called polish notation. It is a big application of stack .It is also used in different algorithm as Tower of Hanoi, traversal of tree and recursive algorithm. Operation on stack PUSH-operation:- to insert element in stack. POP-operation:- to delete element in stack. Overflow:- full stack. Underflow:- empty stack. Representation of stack using array. In this representation we use one array variable which hold the value of stack and other variable is top that hold the index value. If stack is full/overflow then top must be insilized with (size-1). A stack is called underflow if top is assigned with -1 . in this case we can store limited element ...