Java, Shifting Elements in an Array

Assuming your array is {10,20,30,40,50,60,70,80,90,100} What your loop does is: Iteration 1: array[1] = array[0]; {10,10,30,40,50,60,70,80,90,100} Iteration 2: array[2] = array[1]; {10,10,10,40,50,60,70,80,90,100} What you should be doing is

Is complexity O(log(n)) equivalent to O(sqrt(n))?

They are not equivalent: sqrt(N) will increase a lot more quickly than log2(N). There is no constant C so that you would have sqrt(N) < C.log(N) for all values of N greater than some minimum value. An easy way to grab this, is that log2(N) will be a value close to the number of (binary) digits of N, while sqrt(N) will be a number that has itself half the … Read more

What is a good Hash Function?

For doing “normal” hash table lookups on basically any kind of data – this one by Paul Hsieh is the best I’ve ever used. http://www.azillionmonkeys.com/qed/hash.html If you care about cryptographically secure or anything else more advanced, then YMMV. If you just want a kick ass general purpose hash function for a hash table lookup, then … Read more

Efficient swapping of elements of an array in Java

Nope. You could have a function to make it more concise each place you use it, but in the end, the work done would be the same (plus the overhead of the function call, until/unless HotSpot moved it inline — to help it with that, make the function static final).

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)