Skip to content

Instantly share code, notes, and snippets.

View lightkun10's full-sized avatar
🏠
Working at home

Fierdy Pandu lightkun10

🏠
Working at home
  • Pekanbaru, Indonesia.
View GitHub Profile
@bih
bih / MergeSort.markdown
Last active December 31, 2022 14:20
MergeSort Example in Ruby

MergeSort Algorithm in Ruby

When learning about sorting algorithms, I wanted to implement them to help me understand them better. This algorithm was originally invented by John von Neumann in 1948.

The Ruby script attached explains in real code what is going on. Play about with it.

How does the algorithm work?

Step by step:

  • Pass through an array of unsorted numbers (i.e. [4, 3, 2, 10])
@aspyct
aspyct / sort.rb
Last active October 29, 2023 03:08
Ruby implementation of quicksort, mergesort and binary search
# Sample implementation of quicksort and mergesort in ruby
# Both algorithm sort in O(n * lg(n)) time
# Quicksort works inplace, where mergesort works in a new array
def quicksort(array, from=0, to=nil)
if to == nil
# Sort the whole array, by default
to = array.count - 1
end
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream