Simple Sorting : Bubble sort
Hi,
Today, I'll begin a very long journey of exploring algorithms that you need to know as a software engineer. I'll do my best to describe each and every one simply by providing you sample code in java and python.
Each subsequent post will describe one and only one algorithm. We start by the most simple of them : the Bubble Sort. The bubble sort is notoriously slow.
The bubble sort runs in O(N2) time.
Today, I'll begin a very long journey of exploring algorithms that you need to know as a software engineer. I'll do my best to describe each and every one simply by providing you sample code in java and python.
Each subsequent post will describe one and only one algorithm. We start by the most simple of them : the Bubble Sort. The bubble sort is notoriously slow.
Process
- We start at the left of the array, we compare values in positions 0 and 1
- If the value at index 0 is bigger, swap them
- Move on the right
- When you reach the end of the first pass, you know that the last value is sorted, start over at the left of the array till N-x (the number of pass)
Java:
Python:
Comments
Post a Comment