简体   繁体   English

Hill Climbing算法在图中寻找局部最小值/最大值的时间复杂度

[英]Time complexity of Hill Climbing algorithm for finding local min/max in a graph

What is the time complexity (order of algorithm) of an algorithm that finds the local minimum in a graph with n nodes (having each node a maximum of d neighbors)? 什么是在具有n节点的图中找到局部最小值的算法的时间复杂度(算法的顺序)(每个节点最多有d邻居)?

Detail: We have a graph with n nodes. 细节:我们有一个包含n节点的图表。 Each node in the graph has an integer value. 图中的每个节点都有一个整数值。 Each node has maximum of d neighbors. 每个节点最多有d邻居。 We are looking for a node that has the lowest value among its neighbors. 我们正在寻找一个在其邻居中具有最低值的节点。 The graph is represented by an adjacency list. 该图由邻接列表表示。 The algorithm starts by selecting random nodes and, within these nodes, it selects the node with minimum value (let's say node u ). 该算法首先选择随机节点,然后在这些节点中选择具有最小值的节点(比如节点u )。 Starting from node u , the algorithm finds a neighbor v , where value(v) < value(u) . 从节点u开始,算法找到邻居v ,其中value(v) < value(u) Then, it continues with v and repeats the above step. 然后,它继续v并重复上述步骤。 The algorithm terminates when the node does not have any neighbor with a lower value. 当节点没有任何具有较低值的邻居时,算法终止。 What is the time complexity of this algorithm and why? 这个算法的时间复杂度是什么?为什么?

Time complexity is O(n + d), because you can have n nodes, which are connected as this, the number shows the value of node : 时间复杂度为O(n + d),因为您可以有n个节点,这些节点连接成这个,数字显示节点的值:

16-15-14-13-12-11-10-9-8-7-6-5-4-3-2-1

And you can randomly select these, marked by "!" 你可以随机选择这些,标有“!”

!-!-!-13-12-11-10-9-8-7-6-5-4-3-2-1

So you select the node with value 14 and by described alghoritm, you will check all the nodes and all the edges until you reach the node with value 1. 因此,您选择值为14的节点,并通过描述alghoritm,您将检查所有节点和所有边缘,直到到达值为1的节点。

The worst complexity for task : "find one element" is O(N), where "N" is the length of your input and length of your input is actually N=G(n,d)=n+d . 任务的最复杂性:“找到一个元素”是O(N),其中“N”是输入的长度,输入的长度实际上是N=G(n,d)=n+d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM