I'm currently trying to map how to make a good algorithm that won't have issues to find the shortest path. The labyrinth consists of an X and Y dimensions as input; However, the labyrinth will generate obstacles within the dimensions and randomly spawned. There is one entrance and at least one exit after finding the shortest path. The way to find the exit and shortest path will be in an order of movements. First it checks if going up is available, then left, then right, and finally down (priority movements: up->left->right->down). The movements must be horizontally and vertically, so diagonal moves are illegal, unfortunately.
My thought was to probably build a backtracking algorithm that will solve this problem; but, there is a catch for this. It says the labyrinth will not be more than a billion square, meaning that it can be a larger X and Y. Thus, the program will timeout and have to allocate more memory to execute with a Gigabyte file. So to reduce this amount of memory, maybe use bitfields to reduce and manipulate bitwise (which I never used it as a data structure).
My weak point is to have a strong foundation of how to approach such a problem that can be devastating to code and how to take care. I was wondering what kind of approach I need to consider too. I'm happy to discuss further and be curious about your approaches. I like to ask a lot of questions just for me to understand efficiently.
O(|V| log |V| + |E|)
. This particular case is even easier b/c the graph is planar and the degree of each node is ≤ 4. My intuition suggests this results in a typical run time proportional to|V| log sqrt |V|
. For acyclic graphs, the SPP is inTheta(|V| + |E|)
, i.e. linear b/c no queue is needed.