Zulip Chat Archive

Stream: Is there code for X?

Topic: Binary trees?


Thomas Murrills (Jul 15 2024 at 23:31):

Tree is a binary tree with data stored at non-leaf nodes. Is there one with data stored at leaf nodes?

(This is very easy to write myself, but I'd rather use existing types with nice definitions on them if they exist! And I feel it must, for something so common, right?)

Thomas Murrills (Jul 15 2024 at 23:38):

(I'm also wondering about one with a value on the nodes and another type of value on the leaves.)

Joachim Breitner (Jul 16 2024 at 08:28):

Probably precisely because there are a fair number of variants it’s maybe unavoidable that you’ll sometimes have to define your own one.

Thomas Murrills (Jul 16 2024 at 17:56):

Are there a fair number of variants of binary trees? Arguably there's just three: there's "tree with data at nodes and leaves", and the other two are degenerate cases of that.

I mean, I don't mind defining my own! :) But I wonder if this is something that should exist in e.g. Batteries. (I'm quite busy right now, but at some point I'll have the chance to contribute things...! :) )

Joachim Breitner (Jul 16 2024 at 18:10):

Don't computer scientists count 1, 2, many? :-)

Joachim Breitner (Jul 16 2024 at 18:11):

(or was it 0, 1, many? I'm prone to off-by-one errors)


Last updated: May 02 2025 at 03:31 UTC