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.

Showing 1-10 of 13 results. Next

A001855 Sorting numbers: maximal number of comparisons for sorting n elements by binary insertion.

Original entry on oeis.org

0, 1, 3, 5, 8, 11, 14, 17, 21, 25, 29, 33, 37, 41, 45, 49, 54, 59, 64, 69, 74, 79, 84, 89, 94, 99, 104, 109, 114, 119, 124, 129, 135, 141, 147, 153, 159, 165, 171, 177, 183, 189, 195, 201, 207, 213, 219, 225, 231, 237, 243, 249, 255, 261, 267, 273, 279, 285
Offset: 1

Views

Author

Keywords

Comments

Equals n-1 times the expected number of probes for a successful binary search in a size n-1 list.
Piecewise linear: breakpoints at powers of 2 with values given by A000337.
a(n) is the number of digits in the binary representation of all the numbers 1 to n-1. - Hieronymus Fischer, Dec 05 2006
It is also coincidentally the maximum number of comparisons for merge sort. - Li-yao Xia, Nov 18 2015

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, Sect 5.3.1, Eq. (3); Sect. 6.2.1 (4).
  • J. W. Moon, Topics on Tournaments. Holt, NY, 1968, p. 48.
  • N. J. A. Sloane, A Handbook of Integer Sequences, Academic Press, 1973 (includes this sequence).
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • Tianxing Tao, On optimal arrangement of 12 points, pp. 229-234 in Combinatorics, Computing and Complexity, ed. D. Du and G. Hu, Kluwer, 1989.

Crossrefs

