Tag Info

New answers tagged

0

Here I will assume that the weight is an integer with a (relatively) short range (i.e. [0, N)). The reason being that if you have way too many different weights, then each weight will have so little entries that it is not even worth sorting those entries alphanumerically... I would hash the dictionary by weight and then simply use some tree structure to ...


2

Most simple solution: for i = 1 to sqrt(n) if i divides n put i and n/i into your result set (make sure if i=n/i you put it only once there) Complexity: O(sqrt(n)) (as long as you do not work with big numbers and can assume all basic arithmetic operations like test for divisibility as O(1). A more sophisticated algorithm ist described here. ...


1

The mathematical function that is like that is log n. So the big O notation would be O(log n).



Top 50 recent answers are included