sydney.lambda
2020-1-21 20:55:50

I did a google search for some binary tree representations in Scheme, and most seemed to use #f to represent the base case, or that you are at the leaf of a node. Is it bad to do something like this instead? (struct tree (val left right) #:transparent) (struct leaf (char freq) #:transparent) and have the leaves which will be the left/right of some trees as leaf structs rather than having leaves with #f and #f as left/right? I’m using this for Huffman trees, if that helps. Thanks :)


soegaard2
2020-1-21 21:23:18

Is a leaf stored in val or in left, right ?


sydney.lambda
2020-1-21 21:24:56

left, right


soegaard2
2020-1-21 21:26:36

So what goes in val?


sydney.lambda
2020-1-21 21:27:18

I don’t think val is actually needed in the trees. I believe you encode and decode purely by counting the branch movements left/right to the desired letter. I just put it there to match the diagrams I was using to see if it matched up alright. The val is the combined weight of the child nodes.


soegaard2
2020-1-21 21:27:56

It’s a fine approach.


sydney.lambda
2020-1-21 21:32:25

Great! Thanks.