2. List of contents
● Introduction
● Example w/ illustrating figures
● Algorithm
● implementation (Java, C++, Python)
● Performance Runtime
○ Best, Average and worst cases.
● Execution
● Other Notes
3. Introduction
● the simplest sorting algorithm that works by repeatedly swapping the adjacent
elements if they are in wrong order.
● Used in a polygon filling algorithm ,
○ bounding lines are sorted by their x coordinate at a specific (x-parallel) scan line
○ with incrementing y their order changes (two elements are swapped) only at
intersections of two lines
5. Algorithm .
● Loop throw the array
● Loop throw the array-1
● If this index is bigger than it’s bigger adjacent
○ do swap values of index and it’s bigger adjacent .
9. Python .
def bubbleSort(a):
for i in range(len(a)):
for j in range(0, len(a)-i-1):
if a[j] > a[j+1] :
a[j], a[j+1] = a[j+1], a[j]
10. Performance Runtime
● Time complexity Θ(n2) .
● Best case : when array is already sorted. Θ(n) .
● Worst case : when array is reverse sorted. Θ(n2)
● Average case : O(n) <f(n) < O(n2)