Sorting Algorithms 1

By Cooldudue | My Coding adventure | 11 May 2022


Hello everyone

Before I dive deep into the theory of sorting algorithms, I thought it would be a fun exercise to create my own algorithms and see how they compare to those I will learn about. The algorithm I have prepared today simply compares the one element to the adjacent to it, and if the first element is bigger it swaps them. It does this throughout the whole list n times, where n is the length of the list. This algorithm has a time complexity of O(n^2) for its best, average and worst cases. One way to improve the best and average case would be to check if the list is sorted at each step of the first for loop. However, this will make the worst-case scenario much worse. 

Thank you for reading. If you would like to see more of my work check out my GitHub.

How do you rate this article?

0



My Coding adventure
My Coding adventure

Hello, I am a recent graduate from the University of Cape Town. I have a Bachelor of Science in Mathematics and Applied Mathematics. I am interested in becoming a developer. If you are interested in hiring please check out my CV and we can get in contact. I will be posting any projects I am working on here. My Java is a little rusty so I will be working on small problems to familiarise myself again. My CV: https://docs.google.com/document/d/1qVs7YYqWrkn70xxv6EdDgAH3k7LVA2unwC8tLzQCS4M/edit?usp=sharing

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.