Lab Manual Bca 3 Sem Data Structures-I
Lab Manual Bca 3 Sem Data Structures-I
Lab Manual Bca 3 Sem Data Structures-I
Nitin Bansal
A.P.
Department of Computer Science &
Applications
Introduction
The course consists of two laboratory classes per week.
The basic thrust of the course would be to learn programming language C and implementing
data structures.
To understand how various data structures work. To understand some important applictions of
various data structures. To familiarize how certain applications can benefit from the choice of
data structures. To understand how the choice of data structures can lead to efficient
implementations of algorithms.
DATA STRUCTURE-I
BCA- 3rd SEM
LIST OF EXPERIMENTS
1. Program to insert an element in an array.
2. Program to delete an element from array.
3. Program to implement linear search.
4. Program to implement bubble sort.
5. program to implement binary search.
6. Program to implement matrix multiplication.
7. Program to implement linked list.
8. Program to implement insertion in Linked list.
9. Program to implement Deletion in Linked list.
10.
Program to implement searching in linked list.
11.
Program to implement sorting in linked list.
12.
Program to implement deletion in linked list.
13.
Program to implement stack using array with both
of its operation push and pop.
14.
Program to implement queue.
15.
Program to implement quick sort.
Data Structures
A data structure is a scheme for organizing data in the memory of a
computer. Some of the more commonly used data structures include lists,
arrays, stacks, queues, heaps, trees, and graphs.
The way in which the data is organized affects the performance of a program
for different tasks. Computer programmers decide which data structures to
use based on the nature of the data and the processes that need to be
performed on that data.
Many algorithms apply directly to a specific data structures. When working with certain data
structures you need to know how to insert new data, search for a specified item, and deleting a
specific item.
Commonly used algorithms include are useful for:
Sorting the data. There are many ways to sort data. Simple sorting, Advanced sorting
Iterating through all the items in a data structure. (Visiting each item in turn so as to
display it or perform some other action on these items) .
Array
Advantages
Quick inserts
Fast access if index known<
Disadvantages
Slow search
Slow deletes
Fixed size
Slow inserts
Ordered Array Faster search than unsorted array Slow deletes
Fixed size
Stack
Queue
Linked List
Quick inserts
Quick deletes
Slow search
Binary Tree
Quick search
Quick inserts
Quick deletes
(If the tree remains balanced)
Heap
Quick inserts
Quick deletes
Access to largest item
Graph
Efficiency of algorithms
It can be measured on two scales:
I.
II.
III.
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("elements entered are\n");
for(i=0;i<10;i++)
printf("a[%d]=%d\n",i,a[i]);
printf("enter the element to be searched\n");
scanf("%d",&j);
for(i=0;i<10;i++)
{
if(a[i]==j)
{
printf("success\nrequired data is found at position %d\n",i);
break;
}
if(i==9)
printf("failure\ndata not found\n");
}
getch();
}
OUTPUT
{WHEN DATA FOUND}
enter the elements of the array
11
22
33
44
55
66
77
88
99
56
elements entered are
a[0]=11
a[1]=22
a[2]=33
a[3]=44
a[4]=55
a[5]=66
a[6]=77
a[7]=88
a[8]=99
a[9]=56
enter the enter the element to be searched
44
success
required data is found at position 3
54
4
56
34
76
87
98
34
67
98
elements entered are
a[0]=54
a[1]=4
a[2]=56
a[3]=34
a[4]=76
a[5]=87
a[6]=98
a[7]=34
a[8]=67
a[9]=98
enter the element to be searched
44
failure
scanf("%d",&a[i]);
printf("list\n");
for(i=1;i<=n;i++)
printf("a[%d]=%d\n",i,a[i]);
printf("enter the position at which new element to be inserted\n");
scanf("%d",&k);
printf("enter the element to be inserted\n");
scanf("%d",&l);
j=n;
for(j=n;j>=k;j--)
{
a[j+1]=a[j];
}
a[k]=l;
n=n+1;
printf("new list after insertion is\n");
for(i=1;i<=n;i++)
printf("a[%d]=%d\n",i,a[i]);
getch();
}
OUTPUT
990
new list after insertion is
a[1]=11
a[2]=22
a[3]=33
a[4]=44
a[5]=990
a[6]=55
a[7]=66
a[8]=77
a[9]=88
printf("a[%d]=%d\n",i,a[i]);
printf("enter the position of the element to be deleted\n\n");
scanf("%d",&k);
for(j=k;j<=(n-1);j++)
a[j]=a[j+1];
n--;
printf("new list\n");
for(i=1;i<=n;i++)
printf("a[%d]=%d\n",i,a[i]);
getch();
}
Output:
enter the size of array
8
enter the elements of array
2
3
4
5
6
7
8
9
elements entered are
a[1]=2
a[2]=3
a[3]=4
a[4]=5
a[5]=6
a[6]=7
a[7]=8
a[8]=9
enter the position of the element to be deleted
5
new list
a[1]=2
a[2]=3
a[3]=4
a[4]=5
a[5]=7
a[6]=8
a[7]=9
{
a[ptr]=a[ptr]+a[ptr+1];
a[ptr+1]=a[ptr]-a[ptr+1];
a[ptr]=a[ptr]-a[ptr+1];
}
ptr++;
}
}
printf("new list\n");
for(i=1;i<=n;i++)
printf("%d\n",a[i]);
getch();
}
Output:
3
4
5
6
7
8
9