Find a file
2017-10-08 21:54:42 +05:30
data-structures Heap datastructure added 2017-10-08 21:54:42 +05:30
BogoSort.rb Create BogoSort.rb 2016-08-12 22:11:35 +05:30
BubbleSort.rb Added Bubble Sort 2016-07-25 23:03:27 +05:30
InsertionSort.rb Insertion Sort Ruby 2016-07-26 23:46:43 +05:30
README.md Update README.md 2017-09-28 18:58:07 +05:30
Selection_Sort.rb Create Selection_Sort.rb 2017-09-28 18:48:29 +05:30

The Algorithms - Ruby

All algorithms implemented in Ruby (for education)

These are for demonstration purposes only.

Sorting Algorithms

Bogo Sort

Add comments here

Bubble Sort

alt text

From Wikipedia: Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

Properties

  • Worst case performance O(n^2)
  • Best case performance O(n)
  • Average case performance O(n^2)
View the algorithm in action

Insertion Sort

alt text

From Wikipedia: Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.

Properties

  • Worst case performance O(n^2)
  • Best case performance O(n)
  • Average case performance O(n^2)
View the algorithm in action

Selection Sort

alt text

From Wikipedia: The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.

Properties

  • Worst case performance O(n^2)
  • Best case performance O(n^2)
  • Average case performance O(n^2)
View the algorithm in action