Scotty Steven wrote:Hello,
I am looking to write a binary tree in which each node holds both a string and an int value. I want to sort via the string.
Thanks
Scotty Steven wrote:
The integer would strictly be used to record the number of times the string appears.
Thanks
Scotty Steven wrote:
Any suggestions on how to do this, or do you know of code that already exist similar to what I'm looking to do that cam be studied?
Thanks
Chan wrote:
You mean a 'String'? Remember Java is case-sensitive.
Chan wrote:
So that means the String's' can repeat and the tree can hold duplicates. You have not specified how you would handle inserts/updates/deletes of duplicate nodes.
Chan wrote:
Does an equal node traverse the right subtree or does it traverse the left subtree of this node? What is your algorithm ( let us know in plain text ) going to be?
How does a delete operation correct the count value in the affected nodes ( i.e for cases when you have count > 1 ).
.Scotty Steven wrote:
Any suggestions on how to do this, or do you know of code that already exist similar to what I'm looking to do that cam be studied?
Thanks
Chan wrote:
What have you tried? Plus I think we require more details about your problem statement and we need to know your algorithm. Implementation comes much later.
Chan
Scotty Steven wrote:
Chan wrote:
So that means the String's' can repeat and the tree can hold duplicates. You have not specified how you would handle inserts/updates/deletes of duplicate nodes.
No. I guess I wasn't clear enough when I said "The integer would strictly be used to record the number of times the string appears." If a duplicate String appears, instead of inserting the String that already exists, the count integer would advance one. So, the first time the word "programming" appears, it is inserted into the tree along with an integer which would hold the starting value of 1. The next time the word "programming" appears, when the search algorithm finds the duplication, it would trigger the count integer to advance to 2 and would not insert the duplicate into the tree. The compared Strings would be setup to not be case-sensitive.
Scotty Steven wrote:
Chan wrote:
Does an equal node traverse the right subtree or does it traverse the left subtree of this node? What is your algorithm ( let us know in plain text ) going to be?
Let's go with if greater than, go right. If lesser than, go left.
Scotty Steven wrote:
Chan Ag wrote:How does a delete operation correct the count value in the affected nodes ( i.e for cases when you have count > 1 ).
Fair enough. In this project, it will be insert only. This is strictly to keep track of the number of times a String appears in a text file that will be read by the program. No deletions will occur. However, I think a re-balancing of the tree should occur after a couple of insertions.
Scotty Steven wrote:
I haven't coded anything yet. I am trying to figure out how to make this work and looking for a starting point. I know how I'd like it to work, but can not quite figure out how to begin. As such, I decided to request help from people more knowledgeable then myself on the subject. I thought someone could point me towards my goal, or perhaps knew of existing code that I could use as a starting point, but would require reworking it to make it fit.
There are worse crimes than burning books. One of them is not reading them. Ray Bradbury
Steve
No. no, no, don't look there, because I happen to know one page in that link has a little application which counts words in text. It is really long and complicated: about ten lines.Steve Luke wrote: . . . Have you looked at Java's Collections API . . . ? . . .
No, I was mistaken. even if you miss out comments and blank lines, it comes to twelve lines.Earlier, I wrote: . . . about ten lines.
No. no, no, don't look there, because I happen to know one page in that link has a little application which counts words in text. It is really long and complicated: about ten lines.
Earlier, I wrote:
. . . about ten lines.
No, I was mistaken. even if you miss out comments and blank lines, it comes to twelve lines.
Now I know what the application is for, I would suggest you do the counting first and the sorting afterwards.
There are algorithms which people use to try and identify authors' styles.
Not unless you manage to find the little app called Freq or similar on the Map page.Scotty Steven wrote: . . . Got anything more specific? . . .
Oh, it's a thesis? Go for it!!. . . My thesis is to show that a much simpler way exists; that the number of occurrences/some word count will also show the likelihood that a particular word belongs to an author.
Consider Paul's rocket mass heater. |