cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A153241 Balance of general trees as ordered by A014486, variant B.

This page as a plain text file.
%I A153241 #4 Mar 31 2012 13:21:17
%S A153241 0,0,0,0,0,1,-1,0,0,0,1,0,2,2,-1,0,-2,0,1,-2,-1,0,0,0,1,1,2,2,-1,1,0,
%T A153241 3,3,0,3,3,3,-1,0,-1,1,1,-2,-1,-3,0,1,-3,0,2,2,-2,-1,-3,-1,0,-3,-2,0,
%U A153241 1,-3,-2,-1,0,0,0,1,1,2,2,0,2,2,3,3,2,3,3,3,-1,0,0,2,2,-2,1,0,4,4,1,4
%N A153241 Balance of general trees as ordered by A014486, variant B.
%C A153241 This differs from variant A153240 only in that if the degree of the tree is odd (i.e. A057515(n) = 1 mod 2), then the balance of the center-subtree is taken into account ONLY if the total weight of other subtrees at the left and the right hand side from the center were balanced against each other.
%C A153241 Note that for all n, Sum_{i=A014137(n)}^A014138(n) a(i) = 0.
%H A153241 A. Karttunen, <a href="/A153241/b153241.txt">Table of n, a(n) for n = 0..2055</a>
%o A153241 (MIT Scheme:)
%o A153241 (define (A153241 n) (gentree-balance (A014486->parenthesization (A014486 n))))
%o A153241 (define (gentree-balance l) (let ((r (reverse l))) (let loop ((i 0) (j (- (length l) 1)) (l l) (r r) (z 0)) (cond ((= i j) (+ z (if (zero? z) (gentree-balance (car l)) 0))) ((> i j) z) (else (loop (+ i 1) (- j 1) (cdr l) (cdr r) (+ z (- (count-pars (car r)) (count-pars (car l))))))))))
%o A153241 (define (count-pars a) (cond ((not (pair? a)) 0) (else (+ 1 (count-pars (car a)) (count-pars (cdr a))))))
%Y A153241 Differs from variant A153240 for the first time at n=268, where A153240(268) = 2, while a(268)=1. Note that (A014486->parenthesization (A014486 268)) = (() (() (())) (())). a(A061856(n)) = 0 for all n. Cf. also A153239.
%K A153241 sign
%O A153241 0,13
%A A153241 _Antti Karttunen_, Dec 21 2008