

Sorting algorithms made in ruby
source link: https://www.tuicool.com/articles/hit/JZfIRj7
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

What is bubble sort?
It is just a simple algorithm which works by repeatedly swapping the adjacent elements if they are in wrong order. Basically swapping it with the largest integer.
Example:
[1, 5, 2, 3, 4] = (5 <> 2) = [1, 2, 5, 3, 4] = (5 <> 3) = [1, 2, 3, 5, 4] = (5 <> 4) = [1, 2, 3, 4, 5]
What is selection sort?
The selection sort algorithm is simple as the bubblesort one, it works by repeatedly finding the minimum elements. In order for it to understand, you may also classify it as going in "ascending order".
Example:
[64, 25, 12, 22, 11] = (11 <> 64) = [11, 25, 12, 22, 64] = (25 <> 12) = [11, 12, 25, 22, 64] = (25 <> 22) = [11, 12, 22, 25, 64]
What is insertion sort?
Insertion sort is basically like arranging the integers inside your array in a correct order, it works by swapping the elements in order to bring them to correct order.
Example:
[4, 3, 2, 1] = (4 <> 1) = [1, 3, 2, 4] = (3 <> 2) = [1, 2, 3, 4]
What is comb sort?
Comb sort is basically an improved version of bubble sort. Bubble sort always compares adjacent values but comb sort is a bit different, it uses a gap size more than 1 instead of removing all the inversions one by one. The gap starts with a large value and shrinks by a factor of 1.3 in every iteration until it reaches the value 1, thus instead of removing inversions one by one it actually works by removing more than one inversion with only one swap.
Example:
[1, 5, 2, 3, 4] = (5 <> 2) = [1, 2, 5, 3, 4] = (5 <> 3) = [1, 2, 3, 5, 4] = (5 <> 4) = [1, 2, 3, 4, 5]
Result would be much more faster if you compare it using comb sort and bubble sort.
Recommend
-
102
Page not found · GitHub · GitHub Skip to content...
-
30
Sort Algos in C Sorting Algorithms General Implementations in C Programming Language sort-algos-int.c is the most naive version. Every C programming language beginner could understan...
-
12
Sortingis a basic building block that many other algorithms are built upon. It’s related to several exciting ideas that you’ll see throughout your programming career. Understanding how sorting algorithms in Python work behind the scenes is...
-
6
Timsort and Introsort: Swift's Sorting Algorithms Timsort and Introsort: Swift's Sorting Algorithms September 4, 2019 Have you ever asked yourself which algorithm is used by Swift's sorting metho...
-
7
Introduction to Sorting Algorithms in Python Sorting is a basic building block that many other algorithms are built upon. It’s related to several exciting ideas that you’ll see throughout your programming career. Un...
-
5
In this next part of the big STL algorithm tutorial, we cover the sorting operations - except for ranges which will be covered in a different series. sor...
-
6
Sorting Visualizer Responsive visualizer built using React for popular algorithms See it in action This repo is an attempt to help in...
-
6
Test-Driven Algorithms - SortingJune 10, 2021Sorting algorithms are heavily used in Software Development in one way or another. Depending on the language, you might have in handy some sorting functions at your disposal but dep...
-
6
Sorting Algorithms in TypeScriptFive sort algorithms (Bubble, Selection, Insertion, Merge, Quick) and how we can implement them in TypeScriptThe five most common sorting algorithms are:Bubbl...
-
8
Sorting Algorithms that don’t Hate You(This is a sort of sequel to Hash Maps that don’t Hate You.)
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK