17.4 variant 2: 3-sum problem

#1

[EPIJ 10/17 version]

Can the solution to 17.4 variant 2 perform better than O(k^(k-1)) time complexity (where k is the number of elements to sum)? Thanks!

0 Likes

#2

Yes, I think you can easily solve this problem by O(k^ceil(k / 2)).

0 Likes

#3

@tsunghsienlee
I have an idea that I think would achieve O(n^ceil(k/2)).
But you wrote O(k^ceil(k/2)), which has k as the base. Whereas I have n as the base.
Any chance you actually meant O(n^ceil(k/2)), not O(k^ceil(k/2))?

0 Likes

#4

Sorry, it is a typo, definitely O(n^ceil(k/2)) as I was thinking. I was confused by your writing. You wrote O(k^ceil(k/2)).

0 Likes

#5

Yes, you’re right. Thanks!

0 Likes

#6

Can you enlighten the idea please? I am trying to find the solution of this variant.

0 Likes