Programs

  • Haskell
    import Data.List (transpose)
    a001855 n = a001855_list !! n
    a001855_list = 0 : zipWith (+) [1..] (zipWith (+) hs $ tail hs) where
       hs = concat $ transpose [a001855_list, a001855_list]
    -- Reinhard Zumkeller, Jun 03 2013
    
  • Maple
    a := proc(n) local k; k := ilog2(n) + 1; 1 + n*k - 2^k end; # N. J. A. Sloane, Dec 01 2007 [edited by Peter Luschny, Nov 30 2017]
  • Mathematica
    a[n_?EvenQ] := a[n] = n + 2a[n/2] - 1; a[n_?OddQ] := a[n] = n + a[(n+1)/2] + a[(n-1)/2] - 1; a[1] = 0; a[2] = 1; Table[a[n], {n, 1, 58}] (* Jean-François Alcover, Nov 23 2011, after Pari *)
    a[n_] := n IntegerLength[n, 2] - 2^IntegerLength[n, 2] + 1;
    Table[a[n], {n, 1, 58}] (* Peter Luschny, Dec 02 2017 *)
    Accumulate[BitLength[Range[0, 100]]] (* Paolo Xausa, Sep 30 2024 *)
  • PARI
    a(n)=if(n<2,0,n-1+a(n\2)+a((n+1)\2))
    
  • PARI
    a(n)=local(m);if(n<2,0,m=length(binary(n-1));n*m-2^m+1)
    
  • Python
    def A001855(n):
        s, i, z = 0, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A001855(n) for n in range(1, 59)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A001855(n): return n*(m:=(n-1).bit_length())-(1<Chai Wah Wu, Mar 29 2023

Formula

Let n = 2^(k-1) + g, 0 <= g <= 2^(k-1); then a(n) = 1 + n*k - 2^k. - N. J. A. Sloane, Dec 01 2007
a(n) = Sum_{k=1..n}ceiling(log_2 k) = n*ceiling(log_2 n) - 2^ceiling(log_2(n)) + 1.
a(n) = a(floor(n/2)) + a(ceiling(n/2)) + n - 1.
G.f.: x/(1-x)^2 * Sum_{k>=0} x^2^k. - Ralf Stephan, Apr 13 2002
a(1)=0, for n>1, a(n) = ceiling(n*a(n-1)/(n-1)+1). - Benoit Cloitre, Apr 26 2003
a(n) = n-1 + min { a(k)+a(n-k) : 1 <= k <= n-1 }, cf. A003314. - Vladeta Jovovic, Aug 15 2004
a(n) = A061168(n-1) + n - 1 for n>1. - Hieronymus Fischer, Dec 05 2006
a(n) = A123753(n-1) - n. - Peter Luschny, Nov 30 2017

Extensions

Additional comments from M. D. McIlroy (mcilroy(AT)dartmouth.edu)

A070941 Length of binary representation of 2n+1.

Original entry on oeis.org

1, 2, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
Offset: 0

Views

Author

N. J. A. Sloane, May 18 2002

Keywords

Comments

Sequence consists of A011782(n) n+1's. - Jon Perry, Apr 04 2004
For n > 0: a(n) = A003314(n+1) - A003314(n) = A123753(n) - A123753(n-1). - Reinhard Zumkeller, Oct 12 2006
For k >= 2, k appears 2^(k-2) times consecutively. - Bernard Schott, Jun 08 2019
Also length of binary representation of 2n. - Michel Marcus, Oct 28 2020

Crossrefs

Bisection of A070939 and also of A070940.

Programs

  • Mathematica
    Table[IntegerLength[n,2],{n,1,201,2}] (* Harvey P. Dale, May 17 2011 *)
  • PARI
    a(n)=length(binary(2*n+1))
    
  • Python
    def A070941(n): return n.bit_length()+1 # Chai Wah Wu, Mar 29 2023

Formula

Let b(1)=1, b(n) = a(n-floor(n/2)) + 1, then a(n) = b(n+1). - Benoit Cloitre, Oct 23 2002
G.f.: 1/(1-x) * (1 + Sum_{k>=0} x^2^k). - Ralf Stephan, Apr 15 2002
a(n) = ceiling(log_2(n+1)) + 1 = A029837(n+1) + 1. - Ralf Stephan, Apr 15 2002
a(n) = ceiling(average of previous entries) + 1. - Jon Perry, Apr 04 2004

A123753 Partial sums of A070941.

Original entry on oeis.org

1, 3, 6, 9, 13, 17, 21, 25, 30, 35, 40, 45, 50, 55, 60, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119, 125, 131, 137, 143, 149, 155, 161, 168, 175, 182, 189, 196, 203, 210, 217, 224, 231, 238, 245, 252, 259, 266, 273, 280, 287, 294, 301, 308, 315, 322, 329, 336, 343
Offset: 0

Views

Author

Reinhard Zumkeller, Oct 12 2006

Keywords

Crossrefs

Programs

  • Maple
    A123753 := proc(n) local i, J, z; i := n+1: J := i; i := i-1; z := 1;
    while 0 <= i do J := J+i; i := i-z; z := z+z od; J end:
    seq(A123753(n), n=0..57); # Peter Luschny, Nov 30 2017
    # Alternatively:
    a := n -> (n+1)*(1 + ilog2(2*n+3)) - 2^ilog2(2*n+3) + 1:
    seq(a(n), n=0..57); # Peter Luschny, Dec 02 2017
  • Mathematica
    a[n_] := (n + 1)(1 + IntegerLength[n + 1, 2]) - 2^IntegerLength[n + 1, 2] + 1;
    Table[a[n], {n, 0, 57}] (* Peter Luschny, Dec 02 2017 *)
  • Python
    def A123753(n):
        s, i, z = n+1, n, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A123753(n) for n in range(0, 58)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A123753(n): return (n+1)*(1+(m:=n.bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = A003314(n+1)+1. - Reinhard Zumkeller, Oct 12 2006
Let bil(n) = floor(log_2(n)) + 1 for n>0, bil(0) = 0 and b(n) = n + n*bil(n) - 2^bil(n) + 1 then a(n) = b(n+1). (This suggests that '0' be prepended to this sequence.) - Peter Luschny, Dec 02 2017

A033156 a(1) = 1; for m >= 2, a(n) = a(n-1) + floor(a(n-1)/(n-1)) + 2.

Original entry on oeis.org

1, 4, 8, 12, 17, 22, 27, 32, 38, 44, 50, 56, 62, 68, 74, 80, 87, 94, 101, 108, 115, 122, 129, 136, 143, 150, 157, 164, 171, 178, 185, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408
Offset: 1

Views

Author

N. J. A. Sloane, Jun 05 2002

Keywords

Crossrefs

Cf. A123753.

Programs

  • Maple
    A033156 := proc(n) option remember; if n=1 then 1 else A033156(n-1)+floor(A033156(n-1)/(n-1))+2; fi; end;
  • Mathematica
    a[n_] := n (2 + IntegerLength[n, 2]) - 2^IntegerLength[n, 2];
    Table[a[n], {n, 1, 59}] (* Peter Luschny, Dec 02 2017 *)
    nxt[{n_,a_}]:={n+1,a+Floor[a/n]+2}; NestList[nxt,{1,1},60][[All,2]] (* Harvey P. Dale, Nov 03 2020 *)
  • Python
    def A033156(n):
        s, i, z = 2*n-1, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A033156(n) for n in range(1, 60)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A033156(n): return n*(2+(m:=(n-1).bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = n*(floor(log_2 n) + 3) - 2^((floor (log_2 n)) + 1).
a(n) = n + a(floor(n/2)) + a(ceiling(n/2)) = n + min{a(k) + a(n-k):0 < k < n} = n + A003314(n). - Henry Bottomley, Jul 03 2002
A001855(n) + 2n-1. a(n) = b(n)+1 with b(0)=0, b(2n) = b(n) + b(n-1) + 2n + 2, b(2n+1) = 2b(n) + 2n + 3. - Ralf Stephan, Oct 24 2003
a(n) = A123753(n-1) + n - 1. - Peter Luschny, Nov 30 2017

A054248 Binary entropy: a(n) = n + min { a(k)+a(n-k) : 1 <= k <= n-1 }.

Original entry on oeis.org

1, 2, 6, 8, 13, 16, 21, 24, 30, 34, 40, 44, 50, 54, 60, 64, 71, 76, 83, 88, 95, 100, 107, 112, 119, 124, 131, 136, 143, 148, 155, 160, 168, 174, 182, 188, 196, 202, 210, 216, 224, 230, 238, 244, 252, 258, 266, 272, 280, 286, 294, 300, 308, 314, 322, 328, 336
Offset: 1

Views

Author

N. J. A. Sloane, May 04 2000

Keywords

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 3, p. 374.

Crossrefs

Programs

  • Maple
    A054248 := proc(n) local i,j; option remember; if n<=2 then n else j := 10^10; for i from 1 to n-1 do if A054248(i)+A054248(n-i) < j then j := A054248(i)+A054248(n-i); fi; od; n+j; fi; end;
    # second Maple program:
    a:= proc(n) option remember; `if`(n<3, n,
          n + min(seq(a(k)+a(n-k), k=1..n/2)))
        end:
    seq(a(n), n=1..80);  # Alois P. Heinz, Aug 29 2015
  • Mathematica
    a[n_] := n + n IntegerLength[n, 2] - 2^IntegerLength[n, 2] + Mod[n, 2];
    Table[a[n], {n, 1, 54}] (* Peter Luschny, Dec 02 2017 *)
  • Python
    def A054248(n):
        s, i, z = n - (n-1) % 2, n-1, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A054248(n) for n in range(1, 55)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A054248(n): return n*(1+(m:=(n-1).bit_length()))-(1<Chai Wah Wu, Mar 29 2023

Formula

a(n) = A123753(n-1) - (n-1) mod 2. - Peter Luschny, Nov 30 2017

A097383 Minimum total number of comparisons to find each of the values 1 through n using a binary search with 3-way comparisons (less than, equal and greater than).

Original entry on oeis.org

0, 2, 3, 6, 8, 11, 13, 17, 20, 24, 27, 31, 34, 38, 41, 46, 50, 55, 59, 64, 68, 73, 77, 82, 86, 91, 95, 100, 104, 109, 113, 119, 124, 130, 135, 141, 146, 152, 157, 163, 168, 174, 179, 185, 190, 196, 201, 207, 212, 218, 223, 229, 234, 240, 245, 251, 256, 262, 267, 273
Offset: 1

Views

Author

Keywords

Comments

Optimal binary search with equality.

Examples

			a_5 = 8 = 5 + a_1 + a_3; this is the smallest example where choosing the middle value is not optimal.
		

Crossrefs

See A097384 for the sequence with a pure binary search.
A003314 is the sequence with only 2-way comparisons.
Cf. A123753.

Programs

  • Maple
    f:= proc(n) option remember;
         n+min(seq(procname(k)+procname(n-1-k),k=1..n-1))
    end proc:
    f(1):= 0: f(0):= 0:
    map(f, [$1..100]); # Robert Israel, Nov 30 2017
  • Mathematica
    a[n_] := (n+1)(1+IntegerLength[n+1,2])-2^IntegerLength[n+1,2]-Quotient[3n+1,2];
    Table[a[n], {n, 1, 60}] (* Peter Luschny, Dec 02 2017 *)
  • Python
    def A097383(n):
        s, i, z = -n//2, n, 1
        while 0 <= i: s += i; i -= z; z += z
        return s
    print([A097383(n) for n in range(1, 61)]) # Peter Luschny, Nov 30 2017
    
  • Python
    def A097383(n): return (n+1)*(m:=n.bit_length())-(1<>1) # Chai Wah Wu, Mar 29 2023

Formula

a(n) = min_{1<=k<=n-1} n + a(k) + a(n-1-k).
a(n) = A123753(n) - floor(3*(n+1)/2). - Peter Luschny, Nov 30 2017
From Robert Israel, Nov 30 2017: (Start)
Empirical: a(n+3)-a(n+2)-a(n+1)+a(n) = 1 if n = 2^k-3 or 2^k-2 for some k, 0 otherwise.
Empirical g.f.: (2*x^2+x^3)/(1-x-x^2+x^3) + Sum_{k>=2} x^{2^k}/(1-x)^2. (End)

A347301 Let S be a set of n distinct integers in the range -n-3 to n+3, and consider the sums s+t of pairs of distinct elements of S; a(n) is the maximum number of such sums that are powers of 2, over all choices for S.

Original entry on oeis.org

0, 1, 3, 4, 5, 7, 9, 11, 13, 15, 17, 19, 21, 24, 26, 29, 31, 34, 36, 39, 41, 44, 46, 49, 51, 54, 56, 59, 61, 65, 67, 71, 73, 77, 79, 83, 85, 89, 91, 95, 97, 101, 103, 107, 109, 113, 115, 119, 121, 125, 127, 131, 133, 137, 139, 143, 146, 149, 152, 155, 159, 162, 166, 169, 173, 176
Offset: 1

Views

Author

N. J. A. Sloane, Aug 28 2021, based on information supplied by Rob Pratt and Stan Wagon

Keywords

Comments

For a given set S, we count pairs (s,t) with s in S, t in S, s < t, and s+t equal to a power of 2. (The powers need not be distinct.)
Arises in studying Stan Wagon's Problem of the Week 1321, which asks for the maximum number b(n) if S can be any set of n distinct integers.
The values of a(n) for n <= 100 were found by Rob Pratt using a MILP solver. See links.
Of course b(n) >= a(n). For b(n) see A352178. - N. J. A. Sloane, Mar 07 2022
b(5) >= 6 from {-3, -1, 3, 5, 11} whereas a(5) = 5 from {-4, -3, -1, 3, 5}.
Comments from Rob Pratt: (Start)
With [-100,100] bounds, the optimal values for n=11 to 15 are 17, 19, 21, 24, 26.
With [-70,70] bounds, the optimal values for n=16 to 20 are 29, 31, 34, 36, 39.
The following two infinite families of odd consecutive integers appear to yield an n*log n lower bound.
(C1) For n odd, take S = {4-n, 6-n, ..., -3, -1, 1, 3, ..., n, n+2}.
(C2) For n even, take S = {5-n, 7-n, ..., -3, -1, 1, 3, ..., n+1, n+3}.
This is not always optimal. For example, you can do at least 1 better for n = 27 and 28.
n = 27: S = {-23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29} yields 56;
n = 28: S = {-23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31} yields 59;
n = 27: S = {-21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 37} yields 57;
n = 28: S = {-21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 35, 37} yields 60.
(End)
Comments from N. J. A. Sloane, Feb 21 2022: (Start)
Construction (C1) can be analyzed as follows. For n = 1, 3, 5, 7, ... the number of powers of 2 are 0, 2, 5, 9, 13, 17, 21, 26, 31, 36, 41, 46, 51, 56, 61, 67, 73, 79, 85, .... (*)
I computed 200 terms of (*), took first differences, and then the RUNS transform, getting essentially A070941, which implies that (*) appears to be A003314((n+1)/2)-3, which is (1/2)*n*log_2(n) - O(n). This is a plausible lower bound on a(n) for all n, and could even be the true order of growth. (End)
From Chai Wah Wu, Sep 21 2022: (Start)
If for S = {t_i}_i, all the integers t_i are even, then the set S generates the same number of powers of 2 as {t_i/2}_i. This is because 2a+2b is a power of 2 if and only if a+b is a power of 2.
It appears that a(n) can be achieved using S with only odd integers (this may be true for A352178 as well):
a(2) = 1: { -3, 5 }
a(3) = 3: { -1, 3, 5 }
a(4) = 4: { -3, -1, 3, 5 }
a(5) = 5: { -3, -1, 1, 3, 5 }
a(6) = 7: { -5, -3, -1, 5, 7, 9 }
a(7) = 9: { -5, -3, -1, 3, 5, 7, 9 }
a(8) = 11: { -7, -5, -3, -1, 5, 7, 9, 11 }
a(9) = 13: { -7, -5, -3, -1, 3, 5, 7, 9, 11 }
a(10) = 15: { -9, -5, -3, -1, 3, 5, 7, 9, 11, 13 }
a(11) = 17: { -9, -7, -5, -3, -1, 3, 5, 7, 9, 11, 13 }
a(12) = 19: { -9, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13 }
a(13) = 21: { -11, -7, -5, -3, -1, 1, 3, 5, 7, 9, 11, 13, 15 }
(End)
Comments from Eric Snyder, Oct 22 2022: (Start)
Construction (C1), along with the variable M from S. Wagon's solution linked below, is not unique to each n. For instance, for n = 128, all of M = {9, 11, 13, 15, 17} result in the same value, a(n) = 399. (However, for n = 4^p, M = 1 + 2^p does seem to be unique.)
If we consider only the central value of M for each n, M appears to be a stepwise function that "prefers" values near powers of 2, or halfway between powers of 2.
Conjecture: Construction (C1), with proper values of M, will compute the majority of maximal values for a(n). The exceptions, like 27, 28 above, seem to cluster near (7/8)*2^k, with a run from n = 54 to n = 59, and another from n = 111 to n = 124 (comparing values from (C1) to those provided by T. Scheuerle in A352178).
These exceptions seem to arise because including 2^k+1 and/or 2^k+3 in the set allows for connections to -1 and -3 (as well as lower negative numbers), where having 2^k-1 or 2^k-3 in the set of values would only connect to lower negative numbers. (End)

Examples

			a(3) = b(3) = 3 from S = {-1, 3, 5}.
		

Crossrefs

See A352178 for the unrestricted problem.

A228152 Triangle read by rows: T(n,k) = maximal external path length of AVL trees of height n with k (leaf-) nodes, n>=0, fibonacci(n+2)<=k<=2^n.

Original entry on oeis.org

0, 2, 5, 8, 12, 16, 20, 24, 25, 30, 35, 40, 44, 49, 54, 59, 64, 50, 56, 62, 68, 73, 79, 85, 91, 97, 102, 107, 113, 119, 125, 131, 136, 142, 148, 154, 160, 96, 103, 110, 117, 123, 130, 137, 144, 151, 157, 163, 170, 177, 184, 191, 197, 204, 211, 218, 225, 231
Offset: 0

Views

Author

Herbert Eberle, Aug 13 2013

Keywords

Comments

The external path length of a tree is the sum of the levels of its external nodes (i.e. leaves).

Examples

			T(2,3) = 5 because in the (two) AVL trees of height 2 with 3 (leaf-) nodes one has depth 1 and two have depth 2:
       o       o
      / \     / \
     o   1   1   o
    / \         / \
   2   2       2   2
so that the sum of depths is 5 for both trees.
Triangle begins:
  0
  . 2
  . . 5 8
  . . . . 12 16 20 24
  . . . .  .  .  . 25 30 35 40 44 49 54 59 64
  . . . .  .  .  .  .  .  .  .  . 50 56 62 68 73 79 85 91 97 102 ...
  . . . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 96 103 ...
		

References

  • D. E. Knuth, Art of Computer Programming, Vol. 3, Sect. 6.2.3 (7) and (8).

Crossrefs

Row maxima give: n*2^n = A036289(n).
Row minima give: A067331(n-1) for n>0 or A166106(n+2).
Row lengths give: 1+A008466(n).
Number of AVL trees read by rows gives: A143897.
Triangle read by columns gives: A228153.
The infimum of all external path lengths of binary trees with k (leaf-) nodes is: A003314(k) for k>0.
Column maxima give: A228155(k).
Column heights give: A217710(k).
Number of AVL trees read by columns gives: A217298.

Programs

  • Maple
    with(combinat): F:=fibonacci:
    T:= proc(n, k) option remember; `if`(n<1, 0, max(seq([k+T(n-1,t)+
          T(n-1,k-t), k+T(n-1,t) +T(n-2,k-t)][], t=F(n+1)..k-1)))
        end:
    seq(seq(T(n, k), k=F(n+2)..2^n), n=0..7);  # Alois P. Heinz, Aug 14 2013
  • Mathematica
    maxNods = 100; Clear[T, A029837, A072649, A036289, A228155]; T[0, 1] = 0; A029837[1] = 0; A072649[1] = 1; A228155[1] = 0; For[k = 2, k <= maxNods, k++, A029837[k] = maxNods; A072649[k] = 0; A228155u = 0; For[kL = 1, kL <= Floor[k/2], kL++, For[hL = A029837[kL], hL <= A072649[kL] - 1, hL++, For[hR = Max[hL - 1, A029837[k - kL]], hR <= Min[hL + 1, A072649[k - kL] - 1], hR++, maxDepthSum = k + T[hL, kL] + T[hR, k - kL]; A228155u = Max[maxDepthSum, A228155u]; h = Max[hL, hR] + 1; If[ !IntegerQ[T[h, k]], T[h, k] = maxDepthSum, T[h, k] = Max[maxDepthSum, T[h, k]]]; A029837[k] = Min[h, A029837[k]]; If[ !IntegerQ[A036289[h]], A036289[h] = maxDepthSum, A036289[h] = Max[maxDepthSum, A036289[h]]]; A072649[k] = Max[h + 1, A072649[k]]; ]]]; A228155[k] = A228155u]; k =.; Table[T[n, k], {n, 0, maxNods}, {k, 1, maxNods}] // Flatten // Select[#, IntegerQ]& (* Jean-François Alcover, Aug 14 2013, translated and adapted from Herbert Eberle's MuPAD program *)
  • MuPAD
    maxNods:=100: // max number of leaves (= external nodes)
    // Triangle T for all AVL trees with <= maxNods leaves:
    delete T:
    // table T indexed [h, k] (h=height, k=number of leaves):
    T[0, 1]:=0:
    // A029837 indexed [k], min height of tree with k leaves:
    A029837:=array(1..maxNods): A029837[1]:=0:
    // A072649 indexed [k], 1+max height of AVL tree with k leaves:
    A072649:=array(1..maxNods): A072649[1]:=1:
    // A036289 indexed [h], max depthsum of all height h AVL trees:
    A036289:=array(1..maxNods):
    // A228155 indexed [k], max depthsum of all AVL trees with k leaves:
    A228155:=array(1..maxNods): A228155[1]:=0:
    for k from 2 to maxNods do:
      A029837[k]:=maxNods: // try infinity for the min height
      A072649[k]:=0:
      A228155u:=0:
      // Put together 2 AVL trees:
      for kL from 1 to floor(k/2) do:
        // kL leaves in the left tree
        for hL from A029837[kL] to A072649[kL]-1 do:
          for hR from max(hL-1, A029837[k-kL])
                   to min(hL+1, A072649[k-kL]-1) do:
            // k-kL leaves in the right subtree
            maxDepthSum:=T[hL, kL]+T[hR, k-kL]+k:
            A228155u:=max(maxDepthSum, A228155u):
            h:=max(hL, hR)+1:
            if type(T[h, k]) <> DOM_INT then // T[h, k] uninit
              T[h, k]:=maxDepthSum:
            else
              T[h, k]:=max(maxDepthSum, T[h, k]):
            end_if:
            A029837[k]:=min(h, A029837[k]):
            if type(A036289[h]) <> DOM_INT then
              A036289[h]:=maxDepthSum:
            else
              A036289[h]:=max(maxDepthSum, A036289[h]):
            end_if:
            A072649[k]:=max(h+1, A072649[k]):
          end_for: // hR
        end_for: // hL
      end_for: // kL
      A228155[k]:=A228155u:
    end_for: // k

A228153 Triangle read by columns: T(n,k) = maximal external path length of AVL trees of height n with k (leaf-) nodes, k>=1, A029837(k)<=n<A072649(k).

Original entry on oeis.org

0, 2, 5, 8, 12, 16, 20, 24, 25, 30, 35, 40, 44, 49, 50, 54, 56, 59, 62, 64, 68, 73, 79, 85, 91, 97, 96, 102, 103, 107, 110, 113, 117, 119, 123, 125, 130, 131, 137, 136, 144, 142, 151, 148, 157, 154, 163, 160, 170, 177, 184, 180, 191, 188, 197, 196, 204, 204
Offset: 1

Views

Author

Herbert Eberle, Aug 13 2013

Keywords

Comments

The external path length of a tree is the sum of the levels of its external nodes (i.e. leaves).

Examples

			In the (two) AVL trees of height 2 the 3 external nodes (leaves) have once depth 1 and twice depth 2:
       o       o
      / \     / \
     o   1   1   o
    / \         / \
   2   2       2   2
so that the sum of depths is 5 for both trees.
Triangle begins:
  0
  . 2
  . . 5 8
  . . . . 12 16 20 24
  . . . .  .  .  . 25 30 35 40 44 49 54 59 64
  . . . .  .  .  .  .  .  .  .  . 50 56 62 68 73 79 85 91 97 102 ...
  . . . .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  . 96 103 ...
		

References

  • D. E. Knuth, Art of Computer Programming, Vol. 3, Sect. 6.2.3 (7) and (8).

Crossrefs

Triangle read by rows gives: A228152.
Row maxima give: n*2^n = A036289(n).
Row minima give: A067331(n-1) for n>0 or A166106(n+2).
Row lengths give: 1+A008466(n).
Number of AVL trees read by rows gives: A143897.
The infimum of all external path lengths of binary trees with k (leaf-) nodes is: A003314(k) for k>0.
Column maxima give: A228155(k).
Column heights give: A217710(k).
Number of AVL trees read by columns gives: A217298.

Programs

  • Mathematica
    maxNods = 100; Clear[T, A029837, A072649, A036289, A228155]; T[0, 1] = 0; A029837[1] = 0; A072649[1] = 1; A228155[1] = 0; For[k = 2, k <= maxNods, k++, A029837[k] = maxNods; A072649[k] = 0; A228155u = 0; For[kL = 1, kL <= Floor[k/2], kL++, For[hL = A029837[kL], hL <= A072649[kL] - 1, hL++, For[hR = Max[hL - 1, A029837[k - kL]], hR <= Min[hL + 1, A072649[k - kL] - 1], hR++, maxDepthSum = k + T[hL, kL] + T[hR, k - kL]; A228155u = Max[maxDepthSum, A228155u]; h = Max[hL, hR] + 1; If[ !IntegerQ[T[h, k]], T[h, k] = maxDepthSum, T[h, k] = Max[maxDepthSum, T[h, k]]]; A029837[k] = Min[h, A029837[k]]; If[ !IntegerQ[A036289[h]], A036289[h] = maxDepthSum, A036289[h] = Max[maxDepthSum, A036289[h]]]; A072649[k] = Max[h + 1, A072649[k]]; ]]]; A228155[k] = A228155u]; k =.; Table[ Select[ Table[T[n, k], {n, A029837[k], A072649[k] - 1}], IntegerQ], {k, 1, maxNods}] // Flatten (* Jean-François Alcover, Aug 19 2013, translated and adapted from Herbert Eberle's MuPAD program *)
  • MuPAD
    maxNods:=100: // max number of leaves (= external nodes)
    // Triangle T for all AVL trees with <= maxNods leaves:
    delete T:
    // table T indexed [h, k] (h=height, k=number of leaves):
    T[0, 1]:=0:
    // A029837 indexed [k], min height of tree with k leaves:
    A029837:=array(1..maxNods): A029837[1]:=0:
    // A072649 indexed [k], 1+max height of AVL tree with k leaves:
    A072649:=array(1..maxNods): A072649[1]:=1:
    // A036289 indexed [h], max depthsum of all height h AVL trees:
    A036289:=array(1..maxNods):
    // A228155 indexed [k], max depthsum of all AVL trees with k leaves:
    A228155:=array(1..maxNods): A228155[1]:=0:
    for k from 2 to maxNods do:
      A029837[k]:=maxNods: // try infinity for the min height
      A072649[k]:=0:
      A228155u:=0:
      // Put together 2 AVL trees:
      for kL from 1 to floor(k/2) do:
        // kL leaves in the left tree
        for hL from A029837[kL] to A072649[kL]-1 do:
          for hR from max(hL-1, A029837[k-kL])
                   to min(hL+1, A072649[k-kL]-1) do:
            // k-kL leaves in the right subtree
            maxDepthSum:=T[hL, kL]+T[hR, k-kL]+k:
            A228155u:=max(maxDepthSum, A228155u):
            h:=max(hL, hR)+1:
            if type(T[h, k]) <> DOM_INT then // T[h, k] uninit
              T[h, k]:=maxDepthSum:
            else
              T[h, k]:=max(maxDepthSum, T[h, k]):
            end_if:
            A029837[k]:=min(h, A029837[k]):
            if type(A036289[h]) <> DOM_INT then
              A036289[h]:=maxDepthSum:
            else
              A036289[h]:=max(maxDepthSum, A036289[h]):
            end_if:
            A072649[k]:=max(h+1, A072649[k]):
          end_for: // hR
        end_for: // hL
      end_for: // kL
      A228155[k]:=A228155u:
    end_for: // k

A228155 Maximal external path length of AVL trees with n (leaf-) nodes.

Original entry on oeis.org

0, 2, 5, 8, 12, 16, 20, 25, 30, 35, 40, 44, 50, 56, 62, 68, 73, 79, 85, 91, 97, 103, 110, 117, 123, 130, 137, 144, 151, 157, 163, 170, 177, 184, 191, 197, 204, 211, 219, 227, 235, 243, 250, 257, 265, 273, 281, 289, 296, 304, 312, 320, 328, 335, 342, 349, 356
Offset: 1

Views

Author

Herbert Eberle, Aug 14 2013

Keywords

Comments

The external path length of a tree is the sum of the levels of its external nodes (i.e. leaves).

Examples

			The (two) AVL trees with 3 (leaf-) nodes have one with depth 1 and two with depth 2:
       o       o
      / \     / \
     o   1   1   o
    / \         / \
   2   2       2   2
so a(3) = 5.
		

References

  • D. E. Knuth, Art of Computer Programming, Vol. 3, Sect. 6.2.3 (7) and (8).

Crossrefs

Column maxima of triangles A228152, A228153.
Row maxima give: n*2^n = A036289(n).
Row minima give: A067331(n-1) for n>0 or A166106(n+2).
Row lengths give: 1+A008466(n).
Column heights give: A217710(k).
Number of AVL trees read by rows gives: A143897.
The infimum of all external path lengths of all binary trees with k (leaf-) nodes is: A003314(k) for k>0.
Number of AVL trees read by columns gives: A217298.

Programs

  • Mathematica
    maxNods = 100; Clear[T, A029837, A072649, A036289, A228155]; T[0, 1] = 0; A029837[1] = 0; A072649[1] = 1; A228155[1] = 0; For[k = 2, k <= maxNods, k++, A029837[k] = maxNods; A072649[k] = 0; A228155u = 0; For[kL = 1, kL <= Floor[k/2], kL++, For[hL = A029837[kL], hL <= A072649[kL] - 1, hL++, For[hR = Max[hL - 1, A029837[k - kL]], hR <= Min[hL + 1, A072649[k - kL] - 1], hR++, maxDepthSum = k + T[hL, kL] + T[hR, k - kL]; A228155u = Max[maxDepthSum, A228155u]; h = Max[hL, hR] + 1; If[ !IntegerQ[T[h, k]], T[h, k] = maxDepthSum, T[h, k] = Max[maxDepthSum, T[h, k]]]; A029837[k] = Min[h, A029837[k]]; If[ !IntegerQ[A036289[h]], A036289[h] = maxDepthSum, A036289[h] = Max[maxDepthSum, A036289[h]]]; A072649[k] = Max[h + 1, A072649[k]]; ]]]; A228155[k] = A228155u]; k =.; Table[A228155[k], {k, 1, maxNods}] (* Jean-François Alcover, Aug 19 2013, translated and adapted from Herbert Eberle's MuPAD program *)
  • MuPAD
    maxNods:=100: // max number of leaves (= external nodes)
    // Triangle T for all AVL trees with <= maxNods leaves:
    delete T:
    // table T indexed [h, k] (h=height, k=number of leaves):
    T[0, 1]:=0:
    // A029837 indexed [k], min height of tree with k leaves:
    A029837:=array(1..maxNods): A029837[1]:=0:
    // A072649 indexed [k], 1+max height of AVL tree with k leaves:
    A072649:=array(1..maxNods): A072649[1]:=1:
    // A036289 indexed [h], max depthsum of all height h AVL trees:
    A036289:=array(1..maxNods):
    // A228155 indexed [k], max depthsum of all AVL trees with k leaves:
    A228155:=array(1..maxNods): A228155[1]:=0:
    for k from 2 to maxNods do:
      A029837[k]:=maxNods: // try infinity for the min height
      A072649[k]:=0:
      A228155u:=0:
      // Put together 2 AVL trees:
      for kL from 1 to floor(k/2) do:
        // kL leaves in the left tree
        for hL from A029837[kL] to A072649[kL]-1 do:
          for hR from max(hL-1, A029837[k-kL])
                   to min(hL+1, A072649[k-kL]-1) do:
            // k-kL leaves in the right subtree
            maxDepthSum:=T[hL, kL]+T[hR, k-kL]+k:
            A228155u:=max(maxDepthSum, A228155u):
            h:=max(hL, hR)+1:
            if type(T[h, k]) <> DOM_INT then // T[h, k] uninit
              T[h, k]:=maxDepthSum:
            else
              T[h, k]:=max(maxDepthSum, T[h, k]):
            end_if:
            A029837[k]:=min(h, A029837[k]):
            if type(A036289[h]) <> DOM_INT then
              A036289[h]:=maxDepthSum:
            else
              A036289[h]:=max(maxDepthSum, A036289[h]):
            end_if:
            A072649[k]:=max(h+1, A072649[k]):
          end_for: // hR
        end_for: // hL
      end_for: // kL
      A228155[k]:=A228155u:
    end_for: // k
Showing 1-10 of 13 results. Next