Data Structure File
Data Structure File
Data Structure File
FILE
Name : Harsh
Enrollment no. : A50105221095
Course : B.Tech(CSE)
Batch : 2021 – 2025
Submitted to : Dr.Deepthi Sehrwat
INDEX
S.No Topic Practical Date Signature
1. Traversal
2. Insertion
3. Deletion
4. Minimum
Array
5. Maximum
6. Searching
a) Linear Search
7. Searching
b) Binary Search
8. Prime Number
9. Bubble Sort
10. Insertion Sort
11. Selection Sort
Sorting
12. Algorithms Merge Sort
13. Quick Sort
14. Heap Sort
15.
Dislay
POP (Insertion)
Stack POP (Deletion)
Infix to Postfix
Dislay
Enqueue (Insertion)
Linear
Queue Dequeue (Deletion)
EXPERIMENT-1
Traversal in an Array :-
Theory :- Traversing an array means accessing each and every element of the array for a
specific purpose.
Traversing the data elements of an array A can include printing every element, counting the
total number of elements, or performing any process on these elements. Since, array is a
linear data structure (because all its elements form a sequence), traversing its elements is very
simple and straightforward.
Code :-
// WAP on traverse the array
#include <stdio.h>
void printArray(int* arr, int n)
{
int i;
printf("Array: ");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main()
{
int arr[] = { 2, -1, 5, 6, 0, -3 };
int n = sizeof(arr) / sizeof(arr[0]);
printArray(arr, n);
return 0;
}
Output :-
Best Case :-
o(n)
We are printing whole array so time complexity will be same.
Worst Case :-
o(n)
We are printing whole array so time complexity will be same.
EXPERIMENT-2
Insertion in an Array :-
Theory :- Insert operation is to insert one or more data elements into an array.
Based on the requirement, new element can be added at the beginning, end or
any given index of array.
Code :-
#include<stdio.h>
int main(){
int student[40],pos,i,size,value;
printf("enter no of elements in array of students:");
scanf("%d",&size);
printf("enter %d elements are:\n",size);
for(i=0;i<size;i++)
scanf("%d",&student[i]);
printf("enter the position where you want to insert the element:");
scanf("%d",&pos);
printf("enter the value into that poition:");
scanf("%d",&value);
for(i=size-1;i>=pos-1;i--)
student[i+1]=student[i];
student[pos-1]= value;
printf("final array after inserting the value is\n");
for(i=0;i<=size;i++)
printf("%d\n",student[i]);
return 0;
}
Output :-
Best Case :-
o(1) Best case will occur when element will be inserted at the last.
Worst Case :-
o(n) Worst case will occur when the element will be inserted at the
zeroth index.
EXPERIMENT-3
Deletion in an Array :-
Theory:- This program deletes or removes an element from an array. A user will enter the
position at which the array element deletion is required. Deleting an element does not affect
the size of the array. It also checks whether deletion is possible or not.
Code:-
#include <stdio.h>
int main()
{
int array[100], position, c, n;
printf("Resultant array:\n");
return 0;
}
Output :-
Best Case :-
o(1) Best case will occur when element will be deleted from the last
index.
Worst Case :-
o(n) Worst case will occur when the element will be deleted from the
zeroth
EXPERIMENT-4
Code:-
#include <stdio.h>
int main()
{
int array[100], minimum, size, c, location = 1;
minimum = array[0];
Best Case:-
o(n)
Worst Case:-
o(n)
EXPERIMENT-5
Code:-
#include <stdio.h>
int main() {
int n;
int arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);
return 0;
}
Output:-
Best Case:-
o(n)
Worst Case:-
o(n)