0% found this document useful (0 votes)
3 views4 pages

Data Structure Lab File

The document is a lab file for the Data Structure Lab (BCS351) at KCC Institute of Technology & Management for the academic year 2025-26. It includes various experiments related to data structures, starting with the implementation of sorting techniques, specifically Bubble Sort, along with its theory, algorithm, and program code in C. The document also contains a section for viva-voce questions related to the sorting algorithm.

Uploaded by

phoenix07112002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Data Structure Lab File

The document is a lab file for the Data Structure Lab (BCS351) at KCC Institute of Technology & Management for the academic year 2025-26. It includes various experiments related to data structures, starting with the implementation of sorting techniques, specifically Bubble Sort, along with its theory, algorithm, and program code in C. The document also contains a section for viva-voce questions related to the sorting algorithm.

Uploaded by

phoenix07112002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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.

You might also like