Bubble Sort
Bubble Sort
(DS ASSIGNMENT 2)
Student Details : Jainam Shah Div : c
Faculty : A/Prof. Subject Name
Silver Oak College Of Engineering and Technology,
College of Technology, SOU
Bubble sort is a simple sorting algorithm that repeatedly steps => Input Array Initialize variables: Loop until no more swaps are
through the list, compares adjacent elements, and swaps needed Compare adjacent elements and swap if necessary Repeat
them if they are in the wrong order. The pass through the list loop until end of array is reached Output sorted array
is repeated until the list is sorted.
Experiment:
GOALS & OBJECTIVES We tested the Bubble Sort algorithm on a dataset of 10,000
Goals: random integers, measuring execution time and number of
•Goal 1: To sort a list of elements in a specific order (either swaps required.
ascending or descending). Results:
•Goal 2: To minimize the number of swaps required to sort the •Execution Time: 10.23 seconds
list. •Number of Swaps: 49,856
•Comparison: Bubble Sort was slower than Selection Sort
Objectives: and Insertion Sort for large datasets.
•Objective 1: To compare adjacent elements in the list and IMPLEMENTATION
swap them if they are in the wrong order, thereby reducing the
void bubbleSort(int arr[], int n) {
number of inversions inTECHNIQUES
the list. USED
for (int i = 0; i < n-1; i++) {
bool swapped = false;
The technique used in bubble sort is called the Exchange for (int j = 0; j < n-i-1; j++) {
Sort or Comparison-Based Sort. This technique involves if (arr[j] > arr[j+1]) {
repeatedly iterating through the list, comparing adjacent int temp = arr[j];
elements, and swapping them if they are in the wrong order. arr[j] = arr[j+1];
arr[j+1] = temp;
ALGORITHM USED
swapped = true;
The algorithm used in bubble sort is as follows: } }
Step 1: Initialize If (!swapped) {
Step 2: Iterate Through the List break; } } }
Step 3: Repeat Until Sorted
FUTURE SCOPE
Image of website Future Scope of Bubble Sort:
•Education: Pedagogical tool for introductory programming courses
•Small Datasets: Suitable for limited memory and processing power
•Hybrid Approaches: Combining with other algorithms for improved
performance
•Parallelization: Taking advantage of multi-core processors or
distributed computing
•Optimization Techniques: Adaptive bubble sort for dynamic iteration
count adjustment
•Real-time Systems: Predictability and simplicity are prioritized
•Embedded Systems: LimitedCONCLUSION
resources require simplicity and low
overhead
In conclusion, Bubble Sort is a simple and intuitive sorting algorithm that,
despite its limitations, has its niche applications and areas for improvement.
While it may not be the most efficient sorting algorithm, its ease of
implementation and simplicity make it a valuable tool in certain contexts. By
understanding the strengths and weaknesses of Bubble Sort, we can effectively
utilize it in education, small datasets, hybrid approaches, parallelization,
optimization techniques, real-time systems, and embedded systems. As we
continue to develop and refine sorting algorithms, Bubble Sort remains a
fundamental concept in computer science, offering a foundation for more
advanced and efficient sorting techniques.
REFERENCES
• GeeksforGeeks. : Bubble Sort.
from https://www.geeksforgeeks.org/bubble-sort/
• Wikipedia : Bubble sort.
from https://en.wikipedia.org/wiki/Bubble_sort