Jeanne Boyarsky wrote:The code is hanging because you are reading from System.in. You have a couple choices:
1) Refactor the code to take the command as in put rather than from System.in.
2) In the test call System.setIn() to an alternate stream so the test can create test input. Remember to restore the original System.in in @After.
Winston Gutkowski wrote:
benjamin parker wrote:nodeSize refers to left of sub tree + right of subtree + itself. I need it as for example if i were to find words that lies within a range that includes the starting words and exclude the ending words, with it i could easily minus off the nodesize of 2 points. This would return me the exact words that lies in between and the subtraction removes parts that overlap.
But isn't that a function of node height rather than size? It also strikes me that this is something that would apply to a specific type of query (eg "prefix"), rather than to a normal search.
Again, not knowing much about AVL trees I'm guessing here, but if you ALSO want "suffix" queries, then I suspect you could do it with either:
(a) A depth-first search.
(b) (possibly overkill, but probably very fast) Keep two copies of the tree: one in normal order; the other in reverse order.
Like I say, I'm no expert, but I wonder if you're not overthinking this.
Winston Gutkowski wrote:
benjamin parker wrote:The method I am using to get the total numbers of words is working correctly as I am using a nodeSize method whereby it is the addition of both left and right subtree and itself [left subtree+rightsubtree+1].The difference or number of words in a range is obtained as there are overlap points for both start and end stop words.
Doing it that way will probably yield an O(n) solution, and I doubt that there's any way to make it any less.
My question is: Do you actually need a nodeSize() function at all?
Not being familiar with AVL trees I don't know, but if the only thing you need it for is to find out how many words are in the whole tree, then why not keep that figure externally as a field in your AVLTree class, the way most collections do, and simply update it whenever you add or remove a word?
Campbell Ritchie wrote:Which line does the Exception occur on? What object references appear on that line? Have you printed them all to confirm which of them is null?
Paul Clapham wrote:
benjamin parker wrote:i would like to bruteforce everything and store them inside the arraylist.
What's "everything" and what's "them" and what arraylist is that?
If you're given for example 8 numbers then there are 256 ways to choose a subset of those 8 numbers. Does "them" refer to the 256, or what? Basically you're going to have to produce a better description of your approach than what you did there.