Minimize memory usage in the first search

In my next code, I am viewing the graph through breadth first search. The code builds a graph as it moves. This is a very large graph with a fan of 12. Because of this, anytime the depth breadth first searchincreases, I want to destroy the layer above it, trying to minimize memory usage. How can I create an algorithm for this?

string Node::bfs(Node * rootNode) {
QQueue<Cube *> q;
q.enqueue(rootNode);

while (!(q.empty())) {
    Node * currNode = q.dequeue();
    currNode->constructChildren();
    foreach (Node * child, currNode->getListOfChildren()) {
        q.enqueue(child);
    }
    if (currNode->isGoalNode()) {
        return currNode->path;
    }
}
+5
source share
2 answers

, BFS, , . (, K n K ^ n , , n, Theta (K ^ n)).

, . , , "" , DFS, .

"" , - , ( , , ). .

, DFS .

( , ) BFS, O (K ^ n) , n - . DFS O (n).

DFS , DFS, , BFS, "" BFS.

+3

. . , .

+1

All Articles