I have a grid with x-sided field in it. Every field contains a link to it's x surrounding fields. [x is constant]
I have an algorithm which is implemented in this field, (which can probably be optimized):
[java like pseudocode]
public ArrayList getAllFields(ArrayList list) {
list.addToList(this);
for each side {
if ( ! list.contains(neighbour) && constantTimeConditionsAreMet()) {
neighbour.getAllFields(list) //Recursive call
}
}
return list;
}
I'm having trouble finding the time complexity.
ArrayList#contains(Object) runs in linear timeHow do i find the time complexity? My approach is this:
T(n) = O(1) + T(n-1) +
c(nbOfFieldsInArray - n) [The time to check the ever filling ArrayList]
T(n) = O(1) + T(n-1) + c*nbOfFieldsInArray - cn
Does this give me T(n) = T(n-1) + O(n)?