Reputation: 147
I need some help trying to make my algorithm more efficient. I'm trying to make my algorithm run faster (run time) than it already does. I'm testing it with lots of data.. My problem is that right now it is too slow.. maybe because of for loops..
Have 2x linked lists which is going to make the same size. Here is some code.
//vertices in graph
private int v;
// Contains edges represented as adjacency lists
private static LinkedList<Integer>[] edges;
private static LinkedList<Integer>[] Relations;
When creating them, i do this in my construcktor.
edges = (LinkedList<Integer>[]) new LinkedList[v];
Relations = (LinkedList<Integer>[]) new LinkedList[v];
for (int i = 0; i < vertices; i++) {
edges[i] = new LinkedList<Integer>();
Relations[i] = new LinkedList<Integer>();
}
If vertices is, lets say 10.. there is no problem.. but what if its 20000+ , then it going to run it 20000+... Is there a way to make this more efficient?
Have read about that iterate is faster than for loop.. is it?
Upvotes: 0
Views: 94
Reputation: 35011
It is not the for loop that's a problem its the sheer number of objects you are creating
Upvotes: 0