Usha Pnatha

Greenhorn
+ Follow
since Aug 01, 2008
Merit badge: grant badges
For More
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 Usha Pnatha

Hello Ranchers,

I'm required to implement a hashCode() for String objects. Each String will contain maximum 20 characters.

I went through the implementation in java.lang.String class. It's basically as follows:
s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]

Since there's no perfect hashing method, I believe that there can be alternatives to this way of implementation.

So, if anyone of you found a different implementation of the hashCode() for String objects(which would be more efficient than the provided one), please post you ideas here.

Thanks in advance,
Usha
14 years ago
Thank you very much Campbell Ritchie, for the resource.
It's very useful & I managed to solve my problems.

Thank you.
Usha
14 years ago
Yeah, it's working!!!
Thank you very much for all of you.

Can anyone please help me with replacing { "(", ")", "?" , "!" } ?
If there's any resource to refer, please let me know that also.

Thank you.

Usha
14 years ago
Hello Ranchers,

I am using the String.replaceAll(String arg1,String arg2) method to replace some strings like {, . : ;} in a text with white spaces.
This works fine when I give {, : ;} as arg1.
But when I give a "." for arg1, it replaces the whole string with the string given for arg2.

i.e:
System.out.println("This is a file. this has words. and chars".replaceAll(".", "-")); ====> prints as "-----------------------------------------"
and
System.out.println("This is a file. this has words. and chars".replaceAll(".", " ")); ====> prints with " " (only white spaces of length same as the text)


How to solve this problem?

I want to replace all "." in my text with " "(white spaces).

Can anyone please help me in this regard?

Thanks in advance,
Usha



14 years ago
Thank you very much Campbell Ritchie and Rob Prime,

@ Campbell Ritchie : Yes, I've refereed some of the classes in the src.zip folder. I'll go through the HashMap implementation and try to get the ideas. Thank you very much for answering all my questions immediately. You support it highly appreciated for beginners of Java like me. Thank you.

@Rob Prime: Thank you for sharing that point on hashing. It's useful for me. Thank you.


Thanks & Regards,
Usha
14 years ago
Thank you very much Campbell Ritchie.
The code will definitely help me to understand hashing and implement my program.

Could you please give me some answers to my other question of the earlier post?
Another question: Mainly I will have any array of 16 keys; then each element of that array should contain another array of 32keys. How can I link the element of the first level array and second level array? Is it just a object reference like: nodes1[0]=new Object[32] ? or is there any other way?

Do you think, the liked list I implemented earlier would be useful in the program if I'm using multiple level of hashing to handle all possible no of keys? Can't I use only object arrays to implement the multilevel hashtable?


Thank you very much.

Regards,
Usha
14 years ago
Thank you very much Campbell Ritchie.
I searched in the net and found those books. They are very useful not only for this program but to sharpen my knowledge.

But, I couldn't find a hashing method there. If you don't mind, can you please give me a code example? Since I've to handle upto 10,000 different keys, I think going up to
16->32->64 is enough to fulfill the requirement.


Another question: Mainly I will have any array of 16 keys; then each element of that array should contain another array of 32keys. How can I link the element of the first level array and second level array? Is it just a object reference like: nodes1[0]=new Object[32] ? or is there any other way?

Do you think, the liked list I implemented earlier would be useful in the program if I'm using multiple level of hashing to handle all possible no of keys? Can't I use only object arrays to implement the multilevel hashtable?

Please clarify me as early as possible.

Thank you.

Regards,
Usha
14 years ago
In addition to my earlier post:
There will be at most 10,000 unique keys.
So can any one tell me suitable hashing function which avoids collisions when using two levels of hashing?

Regards,
Usha
14 years ago
Hello Ranchers,

With the idea I got from my previous posts, I managed to create a Hash table by my own and used a Linked list for duplicate entries.

Now, the problem I have is: In my hash table I used a hashing function which will results hashcodes form 0-16.
So, there will be 17 keys. A a value will be stored in the place of its key. The main purpose of my program is to search for values & to get the result, using a method which will take a lesser running time. So, when I search for a string, if I convert it, I will get a key & that key may contains several different strings stored in a liked list.
What is the best way to retrieve the particular word, with minimum running time?
Do I need to use another hash table to store values of a key(using a different hashing function)?
If so, normally how many level's I have to go like this?

The main requirement of my program is to retrieve the stored data with minimum running time.

Please help me in this regard as soon as possible.


Thank you,
Usha
14 years ago
Thank you very much Campbell Ritchie and Parambir Singh.

Yes, I have to implement the data structures by my own. So, I can't use any predefined classes in Java.
The link from Campbell Ritchie was new to me thank you very much for sharing it.

So, I can implement a HashMap and List to solve the problem.

Thank you for clarifying about HashMap & HashTable. It was very useful.

Thanks & Regards,
Usha
14 years ago
Hello Ranchers,

Can any one find me the latest edition of the book for SCDJWS? Author name & Titile.


Regards,
Usha
Thank you very much Campbell Ritchie .
Yes, I have to implement the data structures in my own.

What's the different between HashMap and HashTable? Is there any useful features in Map?
I read something about synchronization issues with hashtable.
Is it correct to implement the Hashtable and for duplicate entries, using a linked list as the value in the hashtable entry?


Thanks & Regards,
Usha
14 years ago
Hello Ranchers,

I am doing a small text file search engine and I have to make a good selection of data structures for this assignment.

Data structures are used for the purpose of storing words from text files & the particular word's location(i.e:path& name of the text file it contains).
So, there will be duplicate keys since the same word can repeat more than once. Also both the key&value will be strings.
I have to do searching also. But for that I have to implement the searching algorithm in my own.

So, I need to select suitable data structures to fulfill the above requirement.
Please note that I have to implement all those data structures using Java (i.e: I can't use the Collections in Java directly)

I am planning to use a HashTable mainly and for duplicate entries a LinkedList.

Can anyone please advice me on this? Is my selection correct or are there any more appropriate selections?

Also, if this topic is not suitable for this forum, please excuse me & direct me to the corrected forums.

Thanks in Advance,
Usha

14 years ago
TO:Campbell Ritchie



public class MyClass
{
public void print()
{
System.out.println("MyClass");
}
}

javac MyClass.java
java myclass
java MyClass


That should show you how it in action!



I tried with this. But I'm getting an java.lang.NoClassDefFoundError.
Can you explain how it happens??

Thanks in advance...
15 years ago