Ok , will try Priyadarsini , building the dictionary (code table ) and translation are important . It is a 2-step process, assigning of code number (processed code) and then a unique code .
The code table entries are the sequence in the original stream. So A(0) and B(1) next is AB (2) , 3 so on based on parsing of the original stream .
So , if you look at the pattern : ABAABABA
(A)(B)AABABA
(AB)(AA)(BA)(BA)
(ABA)(ABA)BA
Assign values the sequencing(code) is for proper decoding and fixing the number of bits for storage or transmission etc ...