Data Structure Lab Manual
Data Structure Lab Manual
Data Structure Lab Manual
EXPERIMENT NO:-1
THEORY :- Searching is the process of finding the desired record in a search table
. The search may be internal or external. The linear search technique is the
simplest of all the techniques that searches through the entire table.
clrscr();
printf("/n how many elements 0");
scanf("%d",& n");
printf("enter the number/n");
for(i=0,il=n-1,i++);
{
scanf("%d",& a[i];
}pritf("enter the number to be search/n");
scanf("%d",& item);
for(i=0; i<=n-1; i++)
{
if(item==a[i]
OUTPUT:dneirf
THEORY :-A structure is usually used to store dissimilar data together. Structure
elements can be accessed through a structure variable using a dot(.) operator. It is
possible to create an array of structures.
FLOW CHART (IF REQUIRED) :- Not Required
PROGRAM:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
int i,j;
struct student
{
int roll no;
char sex;
float height, weight;
};
struct student data[3]={
{121 ; m :5.5: 52};
{122 ; f; 5.3: 54 }
{123;m; 5.2: 42}
};
printf("the intialized content are\n");
for(i=0;i<=n;i++)
{
printf("\n**record no %d**\n",i+1);
printf("%d\n",data[j].roll no);
printf("%e\n",data[i].sex);
printf("%s\n",data[i]height);
printf("%s\n",data[j]weight);
}
getch();
}
OUTPUT: 121, m ,5.5, 52
122,f,5.3,54
123,m, 5.2,42
OBSERVATIONS: Program has been run successfully.
THEORY :-PUSH- The process of adding a new element to the top stack is
called PUSH operation. Pushing an element in the stack in the stack invoke
adding of element , as the new element will be insertion at the top after every
push operation the top is incremented by one. In case the array is full and no
new element can be accommodated, it is called STACH-FULL condition.
POP- The process of deletion an element from the top of stack is called POP
operation .After every pop operation the stack is decrement by one . IT there is
no element on the stack and the pop is performed then this will result into
STACK UNDERFLOW CONDITION condition.
PROGRAM :-
#include<stdio.h>
#include<conio.h>
#include<---->
#define maxsize=10
void push();
intpop();
void---
int stack[maxsize];
inttop=-1;
void main()
{
int choice;
char ch;
do
{
clrscr();
printf("\n1.push");
printf("\n2.pop");
printf("\n3.traverle");
printf("\n.enter yourchoice");
scanf("%d",&choice);
switch(choice);
{
case1:push();
break();
case p
rintf("\n the delete element");
break();case3:travers();
break();
OBJECTIVE :- One program based on - In fix to post fix or infix to prefix using
stack Concept - Recursion using stack.
HARDWARE & SYSTEM SOFTWARE REQUIRED :- Not Required
SOFTWARE REQUIRED :- TURBO C++
THEORY :- INFIX – The infix is what we come across in our general mathematics
,where the operator is written in between the operands.
Prefix-The prefix notation in which the operator is written before the operand, it is
also called polish notation.
Postfix –in the notation the operator are written after the operands ,so it is called
the postfix notation.
FLOW CHART (IF REQUIRED) :- Not Required
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
char stack[50];
int top=-1;
void in_to_post(char infix[ ]);
void push(char);
char pop();
void main ()
{
char infix [25];
printf(“enter the infix expression”);
gets(infix);
in_to_post(infix);
getch();
}
void push (char symb)
{
if(top>=49)
{
printf(“stack overflow”);
getch();
return;
}
else
{
top=top+1;
stack [top]=symb;
}
}
char pop ()
{
char item;
if(top==-1)
{
printf(“stack empty”);
#include<stdio.h>
#include<conio.h>
int queue[5];
long front,rear;
void main()
{
int choice, infor;
clrscr();
initqueue(); //initilizing queue
while(1)
{
clrscr();
printf("menu \n"); //displaying menu
printf("1. insertion element in queue\n");
printf("2. delete an element from queue\n");
printf("3.display the queue\n");
printf("4.exit!\n");
printf("your choice");
scanf("%i",& choice);
switch(choice);
{
case1:if(rear<4)
{
printf("enter the number");
scanf("%d",&infor);
if(front==-1)
{
front=0;
rear=0;
}
else
rear=rear=1;
queue[rear]=infor;
}
else
printf("queue is full");
getch();
break;
THEORY :- Linked lists are special list of some data elements linked to one
another. The logical ordering is represented by having each elements pointing to
the next element .Each element is called a node which has two parts. INFO part
which stores the information and the pointer which points to the next
element.linked list are of four types;
1. Singly linked list
2. Doubly linked list
3. Circular linked list
4. Doubly circular linked list
Applications: Linked list are widely used to represent and manipulate polynomials.
Polynomials are the expressions containing numbers of terms with non zero
coefficients and exponents.
THEORY :- Pointers are the variables that store the memory addresses. A pointer
enables us to access a variable that is defined outside the function. It reduces the
length and complexity of a program. The use of a pointer array to character strings
results in saving of data storage space in memory.Pointers can be declare as: data
type *pt_name.
The * tells that the variable pt_name is a pointer variable.
pt_name needs a memory allocation.
pt_name points to a variable of type data type.
FLOW CHART (IF REQUIRED) :- Not required
OUTPUT
Address of a=4020
address of b= 4016
a=12, b= 4
x=42, y=9
a=2; b=7, z=8
s
THEORY :- Three representations are commonly used for graphs. These are
adjacent matrix, adjacency list representation and multi-list representation.
Minimum spanning tree are trees are free trees designed only on undirected
graphs. Binary trees can be represented either using array representation or using
a linked list representation.. The node consists of three fields such as:
data field: holds the value to be given.
Left child: is a link field which contains the address of its left node
Right child: contains the address of the right node.
FLOW CHART (IF REQUIRED) :- Not required.
1. Set k=1
2. For k=1 to (n-1)
Set temp = a[k]
Set j=k-1
While temp< a[j] and (j>=0) perform the following steps.
Set a[j+1]= a[j]
[ end of loop structure]
Assign the value of temp to a[j+1]
[end of for loop structure]
3. Exit.
THEORY :- A binary tree is a finite set of data items which is either empty or
consists of a single item called the root and two disjoint binary trees called the left
sub tree. In a binary tree the maximum degree of any node is atmost two
.Algorithm:
1. Set beg =lb, end= ub and mid= int ((beg+ end))/2
2. Repeat steps 3 and 4 while beg<= end and a [mid] != item
3. if item < a[mid], then
set end = mid-1
else
set beg=mid+1
4. set mid= int((beg+ end))/2
5. if a[mid] = item then
set loc=mid
else
set loc= null
6 exit
THEORY :- A graph data structure consists of a finite (and possibly mutable) set of
ordered pairs, called edges or arcs, of certain entities called nodes or vertices. As in
mathematics, an edge (x,y) is said to point or go from x to y. The nodes may be part of
the graph structure, or may be external entities represented by integer indices. Graph
traversal means visiting all the nodes of the graph. There are two methods of graph
traversal:
1. BSF (breadth first traversal): one node is selected as the start position. It is
visited and marked , then all unvisited node adjacent to the next node are visited
and marked in some sequential order. BSF proceeds level by level.
2. DFS(Depth first traversal): DFS follows first a path from the starting node to an
ending node, then another path from the start to the end and so forth until all
nodes have been visited.
Analysis of DFS
Setting/getting a vertex/edge label takes O(1) time
Each vertex is labeled twice
once as UNEXPLORED
once as VISITED
Each edge is labeled twice
once as UNEXPLORED
once as DISCOVERY or BACK
Method incident Edges is called once for each vertex
DFS runs in O(n + m) time provided the graph is
represented by the adjacency list structure Σv deg(v) = 2m
FLOW CHART (IF REQUIRED) :- Not required.