# How to determine the number of c points in algebraic multi grid

I am trying to write an algebraic multi-grid solver (in c++). At a given level I determine which nodes are c-points and which nodes are f-points (where the total number of c and f points equals the matrix dimension on that level). Therefore I need two arrays: one array to hold the indices of the c-points, and one array to hold the indices of the f-points. The problem is I do not know how many c-points (or f-points) there will be before hand and so I don't know how large to make these arrays. One option is to just make both arrays to have size the same as the number of rows in the matrix that way ensuring no overflow. This is what I am doing right now, but this entails significant extra storage wasted. I could also essentially run my function that determines the c-points and f-points twice, where the first time I just record the final sizes, but this is obviously a lot of extra work. Does anyone know what is the best strategy for dealing with this? There does not seem to be any way of determining the final number of c-points without actually computing them one after another.

In C the command calloc creates an array at runtime and realloc makes a previous array bigger or smaller. In reality you may need a linked list, there's an open source library called Gobject. It'll require further programming skill to use it but may lead to massive memory savings and will allow for a stupidly large number of nodes per layer.