What is the difference between an on-line and off-line algorithm?

后端 未结 7 520
-上瘾入骨i
-上瘾入骨i 2021-01-31 08:08

These terms were used in my data structures textbook, but the explanation was very terse and unclear. I think it has something to do with how much knowledge the algorithm has a

7条回答
  •  广开言路
    2021-01-31 08:50

    We can differentiate offline and online algorithms based on the availability of the inputs prior to the processing of the algorithm.

    Offline Algorithm: All input information are available to the algorithm and processed simultaneously by the algorithm. With the complete set of input information the algorithm finds a way to efficiently process the inputs and obtain an optimal solution.

    Online Algorithm: Inputs come on the fly i.e. all input information are not available to the algorithm simultaneously rather part by part as a sequence or over the time. Upon the availability of an input, the algorithm has to take immediate decision without any knowledge of future input information. In this process, the algorithm produces a sequence of decisions that will have an impact on the final quality of its overall performance.

    Eg: Routing in Communication network:

    Data Packets from different sources come to the nearest router. More than one communication links are connected to the router. When a new data packet arrive to the router, then the router has to decide immediately to which link the data packet is to be sent. (Assume all links are routed to the destination, all links bandwidth are same, all links are the part of the shortest path to the destination). Here, the objective is to assign each incoming data packet to one of the link without knowing the future data packets in such a way that the load of each link will be balanced. No links should be overloaded. This is a load balancing problem.

    Here, the scheduler implemented in the router has no idea about the future data packets, but it has to take scheduling decision for each incoming data packets. In the contrast a offline scheduler has full knowledge about all incoming data packets, then it efficiently assign the data packets to different links and can optimally balance the load among different links.

提交回复
热议问题