Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-351

Binomial Heap Tree Orders

Problem

Insert n nodes one at a time into a binomial heap. The heap contains one binomial tree for each set bit of n, whose order equals the bit position. Return [tree_count, orders] with orders listed from largest to smallest, or [0, []] for n = 0.

Hint

Merging equal-order trees is binary carry, so the tree orders are exactly the set bits of n.

Test cases

case 1
in: [13]
expected: [3,[3,2,0]]
case 2
in: [7]
expected: [3,[2,1,0]]
case 3
in: [1]
expected: [1,[0]]
case 4
in: [0]
expected: [0,[]]
case 5
in: [64]
expected: [1,[6]]
Starter codePython
def binomial_heap_orders(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor