How big can your Adjacency matrix be?

Hello, I am trying to create a word ladder game, and I am declaring an adjacency matrix to link all of the words that have only one letter of difference. There is 5526 4 letter words, so when I declare my adjacency matrix, my program overflows and cannot run. This is how I declare it:

node adjMatrix[5526][5526];

I also tried a regular bool adjMatrix [5526][5526]; in case my node code was corrupted or something.


What can I do to avoid the compilation error? Or what am I doing wrong?

Thanks!!!
Last edited on
If you are doing:

1
2
3
4
int main()
{
    bool adjMatrix [5526][5526]; // this memory is going to be on the stack
}


then you are making that object on the stack, and the stack is only so large. I think on most implementations/default settings it's only 1 megabyte? Your array there is ~30 mb.

It can to be allocated on the heap, using "new" or you could make it static. Both of which are alternatives for the stack.
Last edited on
Topic archived. No new replies allowed.