Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132938 views
License: OTHER
1
cbal_tree(0,nil) :- !.
2
cbal_tree(N,t(x,L,R)) :- N > 0,
3
N0 is N - 1,
4
N1 is N0//2, N2 is N0 - N1,
5
distrib(N1,N2,NL,NR),
6
cbal_tree(NL,L), cbal_tree(NR,R).
7
8
distrib(N,N,N,N) :- !.
9
distrib(N1,N2,N1,N2).
10
distrib(N1,N2,N2,N1).
11