Benefits of a Lookup TableThis tip submitted by Ali Nawkhas Murad on 2012-02-04 06:36:42. It has been viewed 15356 times.Rating of 5.7 with 58 votes The lookup table becomes very important tool when the time is more critical than memory space in your system. In this case a function with tedious and long calculations, consuming too much time can be replaced by a lookup table. A lookup table takes an argument as an index to table to get its corresponding value. For example the factorial function can be substituted by lookup table as shown below: ULONG64 fac(int n) { ULONG64 val[21] = {1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200, 1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000,2432902008176640000}; return val[n]; } More tips Help your fellow programmers! Add a tip! |