Ebook Algorithms: Part 2

(BQ) Part 2 book "Algorithms" has contents: Dynamic programming, linear programming and reductions, NP-complete problems, coping with NP-completeness, quantum algorithms, approximation algorithms, intelligent exhaustive search,.and other contents. | P1: OSO/OVY das23402 Ch06 P2: OSO/OVY QC: OSO/OVY T1: OSO GTBL020-Dasgupta-v10 Chapter 6 Dynamic programming In the preceding chapters we have seen some elegant design principles—such as divide-and-conquer, graph exploration, and greedy choice—that yield definitive algorithms for a variety of important computational tasks. The drawback of these tools is that they can only be used on very specific types of problems. We now turn to the two sledgehammers of the algorithms craft, dynamic programming and linear programming, techniques of very broad applicability that can be invoked when more specialized methods fail. Predictably, this generality often comes with a cost in efficiency. Shortest paths in dags, revisited At the conclusion of our study of shortest paths (Chapter 4), we observed that the problem is especially easy in directed acyclic graphs (dags). Let’s recapitulate this case, because it lies at the heart of dynamic programming. The special distinguishing feature of a dag is that its nodes can be linearized; that is, they can be arranged on a line so that all edges go from left to right (Figure ). To see why this helps with shortest paths, suppose we want to figure out distances from node S to the other nodes. For concreteness, let’s focus on node D. The only way to get to it is through its predecessors, B or C ; so to find the shortest path to D, we need only compare these two routes: dist(D) = min{dist(B) + 1, dist(C ) + 3}. A similar relation can be written for every node. If we compute these dist values in the left-to-right order of Figure , we can always be sure that by the time we get to a node v, we already have all the information we need to compute dist(v). We are therefore able to compute all distances in a single pass: initialize all dist(·) values to ∞ dist(s) = 0 for each v ∈ V\{s}, in linearized order: dist(v) = min(u,v)∈E {dist(u) + l(u, v)} Notice that this algorithm is solving a collection of subproblems, {dist(u) : u ∈ .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.