Stephan van Hulst wrote:
D.J. Quavern wrote:Uh, NP-hard? Wiki has a funny definition : "the defining property of a class of problems that are, informally, "at least as hard as the hardest problems in NP"
Let's explain this in another funny way: If aliens come down to earth and hand us a small machine that does nothing else but provide answers to the traveling salesman problem instantaneously, we can build it into our computer processors to make them able to quickly provide an answer to EVERY OTHER NP-problem, even if they seem completely unrelated to the traveling salesman problem. For instance, if you want to decrypt a secret message without knowing the key, you can write a program that states the decryption operation in terms of the traveling salesman problem, and the computer will be able to provide you the decrypted message very fast.
D.J. Quavern wrote:I had a look at the minimal spanning tree: so this is the one we have, but how do you deal with them when there are no weights on the branches?
D.J. Quavern wrote: I also looked at Dijkstra algorithm: how can it find the most optimal route when it can't see the path n+2? I mean what if it choses the cheapest weight (2), but the next-one is extra salty (45)? Maybe it's not the point and it's a very stupid question though.
Paul Clapham wrote:Buckets don't have anything to do with the algorithm. If the Map you're asking about happens to use them, then it will have software to deal with them appropriately. You do not need to know the details of how it works.
Arun Singh Raaj wrote:
If the key is a String instance = "hello". If hash of "hello" is 99162322 so initially when bucket size is 16, Java calculates the index:
(99162322 & 15) = 2 and the entryset gets stored into index 2.
But how does it get the same index for another "hello" when bucket size is 32 or more?
Or my understanding is wrong, it's not mandatory to have the same index for two same instances?
Arun Singh Raaj wrote:So in case I try to store duplicate key, does it firstly calculate the index then check the particular index of bucket or
it firstly compares all the keys of all the buckets with the one you are going to store?
Bart Ret wrote:BTW. Like you said , it doesn't work properly. Still are repeated items.
Lb Ward wrote:Correction: If line 7 read "check(p1, p1->p1.age<5);", then line 7 doesn't compile. I get an error: 'Variable 'p1' is already defined in this scope.' So... I'm still trying to figure out what the parameter on each side of the "->" comes from. I believe it is the object upon which the testing is done, but what determines it's value?
I'm beginning to believe that in the form "check(p1, p->p.age <5);", that p is the parameter passed to the interface containing the test method. But I still can't see how java knows what to pass in as parameter p.