construct data structure for binary search