implemented memoization to speed up computing the sort inforamtion of a KItem