双端队列的应用?
老师好,请问这节课讲的双端队列,在两端进行add和remove操作,这个数据结构平时在哪些典型场景中得以应用呢?
正在回答
虽然在算法竞赛中可以看到很多应用双端队列的问题,但在这里我还是想举一个更实际的例子。
整体,所有的队列数据结构的经典应用都是“调度算法”(不管是线性的队列,还是优先队列)。双端队列的一个典型应用是 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 星