Why is the complexity of A* exponential in memory?

前端 未结 3 1370
无人共我
无人共我 2021-02-02 12:43

Wikipedia says on A* complexity the following (link here):

More problematic than its time complexity is A*’s memory usage. In the worst case, it must

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-02 13:24

    I am not an expert, but I studied the Wikipedia article for a while and my explanation would be this one (hope i have understood it well :)

    Say, we have a 4x4 matrix of nodes.
    A,B,C,D are the directions we can take at a given time (North,South,East,West)
    The A* algorithm starts searching.

    A
    Queue: B,C,D
    AA
    Queue: B,C,D,AB,AC,AD
    AAA-->Goal
    Queue: B,C,D,AB,AC,AD,AAB,AAC,AAD
    The goal is reached but there are still other possibilities to consider.

    D
    Queue: B,C,AB,AC,AD,AAB,AAC,AAD
    DC
    Queue: B,C,AB,AC,AD,AAB,AAC,AAD,DA,DB,DD
    DCA
    Queue: B,C,AB,AC,AD,AAB,AAC,AAD,DA,DB,DD,DCB,DCC,DCD
    DCAB-->Goal
    Queue: B,C,AB,AC,AD,AAB,AAC,AAD,DA,DB,DD,DCB,DCC,DCD,DCAA,DCAC,DCAD
    Etc etc

    As you can see, for every step taken, three more nodes are added to the queue.
    Since A* follows only acyclic paths [1], the maximum number of steps per route is 15.
    The max number of possible routes in this case is 3^15, or directions^nodes.
    Since every route has 15 steps,the worst case steps taken is 15*3^15.
    In the absolute worst case, every step ever taken is "wrong".
    In that case 3*15*3^15 nodes are in the queue before finding the answer.
    So the worst case amount of nodes that needs to be kept in memory is a constant, to the power of the number of nodes available. In other words the memory use is exponential to the amount of nodes.

    [1] http://www.autonlab.org/tutorials/astar08.pdf, slide 15

提交回复
热议问题