English 中文(简体)
• 如何在矩阵中以单一模式浏览器和栏目找到最大值
原标题:How to find max in matrix with unimodal rows and columns
  • 时间:2024-02-23 14:17:34
  •  标签:
  • algorithm

假设我们有两种积极的愤怒论点,产生浮动结果。 在确定其中一个论点和增加另一个论点时,由此产生的价值清单是单一模式,然后在下降(可能重复高峰时期的某些结果)。

是否比以一个论点和二元搜索来寻找最高峰结果时使用第二个论点而确定最大程度的更有效方法? 如果是,如何?

问题回答

我非常怀疑存在有效的算法,因为情况类似:

1 2 3 2 1
2 6 4 3 2
3 4 5 4 3
2 3 4 7 2
1 2 3 2 1

每一行和一栏都是单一模式,但当地最大程度6不是全球最大。 在一个较大的矩阵中,可能会出现多个地方高峰。

There is some information to be gleaned from finding a local maximum, though. If the local maximum is not the global maximum, then the global maximum cannot be elsewhere in the row or column of the local maximum. This effectively splits the matrix into four sub-matrices, on which you could run a recursive algorithm.
Additionally, if you walk along the row and column of a local maximum, and look at the values at each side, you need to find an uphill neighbour in order for the global maximum to potentially be in that quadrant. So you may be able to discard some of the quadrants.

但是,在最坏的情况下,我担心你会重新审视大多数价值观。 我不认为任何东西比对所有各行或所有栏目进行双双双双双双双双双轨搜查更为有效。


决 定

If you had a very efficient algorithm to find the peak, that had to look at only a small number of values, you would not be sure whether the result was the global maximum, or just a local maximum. So you d have to run the algorithm again on the data that you hadn t checked yet. In an NxM matrix, you could have up to N or M (whichever is smaller) local maximums. In order for this to be more efficient than a version of binary search on every row or column (whichever there are fewer of) your peak-finding algorithm would have to be more efficient that O(LogN) or O(LogM).
If you traverse the matrix in any other way than per row or column, you don t know anything about how the values are ordered. If you traverse the matrix by row or column, you know your search space is unimodal, and you can at least leverage that to make your search more efficient.
That means that a form of binary search over the rows or columns (whichever there are fewer of) is the most efficient way to find the global maximum.





相关问题
How to add/merge several Big O s into one

If I have an algorithm which is comprised of (let s say) three sub-algorithms, all with different O() characteristics, e.g.: algorithm A: O(n) algorithm B: O(log(n)) algorithm C: O(n log(n)) How do ...

Grokking Timsort

There s a (relatively) new sort on the block called Timsort. It s been used as Python s list.sort, and is now going to be the new Array.sort in Java 7. There s some documentation and a tiny Wikipedia ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Enumerating All Minimal Directed Cycles Of A Directed Graph

I have a directed graph and my problem is to enumerate all the minimal (cycles that cannot be constructed as the union of other cycles) directed cycles of this graph. This is different from what the ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签