Complexity of enum.values()

The array returned by
Colour.values() always contains the
same elements, but values() creates a
new array every time it's called (so it's
O(n) where n is the number of enum values). And
you never modify that array. So calling the method
every time you need it is a waste of time. And
storing an array in every instance of your
DataStructure class is a waste of time and memory.
I would simply call the method once and cache that
array in a constant:

The inner loop is O(N^2) for prime numbers but fast for non-primes
(worst case O(N^1/2) because you only have to search up to sqrt(N)).
The number of prime numbers, however, is small compared to the number
of non-primes. An approximation of the number of primes to up X is:
X / log(X), as found in this reference link.
So throwing out the non-primes as inconsequential, there are N /
log(N) prime

When determining complexities, we don't include constants or
coefficients. Instead of O(2N + 2), it should be O(n). We only care
about numbers if they're exponential, i.e. 2^n or n^2, log2(n), etc.
Putting that aside, are you sure this is O(n)? O(n) would mean that it
runs n times, but it looks like j is going to catch up to n before n
times. See what I'm saying?
EDIT: Ok, here's what's going o

SPARQL itself is PSPACE-complete. You can probably only come up with
the best case complexity for any given query. The real-world
complexity will depend on the implementation of the database to some
degree.

The implementation of heapsort that you've described above sure
doesn't look like it works in constant space for precisely the reason
that you're worried about.
However, that doesn't mean that it's not possible to implement
heapsort in O(1) auxiliary space. Typically, an implementation of
heapsort would reorder the elements in the array to implicitly store a
binary max-heap. One nifty detail abou

first, you have convince yourself, the problem is bounded by n and the
growth of s.
let see how fast s grows. every iteration, the current value of i will
be added and i itself will add 1. that is, in the j-th iteration,
i==j.
so, given any iteration, the current value of s is summing up from 1
to current i, which is roughly i^2, which will be compared to n.
therefore, the number of iterations,