双端队列的应用?

双端队列的应用?

老师好,请问这节课讲的双端队列,在两端进行add和remove操作,这个数据结构平时在哪些典型场景中得以应用呢?

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

虽然在算法竞赛中可以看到很多应用双端队列的问题,但在这里我还是想举一个更实际的例子。


整体,所有的队列数据结构的经典应用都是“调度算法”(不管是线性的队列,还是优先队列)。双端队列的一个典型应用是 work stealing algorithm,中文叫“工作窃取算法”。如果你感兴趣可以搜索学习一下。贴一段英文 wiki 上的对这个算法的简单介绍:


Work Stealing Algorithm implements task scheduling for several processors. A separate deque with threads to be executed is maintained for each processor. To execute the next thread, the processor gets the first element from the deque (using the "remove first element" deque operation). If the current thread forks, it is put back to the front of the deque ("insert element at front") and a new thread is executed. When one of the processors finishes execution of its own threads (i.e. its deque is empty), it can "steal" a thread from another processor: it gets the last element from the deque of another processor ("remove last element") and executes it. The work stealing algorithm is used by Intel's Threading Building Blocks (TBB) library for parallel programming.


继续加油!:)

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
算法与数据结构
  • 参与学习       2594    人
  • 解答问题       1091    个

慕课网算法名师Liuyubobobo,5年集大成之作 从0到工作5年,算法与数据结构系统解决方案

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师