Skip to content

Instantly share code, notes, and snippets.

View AnielaMW's full-sized avatar
☺️
Looking for my next challenge.

A. Wolkonowski AnielaMW

☺️
Looking for my next challenge.
  • RedArgyle
  • Upstate New York
View GitHub Profile
@AnielaMW
AnielaMW / heap_sort.rb
Last active July 19, 2019 06:26
Heap Sort Challenge
require 'pry'
puts "Heap Sort"
# 1. In def heap_sort, we first build a max heap.
# 2. Then, we call a loop: while the array length is greater than 1, swap root element with the last element, reduce the length by 1 (since we have sorted one item), and re-build the heap so that it satisfies the max-heap condition.
# 3. At the end, we remake the array into its original size and revert the root back to index [0].
# 4. The def heapify method will sift the elements until they’re in their rightful place.
# 5. parent indicates where to start sifting and limit tells how far down the heap to sift.
# 6. Set parent node as the root. While the child index is less than or equal to the limit (indicates that root has at least one child), we increment child by 1 to get it’s sibling IF the child is less than limit and the value of child is smaller than value of it’s sibling. The loop terminates if value of root is greater than value of child (since root must always be greater than children in a max heap). Otherwise, swap the
@AnielaMW
AnielaMW / p_and_p.rb
Last active March 11, 2019 22:08
Pride and Prejudice Ruby Logic
puts "Pride and Prejudice Logic"
# It is a truth universally acknowledged, that a single man in possession of a good fortune, must be in want of a wife.
class Man
attr_reader :truth
def initialize (name, single, fortune)
@fortune = fortune
@single = single