Smatchcube's website ๐ŸŒ


Exercise 2.68

Here is my encode-symbol procedure to encode a symbol.

We can test the procedure to see if we get the correct encoded message:

We can optimize the encode-symbol procedure by checking if the symbol is in the global set of symbols then we only need to check the left branch (if the symbol is not in the left branch it means itโ€™s in the right branch). Here is my optimization:

In most cases this procedure requires less steps.