Skip to main content
edited tags
Link
200_success
  • 144.2k
  • 22
  • 188
  • 473
deleted 4 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

A partition algorithm for positive integers

So, for example let's have the array {2, 80, 50, 42, 1, 1, 1, 2}.:

{2, 80, 50, 42, 1, 1, 1, 2}

The best partitioning according to the problem is { {2, 80}, {50}, {42, 1, 1, 1, 2} },:

{ {2, 80}, {50}, {42, 1, 1, 1, 2} }

so the output of the program in this case would be 82.

I have already thought of a \$O(n^2)\$ algorithm, but isn't there any better ( ee.g. \$O(n)\$ or \$O(n\log n)\$  ) algorithm?

My \$O(n^2)\$ algorithm is (it is in C++):

A partition algorithm

So, for example let's have the array {2, 80, 50, 42, 1, 1, 1, 2}. The best partitioning according to the problem is { {2, 80}, {50}, {42, 1, 1, 1, 2} }, so the output of the program in this case would be 82.

I have already thought of a \$O(n^2)\$ algorithm, but isn't there any better ( e.g. \$O(n)\$ or \$O(n\log n)\$  ) algorithm?

My \$O(n^2)\$ algorithm is (it is in C++):

A partition algorithm for positive integers

So, for example let's have the array:

{2, 80, 50, 42, 1, 1, 1, 2}

The best partitioning according to the problem is:

{ {2, 80}, {50}, {42, 1, 1, 1, 2} }

so the output of the program in this case would be 82.

I have already thought of a \$O(n^2)\$ algorithm, but isn't there any better (e.g. \$O(n)\$ or \$O(n\log n)\$) algorithm?

My \$O(n^2)\$ algorithm:

edited tags
Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144
TeX formatting, C++ tag.
Source Link
ferada
  • 11.1k
  • 25
  • 63
Loading
language tag, still needs version tag
Link
Pimgd
  • 22.3k
  • 5
  • 66
  • 144
Loading
Source Link
user65079
user65079
Loading