but i recently read an article that was suggesting that String str = new String("Cat"); creates either one string object, if "Cat" is already in the string pool, or 2 string objects if "Cat" is not in the string pool. So what is actually the correct answer? haha. I am inclined to believe that Paul is right although I can't think of a way to test this.
If you create a new String object like this: String badIdea = new String("Don't do this") then yes, a new String object is created. But no, doing that doesn't affect the string pool at all.
Paul, are you trying to say that string objects that are created with string concatenation do not go into the string pool? If yes then it makes sense, since a StringBuilder is used, but if we just had: String answer = "Yes, but "; then it would go into the string pool, wouldn't it?
If you create a new String object for example like this: String answer = "Yes, but " + idea then the resulting String object doesn't go into the String pool.
Piet Souris wrote:So you are still planning to go the brute force way?
I have some tips that may help ease the coding a little:
What I would do first is to try to reduce the size of the graph a little. Since the relation 'connected' is an equivalence relation, introducing a partition of the graph (into the maximal connected subgraphs), you can do the brute force on these (hopefully) reduced graphs (if the graph is connected, then this would fail, of course).
Also, I stated it before, if the maximal outdegree is 4, then you need at least 34 / 5 = 7 vertices, so there would be no need to investigate smaller subsets.
Lastly: I agree with Mike that using the Longs is a handy way. If you have all the Longs from 1 to 2^34 - 1, then you can create a Map<bitcount, List<Long> easily using the bitCount() method of a Long. To find which bits are set, I would turn my Long into a BitSet and use the method stream().