由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问个面试题目
相关主题
Check if the sum of two integers in an integer array eqauls to the given number encode high cardinality categorical features
[转载] CS Algorithm Interview question求助:关于2个python的题目
关于在rotated sorted array中查找的问题这个同学很神
Re: amazon onsite interview question (转载)How to read binary(data) file generated by Fortran in C/C++ (转载)
一FG家常见题 (转载)讨论几个面试题
size不固定的struct怎么定义呀?If using C++, please avoid the use of STL for these questio (转载)
[合集] 这个问题怎么做好?(word sqaure)An interview question. Thanks.
问两个算法题, 没什么头绪a probability interview question.
相关话题的讨论汇总
话题: array话题: 2d话题: binary话题: search话题: move
进入Programming版参与讨论
1 (共1页)
s*******s
发帖数: 27
1
Binary Search on 2D Array
How do you apply Binary Search on 2D array supposed you have 2D array with
integers sorted both horizontally and vertically. If you find any occurrence
of the value you are looking for you return true else false. What is the
complexity?
For example the 2D array could look like the following
1 4 5 6
2 5 7 9
3 8 10 11
6 9 12 20
h*******e
发帖数: 225
2
This is a classic problem. Binary search doesn't really help you in terms of
comlexity. Finding an element in the nxn sorted matrix is Theta(n) using
the diagonal method.

occurrence

【在 s*******s 的大作中提到】
: Binary Search on 2D Array
: How do you apply Binary Search on 2D array supposed you have 2D array with
: integers sorted both horizontally and vertically. If you find any occurrence
: of the value you are looking for you return true else false. What is the
: complexity?
: For example the 2D array could look like the following
: 1 4 5 6
: 2 5 7 9
: 3 8 10 11
: 6 9 12 20

s*******s
发帖数: 27
3
Could you please give an example of the diagonal method? For example, how to find 6 in the array? Thanks.

of

【在 h*******e 的大作中提到】
: This is a classic problem. Binary search doesn't really help you in terms of
: comlexity. Finding an element in the nxn sorted matrix is Theta(n) using
: the diagonal method.
:
: occurrence

h********g
发帖数: 116
4
start from bottom left corner, let the value be v,
if xv, move left

【在 s*******s 的大作中提到】
: Could you please give an example of the diagonal method? For example, how to find 6 in the array? Thanks.
:
: of

c*****t
发帖数: 1879
5

^^^^
guess it is typo, should be right

【在 h********g 的大作中提到】
: start from bottom left corner, let the value be v,
: if xv, move left

s*******s
发帖数: 27
6
Let me formalize it a bit.
2D array: A[0..n-1, 0..n-1]
Target value: v
Start from bottom left corner. Only movements of up and right are allowed.
Let the array value of current position be a.
do the following:
if a>v, move up;
if a until find v or hitting the right or top side of the array.
Is it the same to start from top right corner and do the following movement?
if a>v, move left;
if a until find v or hit the bottom or left side of the array.

【在 h********g 的大作中提到】
: start from bottom left corner, let the value be v,
: if xv, move left

1 (共1页)
进入Programming版参与讨论
相关主题
a probability interview question.一FG家常见题 (转载)
这个怎么allocate memory?size不固定的struct怎么定义呀?
convert sorted array to binary search tree, 非递归怎么解?[合集] 这个问题怎么做好?(word sqaure)
请帮我看看这个java method? 一直不正常运行问两个算法题, 没什么头绪
Check if the sum of two integers in an integer array eqauls to the given number encode high cardinality categorical features
[转载] CS Algorithm Interview question求助:关于2个python的题目
关于在rotated sorted array中查找的问题这个同学很神
Re: amazon onsite interview question (转载)How to read binary(data) file generated by Fortran in C/C++ (转载)
相关话题的讨论汇总
话题: array话题: 2d话题: binary话题: search话题: move