3 years ago
csgeek
in English · 1,745 Views
likes 1clips 1comments 2
Data Structures: Max Heaps (in Ruby)
I found this helpful tutorial on heaps in Ruby. A max heap is a tree data structure with the following rules: *The keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node. They are usually implemented as arrays. [10, 4, 8, 2, 1, 7] (Pic 1) But not arrays are heaps, for example: [2,1,7] (Pic 2) * 2 is smaller than 7, which breaks the rule of heaps To learn how to implement this in Ruby, check out the tutorial at the link!
csgeek clipped in 2 collections