Algorithmic Toolbox week4 Divide and Conquer --- Introduction

Def

1.Divide problem into sub problems that can be solved independently.
2.Sub problems have no overlap.
3.Sub problems's type are same as original problem.
  将一个矩形必须分解为若干个矩形,而不是三角形或者其他类型。


Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第1张图片
Divide
Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第2张图片
Conquer
Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第3张图片
Combine

In summary, the divide and conquer algorithm consists of one: breaking the problem into non-overlapping subproblems of the same type. Two: recursively solving those subproblems. And three: combining the results.


Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第4张图片
Divide and Conquer

Linear Search

Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第5张图片
Searching in an array
Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第6张图片
Linear Search

for low in (low, high+2),也就是low将会从low增加到high+1,所以n=high-low+1.

Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第7张图片
Iterative version
Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第8张图片
Summary

Binary Search

Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第9张图片
Binary Search
Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第10张图片
image.png

Binary Search Runtime

Algorithmic Toolbox week4 Divide and Conquer --- Introduction_第11张图片
image.png

The way to do that was an augmented set of arrays.

你可能感兴趣的:(Algorithmic Toolbox week4 Divide and Conquer --- Introduction)