/ binary heap \d hpbn / shift down sd:{$[(yx@i:(z>)#y,-1 0+2*y+1;o[@[x;y,i[c];:;x@i[c],y];i[c];z];x]} / shift up su:{$[y&>/v:x@y,s:-2!y-1;o[@[x;s,y;:;v];s];x]} /heapify hp:{sd/[x;|:!c:1+-2!-2+#x;#x]} / heap insert hi:{su[x,y;#x]} / max extract hx:{(*x;sd[(*|x),-1_1_x;0;#x])} / heap sort hs:{h:hp@x;*(-1+#x)({(sd[@[x;0,y;:;x@y,0];0;y];y-1)}.)/(h;-1+#x)} / binomial heap \d hpbl / heap insert hi:{mg@hi0[x;y]} hi0:{(r;p;d;n):x;(r,#p;p,#p;d,0;n,y)} / merge heap mg:{(r;p;d):-1_x *{$[2>#l:*|x;x ~=/x[0;2;2#l];x (cm[*x;2#l];1_l)]}/(x;@/1(n@r p:@[p;r@m;:;0N] p:@[p;c;:;c:&p=r@m] (n@r@m;mg@(c,r_m;p;d;n))} \d .