Back to problems

Huffman-Style Binary Encode / Decode

Algorithm · Two Sigma · Hard

Requirements For a supplied string, create two operations: encode(s) — transform the given text into a sequence of bits. decode(bits) — reconstruct the initial text from that bit sequence. The input s is a string. encode(s) returns a string containing only 0 and 1. decode(bits) accepts that bit string and returns the original string. Derive the representation from how often each character occurs: Treat every distinct character as an initial leaf. Construct a binary tree by…

Checking your access…