Giter Site home page Giter Site logo

ruby's Introduction

The Algorithms - Ruby

All algorithms implemented in Ruby (for education)

These are for demonstration purposes only. For a full list of all algorithms, please see:DIRECTORY.md

Sorting Algorithms

Bogo Sort

alt text

From Wikipedia: Bogo sort is a highly ineffective sorting function based on the generate and test paradigm. The function successively generates permutations of its input until it finds one that is sorted. It is not useful for sorting, but may be used for educational purposes, to contrast it with more efficient algorithms.

Properties

  • Unbounded (randomized version), O((n+1)!) (deterministic version)
  • Best case performance O(n)
  • Average case performance O((n+1)!)

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

Shell Sort

alt text

From Wikipedia: Shellsort, also known as Shell sort or Shell's method, is an in-place comparison sort. It can be seen as either a generalization of sorting by exchange (bubble sort) or sorting by insertion (insertion sort).[3] The method starts by sorting pairs of elements far apart from each other, then progressively reducing the gap between elements to be compared. Starting with far apart elements, it can move some out-of-place elements into position faster than a simple nearest neighbor exchange. Donald Shell published the first version of this sort in 1959.[4][5] The running time of Shellsort is heavily dependent on the gap sequence it uses. For many practical variants, determining their time complexity remains an open problem.

Properties

  • Worst case performance O(n^2)
  • Best case performance O(n log n)
  • Average case performance depends on gap sequence
View the algorithm in action

ruby's People

Contributors

dynamitechetan avatar christianbender avatar vzvu3k6k avatar anew-bhav avatar anupkumarpanwar avatar stepfenshawn avatar doppon avatar raivaibhav avatar simonszu avatar pablohildo avatar red0xff avatar andredurao avatar t-mangoe avatar michellejanosi avatar ievaskrabutena avatar tuwukee avatar vitorcarminatti avatar thomashhuang avatar spencerking avatar nikhilkala avatar mateusluizfb avatar ankitxjoshi avatar juantaldea avatar dandynaufaldi avatar andrewhyi avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.