2D阵列上的二进制搜索

Vin*_*C M 0 java arrays algorithm binary-search

我有一个完全排序的2D数组.下面的数组是示例

    1  2  3  
    5  6  7  
    9 10 11 
Run Code Online (Sandbox Code Playgroud)

    1  2  3  4  5
    6  7  8  9  10
Run Code Online (Sandbox Code Playgroud)

我想在这些数组上使用二进制搜索.我们rows是行数和cols被列数

最初start = 0end = rows * cols -1

在上面的3 X 3阵列中,中点可以是4 [9个元素].现在我如何找到具有中点的相应行和列?那有什么标准配方吗?

izo*_*ica 6

公式非常简单:

row = number/cols_per_row;
col = number%cols_per_row;
Run Code Online (Sandbox Code Playgroud)