December 29 - Building Bubble Sort From Scratch
This coding exercise walks through how to implement the Bubble Sort algorithm in Ruby and how to add it to the built in Array class.
Guide Tasks
- Read Tutorial
- Watch Guide Video
- Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license
Already a Bottega Student? Sign In
Summary
Build the Bubble Sort algorithm from scratch and add it to the Array class in Ruby.
Exercise Description
Given an array of integers, such as:
arr = ['42', '8', '70']
Implement the bubble sort algorithm so that it can be called directly on an array, such as:
arr.bubble_sort
Sample Output
['8', '42', '70']
Real World Usage
Sorting algorithms are popular interview questions. This is mainly because sorting algorithms force you: to think logically, manage data, manipulate collections, and return accurate values. Additionally, to correctly perform this exercise you will need to implement monkey patching, which allows you to add functionality to pre-existing classes in Ruby.