Big o 强力解决方案的大O表示法

Big o 强力解决方案的大O表示法,big-o,asymptotic-complexity,Big O,Asymptotic Complexity,我正在处理来自InterviewCake[]的编程问题,这个问题让我困惑 I have an array stock_prices_yesterday where: - The indices are the time, as a number of minutes past trade opening time, which was 9:30am local time. - The values are the price of Apple stock at that time, i

我正在处理来自InterviewCake[]的编程问题,这个问题让我困惑

 I have an array stock_prices_yesterday where:

- The indices are the time, as a number of minutes past trade 
  opening time, which was 9:30am local time.
- The values are the price of Apple stock at that time, in dollars.

For example, the stock cost $500 at 10:30am, 
so stock_prices_yesterday[60] = 500. 
建议的暴力解决方案是:

 The brute force ↴ approach would be to try every pair of times
 (treating the earlier time as the buy time and the later time as the 
 sell time) and see which one is best. There are n2 such combinations,
 so this will take O(n2) time.
我想不出这个溶液是怎样的O(n2)

如果我有一个很小的清单,上面有股票价格,比如说
[21,10,43]
,那么所有可能的组合都是:

(21, 10)
(21, 43)
(10, 43)
(10, 21)
(43, 10)
(43, 21)
这不是n**2组合。。。我相信这真的很简单,但它总是让我感动

这不是n**2组合

大O表示法是最重要的因素,组合的数量(不包括重复项)(例如(10,10))仍然与n2成比例。事实上,没有重复的组合总数为n2-n。在big-O中,只保留最重要的项,所以O(n2)

通常,对的集合将通过

for i in indexes
  for j in indexes
    if i != j then
      process(i, j)
对于每个索引,再次枚举所有索引:索引数乘以索引数:O(n2)

这不是n**2组合

大O表示法是最重要的因素,组合的数量(不包括重复项)(例如(10,10))仍然与n2成比例。事实上,没有重复的组合总数为n2-n。在big-O中,只保留最重要的项,所以O(n2)

通常,对的集合将通过

for i in indexes
  for j in indexes
    if i != j then
      process(i, j)
对于每个索引,再次枚举所有索引:索引数乘以索引数:O(n2)

这不是n**2组合

大O表示法是最重要的因素,组合的数量(不包括重复项)(例如(10,10))仍然与n2成比例。事实上,没有重复的组合总数为n2-n。在big-O中,只保留最重要的项,所以O(n2)

通常,对的集合将通过

for i in indexes
  for j in indexes
    if i != j then
      process(i, j)
对于每个索引,再次枚举所有索引:索引数乘以索引数:O(n2)

这不是n**2组合

大O表示法是最重要的因素,组合的数量(不包括重复项)(例如(10,10))仍然与n2成比例。事实上,没有重复的组合总数为n2-n。在big-O中,只保留最重要的项,所以O(n2)

通常,对的集合将通过

for i in indexes
  for j in indexes
    if i != j then
      process(i, j)
对于每个索引,再次枚举所有索引:索引数乘以索引数:O(n2)