Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

##Not an O(N^2) algorithm##

Not an O(N^2) algorithm

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.

##Not an O(N^2) algorithm##

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.

Not an O(N^2) algorithm

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.

added 166 characters in body
Source Link
JS1
  • 28.8k
  • 3
  • 41
  • 83

##Not an O(N^2) algorithm##

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.

##Not an O(N^2) algorithm##

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

##Not an O(N^2) algorithm##

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

By the way, unless you allow printing ranges of answers, there is no O(N^2) solution to this problem because there can be O(N^3) triplets that need to be printed.

Source Link
JS1
  • 28.8k
  • 3
  • 41
  • 83

##Not an O(N^2) algorithm##

  1. You create a vector that contains every (i,j) pair. This vector contains O(N^2) elements.

  2. For each pair, you loop across the original vector of N elements.

Outer loop = O(N^2)
Inner loop = O(N)

Total = O(N^3)

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /