微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

A* 平均时间复杂度

如何解决A* 平均时间复杂度

我正在为我的学士学位论文研究两种算法:Floyd-Warshall 和 A* 算法。在我的工作中比较两种算法时,时间复杂度是一个重要部分。但由于 A* 中的启发式算法,算法的时间复杂度不恒定。我发现的唯一信息是,在最坏的情况下,时间复杂度会呈指数级增长。

在正常实践中,A* 算法的平均和最佳时间复杂度是多少?

解决方法

首先,我建议您将 A* 视为某种具有启发式近似解的 Dijkstra,因此在最坏的情况下,您的解决方案将是 Dijkstra 的时间复杂度(即 O(|V|+|E|) * log|V|) 在原始算法中)所以肯定不是指数的,当然,如果您认为启发式函数不大于实际距离本身)。为了理解起见,当我在同一算法上实现 Dijkstra 和 A* 时,您可以在此处查看我的“放松”函数代码的比较器:

---
//this function is a comparator between the distance of two vertices,it will be used 
for the heap and the Relax function in Dijkstra 
struct minDistance {
    bool operator()(Vertex* a,Vertex * b) const {
        return (a->getDis() > b->getDis());
    }
};

//this function is a comparator between the distance of two vertices but with the 
heurstic function's value added,it will be used in AStar
struct minDistanceProx {
    bool operator()(Vertex* a,Vertex * b) const {
        return ((a->getDis() + a->getDisProx()) > (b->getDis() + b->getDisProx()));
        //notice that the relax function will only change the distance value,//but the heap will count the distance and the heuristic value together so the 
heap is sorted as planned!
    }
};
---

您可以将其视为“从该节点到解决方案的距离至少为 x 远”,这就是为什么可以在从目的地或“空中距离”的转置图上将良好的近似实现为 BFS(如果您考虑)节点作为某种地图。 为了获得最佳时间复杂度,当您的启发式函数是实际距离并且近似值 100% 准确时,就会发生这种情况 - 这将是解决方案的直接途径。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。