UPDATE: rename some variables.
NEW: created function representing Optimal algorithm. Right now it only creates table with proper dimensions