I am trying to make an adjacencylist. The problem is that my implementation cost to much in memory...
I read a file of words, add them to my graph and add the neighbors of the graph
static public void createEdges(){
for(String string : words){ //words is the list of all the ~4 000 words that have been read
ArrayList<String> wordlist = new ArrayList<String>();
// ........................................................
//(irrelevant part where I create a new String "word" from "string")
// .........................................................
if (Contains(word) != null){ //Contains checks if the new String "word" is a part of the file I read.
wordlist.add(word);
}
list.put(string, wordlist); //list is of type: Hashtable<String, ArrayList<String>>; and represents the wordgraph where "string" is the node and "wordlist" is the neighbors of the node
}}
One way I think would save memory is to not create a new ArrayList evere loop, since it will loop ~4 000 times... But then I can't think of any good way to store my adjacent nodes. Is use of this datastructure doomed for my purpose or are there any smarter ways to implement this?