Find a number in sorted multidimentional array with binary search

后端 未结 10 957
深忆病人
深忆病人 2021-01-14 02:12

we got an increasing sorted multidimensional array for example:

int[][] mat = {{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16}};

How can

10条回答
  •  萌比男神i
    2021-01-14 02:54

    If the multidimensional array is sorted, you could divide the binary search algorithm in two parts. First of all, you would perform the binary search to find the array inside the multidimensional one which contains the number you are looking for. And then, you perform the search inside that array.

    Hope that helps.

提交回复
热议问题