I knew the time complexity of Topological ordering is O(V+E) since we don't need to do sorting during the selection of node whose incoming degree is 0. But what about the least topological ordering that make sure every node to delete is always the least one of the List of 0 incoming degree nodes. Like the picture show below, "1 2 4 3 5" and "2 1 4 3 5" are both topological ordering but the least one is "1 2 4 3 5".
enter image description here

我将0个传入的度 node 存储在一个优先级队列(min—Heap)中,每次都删除它的顶部.因此,总共有V个 node 要删除,并且每个删除都需要优先级队列O(log V)来调整,以保持其自身为min—Heap.总 node 删除似乎是O(VlogV) while the basic topological ordering is O(V+E). What is the exactly time complexity of The least topological ordering? Is it O(VlogV + E)?希望你能帮我!

推荐答案

是的,这个问题的最佳复杂度是O(V*log(V) + E).因此,你的方法是正确的.恭喜您:)

从实际的Angular 来看,平均时间将更接近O(V + E),因为绝大多数测试用例不需要在任何给定点的优先级队列中超过sqrt(V)个 node .

然而,如果你真的想在这个问题上获得最佳性能(实际上,也就是说,因为复杂性将保持不变),你可以使用斐波那契堆来实现它.这通常会给你一个摊销的 node 删除O(1),但它带来了它的开销,而且更难实现.尽管如此,这是一个超出本问题范围的高级概念,我将在下面链接它. https://en.wikipedia.org/wiki/Fibonacci_heap#:~:text=In%20computer%20science%2C%20a%20Fibonacci,binary%20heap%20and%20binomial%20heap.

希望这对你有帮助!

Java相关问答推荐

Spring bootstrap @ Asmat注释与@ Routed

是否有一种格式模式,可以在除0之外的数字前面有正负符号?

Springdoc Whitelabel Error Page with Spring V3

inteliJ中是否有一个功能可以自动在块注释中的/*后面添加一个空格?''

从技术上讲,OPC UA客户端是否可以通过转发代理将请求通过 tunel 发送到OPC UA服务器?

Java模式匹配记录

如何以干净的方式访问深度嵌套的对象S属性?

使用Testcontainers与OpenLiberty Server进行集成测试会抛出SocketException

在Java Swing Paint应用程序中捕获快速鼠标移动时遇到困难

Spring Boot Maven包

Com.example.service.QuestionService中的构造函数的参数0需要找不到的类型为';com.example.Dao.QuestionDao;的Bean

%This内置函数示例

将ByteBuffer异步写入InputStream或Channel或类似对象

将关闭拍卖的TimerService

错误:未找到扩展元素在JBossEAP 7.2中安装FUSE时出错

使用迭代器遍历HashMap不会因IF条件而停止

如何在Maven Central上部署?

将BlockingQueue+守护程序线程替换为执行器

模拟JUnit未检测到返回字符串的方法的任何声纳覆盖

如果c不为null,Arrays.sort(T[]a,Comparator<;?super T>;c)是否会引发ClassCastException?