benjamin parker

Ranch Hand
+ Follow
since Feb 18, 2014
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by benjamin parker

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.



what do you mean by 1)
and how do you restore for 2)

sorry for the questions, i kinda fixed my problem by shifting the run() method to the main instead of leaving it in the constructor
4 years ago
i'm learning how to use junit but have no idea why my test does not work. it seems to not run the test and just shows the default

Welcome to TextBuddy. testfile.txt is ready for use
command:


4 years ago
I need some help in this. example my program is reading a text file with the input below. Is there a way such that upon reaching an empty line, it will call itself again or clear any memory it has used earlier and keep going on till eof.

create zat 2
create xat 1
create yat 2

create aat 2
create xat 2
create uat 1

create zat 5
create 8at 4
create qat 6
4 years ago
i don't think it is due to writing to file that is taking a long time. probably the downloading part?
4 years ago
I have a code below that is reading large image size and writing them to file however the process is too slow. how can i refine this code in such a way that it will work faster?

4 years ago
Actually I think all I need to do now is maybe insert the nozesize function in the right place such that it will recompute after every insertion and rotation. Cant seem to figure out how to get it right
4 years ago

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



Height of a node in a balancing binary search tree has a different meaning and is used to compute balance factor which is later used to balance the whole tree such that it will be logn for searching. It does not work the same as a normal height.

For a) a depth first search, do you mean to transverse the whole structure once?

b) i needed to maintain a balanced binary search tree, so keeping 2 trees of different order is not possible.
4 years ago

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?

Winston



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.
4 years ago
Currently I have managed to get all 4 cases of rotation code right. My problem now is to get words that are in a range defined by the system. It is inclusive of start and exclusive of end stop words provided by the system.

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.

What I am using to update for all nodes sizes in an AVL tree is to implement nodeSize method in an inorder method. This works fine as i have checked earlier for small range details. The only issue now I encounter how to make it more time efficient when there are over 10,000 nodes in the tree and over 5000 queries for it.

4 years ago

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?


i think i have solved this, i need help in resolving this now http://www.coderanch.com/t/638834/java/java/Recursion
4 years ago
I have written rotation for all 4 cases of an AVL binary search tree which are left,right,left right and right left. Have an issue now which is after rotation function is called, it is unable to save itself once it finishes. And thus all rotation done is invalid. One example would be the insertion of 1,2,3. In-order transversal is supposed to show 1 2 3 but for my case it just breaks and shows 1 and the other values such as the balance (-2) height (2) Rank (3). i went back to add a print out for rotate left and realised the rotation was working fine but just can't figure out why it doesn't maintain in that state upon exiting the function .would appreciate if anyone could guide me for this


4 years ago
I am trying to write a self balancing binary search tree using AVL.It will do a self balance check after every insertion. Currently i am facing null pointer exception after the third insertion. could anyone point me where am i making a mistake as i can't seem to figure it out

4 years ago

Josh Borg wrote:I didn't understood what creator of topic wants.


to find the subset sum that is closest or equal to my original sum
5 years ago
i need help in the recursion part. i am only able to go 1 direction

5 years ago

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.


the arraylist contains the result and the total sum.

result meaning the list of numbers that are calculated into the total sum.
5 years ago