Department of computer Science & Engineering
KCC INSTITUTE OF TECHNOLOGY & MANAGEMENT
2B-2C, Knowledge Park-III, Greater Noida, Uttar Pradesh
BCS351-DATA STRUCTURE LAB
LAB FILE
(2025-26)
THIRD SEMESTER
SUBMITTED TO: SUBMITTED BY:
Mr. Chand Babu Om Yadav
(Assistant Professor) [Link]-CSE(AI) (3rd Sem)
Department of CSE Roll No.: 2404921520140
Section: B7
Index
Page
Sr. No. Name of the experiment Date
No.
1. 1-4
Implementing Sorting Techniques
2. 5-6
Implementing Searching and Hashing Techniques
3. 7-9
Implementing Stacks
4. 10-12
Implementing Queue
5. 13-16
Implementing Linked List
6.
Implementing Trees
7.
Implementing Graphs
Experiment-1
< Implementing Sorting Techniques >
(i)To implement Bubble Sort to sort a given list of numbers in
ascending order.
Theory:
Bubble sort is a simple comparison–based sorting algorithm. It repeatedly
compares adjacent elements of the array and swaps them if they are in the wrong
order. In each pass, the largest element “bubbles up” to its correct position at the
end of the array. Time complexity in worst and average case is O(n²).
Algorithm:
● Start
● Read n, the number of elements.
● Read n elements into array a[ ].
● Repeat steps 5–7 for i = 0 to n-2
● Repeat for j = 0 to n-2-i
● If `a[j] > a[j+1]` then swap `a[j]` and `a[j+1]`.
●
● End inner loop
● End outer loop
● Display the sorted array.
● Stop
PROGRAM CODE(C) :
#include
<stdio.h> int
main() {
int a[50];
int n, i, j, temp;
printf("Enter number of elements: ");
scanf("%d", &n);
printf("Enter %d elements:\n", n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1 - i; j++) {
if (a[j] > a[j + 1])
{ temp = a[j];
a[j] = a[j + 1]; a[j
+ 1] = temp;
printf("Sorted array (ascending):\n");
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
Return 0;
************************Output*******************************
Result / Conclusion:
Thus the Bubble Sort algorithm was implemented in C language and the given list of numbers was
successfully sorted in ascending order.
Viva-Voce Questions:
1. Q: What is the time complexity of bubble sort?
Ans: O(n²) in worst and average case, O(n) in best case (already sorted array).
2. Q: Why is it called “Bubble” sort?
Ans: Because in each pass, the largest element moves to the end like a bubble rising to the surface.
3. Q: Is bubble sort stable?
Ans: Yes, it is a stable sorting algorithm.