Bubble Sort
Bubble Sort
Topic
BUBBLE SORT
Session - 25
INSTRUCTIONAL OBJECTIVES
1. Define Sorting and its advantages.
2. Understand the importance of sorted data over unsorted.
3. Understand the concept of sorting using the technique of Bubble
sort.
4. Illustrate the time complexity of Bubble sort.
LEARNING OUTCOMES
At the end of this session, you should be able to:
1. Illustrate the importance of sorted data.
2. Sort given array of elements using Bubble sort.
3. State the time complexity of Bubble sort.
•This algorithm is not suitable for large data sets as its average and worst-case
time complexity is quite high..
•In this way, the largest element is moved to the rightmost end at first.
•This process is then continued to find the second largest and place it in the second right
most end and so on until the data is sorted.
Second Pass:
Place the second largest element at correct position
Third Pass:
Place the remaining two elements at their correct positions.
•Bubble sort has a time complexity of O(N2) which makes it very slow for large data sets.
•Bubble sort is a comparison-based sorting algorithm, which means that it requires a comparison operator to determine
the relative order of elements in the input data set. It can limit the efficiency of the algorithm in certain cases.
Lets raise the question- what is the daily use of the algorithm discussed?—
Well the reply is straight forward and simple. We have been witnessing this from our
school days in our physical educational classes or in sports. The teacher asks to
assemble in line in front of the teacher in ascending order of heights. Now, comes the
well discussed sorting algorithm –The Bubble sort. Here in every pass the teacher
arranges the students slowly by comparing in pairs and interchanging them. The
process finally ends in ordered line of students in increasing order of their heights .
2. What is the status of the following array after the 4th pass [45,
56,2, 58, 14,9] ?
Reference Books: