Bubble Sort in C
Bubble Sort in C
TECHNICAL REPORT
ON BUBBLE SORT FOR #CA2 EXAMINATION
Page 1 of 5
Topic: Bubble Sort
Content
Topics Page No
Introduction 3
Algorithm 3
Performance Analysis 3
Code/Function in C 4
Example 5
Conclusion 5
References 5
Introduction:
Bubble sort is a simple and popular sorting algorithm that is used to sort arrays or lists of
elements. It is a comparison-based sorting algorithm that works by repeatedly swapping
adjacent elements if they are in the wrong order. Bubble sort is easy to understand and
implement, but it could be more efficient for large data sets.
Page 2 of 5
Algorithm:
The algorithm for selection sort can be described as follows:
Step-1: Start with the first element in the array or list.
Step-2: Compare the current element with the next element.
Step-3: If the current element exceeds the next element, swap them.
Step-4: Move to the next pair of elements and repeat steps 2 and 3.
Step-5: Continue until the end of the array or list is reached.
Step-6: If any swaps were made during the previous pass, repeat step 1.
Perfomance Analysis:
Average Time Σ
𝑛
(𝑛 − 𝑘) the average of the best and
𝑘= 1
Complexity worst case
𝑛 (𝑛−1) 2
= 2
≈ O(𝑛 )
Page 3 of 5
Code / Function in C:
Page 4 of 5
Sorting a array containing element [3, 1, 5, 4, 2] using bubble sort algorithm,
Comparing
Swapping
CONCLUSION:
In conclusion, bubble sort is a simple and popular sorting algorithm that works by repeatedly
swapping adjacent elements if they are in the wrong order. While it is easy to understand and
implement, it could be more efficient for large data sets. However, it is a good choice for
small data sets or when simplicity is more important than efficiency.
REFERENCES:
1. Introduction to Algorithms, 4TH Edition, Thomas H Cormen, Charles E Lieserson,
Ronald L Rivest and Clifford Stein, MIT Press/McGraw-Hill.
2. Algorithms Design and Analysis, Udit Agarwal, Dhanpat Rai
3. Bubble Sort (With Code in Python/C++/Java/C)
4. https://github.com/driptanil/DSA-Data-Structures-Algorithms/tree/main/08-bubble-so
rt
5. Bubble Sort Algorithm - Theory + Code
Page 5 of 5