Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
5 views

Bubble Sorting Algorithm in Python

Uploaded by

loanaiveannafay
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Bubble Sorting Algorithm in Python

Uploaded by

loanaiveannafay
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Bubble Sorting Algorithm

in Python
Presented By:
Luib, Diomar
Macon-ay, Rheymart
Montejo, John Patrick
Scope Of Discussion:
• To define what is Bubble sort
• To explain the process of Bubble sort
• To give and explain the advantages and disadvantages of
Bubble Sort
Definition Of Bubble Sort
• Bubble sort, sometimes referred to as “sinking sort”, is a
simple sorting algorithm that repeatedly steps through the
list to be sorted, compares each pair of adjacent items
and swaps them if they are in the wrong order. The pass
through the list is repeated until no swaps are needed,
which indicates that the list is sorted.
Process Of Bubble Sort
• It is an algorithm that passes through the list that is to be
sorted, compares each pair of adjacent items and swaps
them if they are in the wrong order. The pass through the
list will be repeated until no swaps are needed and the list
is already in order.
• Bubble sort uses the Big O Notation and has worst-case
and average complexity both О(n2), where n is the
number of items being sorted.
Formulas in Bubble Sort
Big O Notation:
• Worst-case performance O(n^2)
• Best-case performance O(n)
• Average performance O(n^2)
• Worst-case
space complexity O(1) auxiliary
Recap: Big O Notation
• is used to classify the worst-case “speed” of an algorithm
by looking at the order of magnitude of execution time.

O(n)
O - represents the function
n - represents the elements
Flow Chartof Bubble Sort
Advantages and Disadvantages of
Bubble Sorting
Advantages:
• Easy to understand.
• Easy to implement.
• In-place, no external memory is needed.
• Performs greatly when the array is almost sorted.
• Practical if the input is usually in sort order
Advantages and Disadvantages of
Bubble Sorting
Disadvantages
• Very expensive, O(n2) in worst case and average case.
• It does more element assignments than its counterpart,
insertion sort.
• It is too slow and impractical for most problems even
when compared to insertion sort.
Example of Bubble Sort
• 1st Pass
13254- No Swap
13254- Swap - From the order of items 3 & 2, it will become
2&3
12354- No Swap
12354- Swap - From the order of items 5 & 4, it will become
4&5
Note: the array is already sorted, but the algorithm does not know if it is
completed. The algorithm needs one whole pass without any swap to know it is
sorted.
• 2nd Pass
• 12345- No Swap
• 12345- No Swap
• 12345- No Swap
• 12345- No Swap
Animation:

You might also like