https://github.com/marlonmontenegro/rubybubblesort
The Bubble Sort exercise challenges I implement the Bubble Sort algorithm in Ruby. Bubble Sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order.
https://github.com/marlonmontenegro/rubybubblesort
Last synced: 4 months ago
JSON representation
The Bubble Sort exercise challenges I implement the Bubble Sort algorithm in Ruby. Bubble Sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order.
- Host: GitHub
- URL: https://github.com/marlonmontenegro/rubybubblesort
- Owner: MarlonMontenegro
- Created: 2023-08-21T18:39:37.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T19:17:56.000Z (almost 2 years ago)
- Last Synced: 2025-01-23T17:16:08.606Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Bubble Sort Algorithm in Ruby
The Bubble Sort exercise challenges you to implement the Bubble Sort algorithm in Ruby. Bubble Sort is a simple sorting algorithm that repeatedly steps through a list, compares adjacent elements, and swaps them if they are in the wrong order. The goal is to sort the list by "bubbling up" the largest (or smallest) elements to their correct positions.
## Exercise Description
The purpose of this exercise is to implement the Bubble Sort algorithm using Ruby. You will create a method called `bubble_sort` that takes an array as input and returns a sorted version of the array. The exercise involves iterating through the array, comparing adjacent elements, and swapping them as needed to ensure the array is sorted.
## Features
- **Sorting Logic:** The `bubble_sort` method uses nested loops to iterate through the array and swap elements as needed to achieve sorting.
- **Adjacent Element Comparison:** The algorithm compares adjacent elements and swaps them if they are in the wrong order.
- **Optimization:** After each iteration, the largest (or smallest) element is moved to its correct position, reducing the number of comparisons in subsequent iterations.
- **Output:** The method returns a sorted array.## Example
For example, if you provide the `unsorted_array = [64, 34, 25, 12, 22, 11, 90]`, the expected output might be:
Sorted Array: [11, 12, 22, 25, 34, 64, 90]The method correctly sorts the provided array using the Bubble Sort algorithm.