Skip to content

Instantly share code, notes, and snippets.

View caovanbi235's full-sized avatar
🏠
Working from home

Cao Van Bi caovanbi235

🏠
Working from home
View GitHub Profile
@caovanbi235
caovanbi235 / priority_queue.rb
Created March 31, 2025 05:25
Ruby Priority Queue
class PriorityQueue
def initialize
@heap = []
end
def push(item, priority)
@heap << [item, priority]
bubble_up_iterative(@heap.size - 1)
self
end
@caovanbi235
caovanbi235 / unionfind.rb
Last active March 31, 2025 05:22
Ruby UnionFind
class UnionFind
def initialize(n)
@d = Array.new(n, -1)
end
def root(x)
return x if @d[x] < 0
@d[x] = root(@d[x])
end