In this project, we got an opportunity to build bubble sort algorithm. One of the simpler (but more processor-intensive) ways of sorting a group of items in an array. Elements are compared and swapped. If the one on the left is larger than the one on the right a swap takes course. This continues until the array is eventually sorted.
Take a look at this entry on Bubble Sort on Wikipedia.
Here is how we built the bubble_sort algorithm:
We first came-up with a pseudo code that explains all the steps to take. Bubble sort compares ach array elements unless the whole array is completely in ascending order. What if the array needs no more swapping as all elements are already ascending? To ease out the issue we used one flag varriable swapped, which helped us see if any swap happened or not. If no swap happened ie the array requires no more looping it comes out of the loop.
We assumed that list of array of numbers are array(n) elements. We further assumed that swap function swaps the value of a given array. We defined a method and called it bubble_sort and gave it codes that will perform the algorithm function. The algorithm performs the function and returns a list of sorted items depending on the if statements.
Built With
- RUBY
👤 Kiptoo Hillary
- Github: @githubhandle
- Twitter: @twitterhandle
- Linkedin: linkedin
- Email: Email
👤 Taiwo Coker
- Github: @githubhandle
- Twitter: @twitterhandle
- Linkedin: linkedin
- Email: Email
🤝 Contributing Contributions, issues and feature requests are welcome!
Show your support Give a ⭐️ if you like this project!