grammar-based code

grammar-based code

Grammar-based codes or Grammar-based compression are compression algorithms based on the idea of constructing a context-free grammar (CFG) for the string to be compressed. Examples include universal lossless data compression algorithms.[1] To compress a data sequence {\displaystyle x=x_{1}\cdots x_{n}}x=x_{1}\cdots x_{n}, a grammar-based code transforms {\displaystyle x}x into a context-free grammar {\displaystyle G}G. The problem of finding a smallest grammar for an input sequence (smallest grammar problem) is known to be NP-hard,[2] so many grammar-transform algorithms are proposed from theoretical and practical viewpoints. Generally, the produced grammar {\displaystyle G}G is further compressed by statistical encoders like arithmetic coding.