• 沒有找到結果。

# Algorithm Design and Analysis Divide and Conquer (2)

N/A
N/A
Protected

Share "Algorithm Design and Analysis Divide and Conquer (2)"

Copied!
38
0
0

(1)

(2)

### Outline

• Recurrence (遞迴)

• Divide-and-Conquer

• D&C #1: Tower of Hanoi (河內塔)

• D&C #2: Merge Sort

• D&C #3: Bitonic Champion

• D&C #4: Maximum Subarray

• Solving Recurrences

### • Master Method

• D&C #5: Matrix Multiplication

• D&C #6: Selection Problem

• D&C #7: Closest Pair of Points Problem

Divide-and-Conquer 之神乎奇技

Divide-and-Conquer 首部曲

(3)

### 1. Divide the problem into a number of subproblems that are smaller instances of the

same problem (比較小的同樣問題)

### 2. Conquer the subproblems by solving them recursively

If the subproblem sizes are small enough

• then solve the subproblems

• else recursively solve itself

### 3. Combine

the solutions to the subproblems into the solution for the original problem

base case recursive case

(4)

## Solving Recurrences

Textbook Chapter 4.3 – The substitution method for solving recurrences Textbook Chapter 4.4 – The recursion-tree method for solving recurrences Textbook Chapter 4.5 – The master method for solving recurrences

(5)

(6)

## 1. Substitution Method (取代法)

• Guess a bound and then prove by induction

## 2. Recursion-Tree Method (遞迴樹法)

• Expand the recurrence into a tree and sum up the cost

## 3. Master Method (套公式大法/大師法)

• Apply Master Theorem to a specific form of recurrences

### • Useful simplification tricks

• Ignore floors, ceilings, boundary conditions (proof in Ch. 4.6)

• Assume base cases are constant (for small n)

(7)

## Substitution Method

Textbook Chapter 4.3 – The substitution method for solving recurrences

(8)

### • Proof

• There exists positive constant 𝑎, 𝑏 s.t.

• Use induction to prove

• n = 1, trivial

• n > 1,

Substitution Method (取代法)

guess a bound and then prove by induction

(9)

### Substitution Method (取代法)

• Guess the form of the solution

• Verify by mathematical induction (數學歸納法)

• Prove it works for 𝑛 = 1

• Prove that if it works for 𝑛 = 𝑚, then it works for 𝑛 = 𝑚 + 1

→ It can work for all positive integer 𝑛

• Solve constants to show that the solution works

• Prove 𝑂 and Ω separately

(10)

0

0

0

• n = 1, trivial

• n > 1,

### • holds when

e.g.

Inductive hypothesis

Guess

Verify

Solve

(11)

0

0

0

### , 𝑐

• n = 1, trivial

• n > 1,

Inductive hypothesis

Tighter upper bound?

(12)

0

1

2

0

0

1

### , 𝑐

2

• n = 1, holds for

• n > 1,

### • holds when

e.g.

Inductive hypothesis

Guess

Verify

Solve Strengthen the inductive hypothesis

by subtracting a low-order term

(13)

### Useful Tricks

• Guess based on seen recurrences

• Use the recursion-tree method

• From loose bound to tight bound

• Strengthen the inductive hypothesis by subtracting a low-order term

• Change variables

• E.g.,

1. Change variable:

2. Change variable again:

3. Solve recurrence

(14)

## Recursion-Tree Method

Textbook Chapter 4.4 – The recursion-tree method for solving recurrences

(15)

### • Proof

2nd expansion 1st expansion

kth expansion

The expansion stops when 2𝑘 = 𝑛

Recursion-Tree Method (遞迴樹法)

Expand the recurrence into a tree and sum up the cost

(16)

### • Verify the guess as in the substitution method

• Promote intuition

• Generate good guesses for the substitution method

1. Expand

2. Sumup

3. Verify

(17)

(18)

(19)

(20)

(21)

## Master Theorem

Textbook Chapter 4.4 – The recursion-tree method for solving recurrences

(22)

### Master Theorem

log 𝑎

divide a problem of size 𝑛 into 𝑎 subproblems, each of size 𝑛

𝑏 is solved in time 𝑇 𝑛

𝑏 recursively

The proof is in Ch. 4.6

(23)

𝑎 𝑎

(24)

### Three Cases

• 𝑎 ≥ 1, the number of subproblems

• 𝑏 > 1, the factor by which the subproblem size decreases

• 𝑓(𝑛) = work to divide/combine subproblems

• Compare 𝑓 𝑛 with 𝑛log𝑏 𝑎

1. Case 1: 𝑓 𝑛 grows polynomially slower than 𝑛log𝑏𝑎 2. Case 2: 𝑓 𝑛 and 𝑛log𝑏 𝑎 grow at similar rates

3. Case 3: 𝑓 𝑛 grows polynomially faster than 𝑛log𝑏 𝑎

(25)

𝑎 𝑎

(26)

(27)

𝑎 𝑎

(28)

(29)

𝑎 𝑎

log 𝑎

(30)

(31)

### Master Theorem

divide a problem of size 𝑛 into 𝑎 subproblems, each of size 𝑛

𝑏 is solved in time 𝑇 𝑛

𝑏 recursively

The proof is in Ch. 4.6

(32)

### Examples

compare 𝑓 𝑛 with 𝑛log𝑏𝑎

(33)

### Floors and Ceilings

• Master theorem can be extended to recurrences with floors and ceilings

• The proof is in the Ch. 4.6

(34)

(35)

(36)

(37)

(38)

## Question?

Important announcement will be sent to

@ntu.edu.tw mailbox & post to the course website

4 Solving optimization problems Kernel: decomposition methods Linear: coordinate descent method Linear: second-order methods Experiments. Chih-Jen Lin (National Taiwan Univ.) 86

Textbook Chapter 33.4 – Finding the closest pair of points.. Closest Pair of

Textbook Chapter 4.3 – The substitution method for solving recurrences Textbook Chapter 4.4 – The recursion-tree method for solving recurrences Textbook Chapter 4.5 – The master

In this case Lagrange’s method is to look for extreme values by solving five equations in the five unknowns x, y, z, λ, and µ ... Example 5

See Chapter 5, Interrupt and Exception Handling, in the IA-32 Intel Architecture Software Developer’s Manual, Volume 3, for a detailed description of the processor’s mechanism

• The start node representing the initial conﬁguration has zero in degree.... The Reachability

This theorem does not establish the existence of a consis- tent estimator sequence since, with the true value θ 0 unknown, the data do not tell us which root to choose so as to obtain

The underlying idea was to use the power of sampling, in a fashion similar to the way it is used in empirical samples from large universes of data, in order to approximate the

In this chapter we develop the Lanczos method, a technique that is applicable to large sparse, symmetric eigenproblems.. The method involves tridiagonalizing the given

For the proposed algorithm, we establish a global convergence estimate in terms of the objective value, and moreover present a dual application to the standard SCLP, which leads to

Abstract In this paper, we consider the smoothing Newton method for solving a type of absolute value equations associated with second order cone (SOCAVE for short), which.. 1

Like the proximal point algorithm using D-function [5, 8], we under some mild assumptions es- tablish the global convergence of the algorithm expressed in terms of function values,

[r]

Textbook Chapter 15.4 – Longest common subsequence Textbook Problem 15-5 – Edit

Multiple images from a sequence tracked with 6DOF SLAM on a client, while a localization server provides the global pose used to overlay the building outlines with transparent

Biases in Pricing Continuously Monitored Options with Monte Carlo (continued).. • If all of the sampled prices are below the barrier, this sample path pays max(S(t n ) −

Moreover, this chapter also presents the basic of the Taguchi method, artificial neural network, genetic algorithm, particle swarm optimization, soft computing and

Approach and a Boundary Element Method for the Calculation of Sound Fields in the Human Ear Canal, &#34; Journal of the Acoustical Society of America, 118(4), pp. Axelsson,

When collecting data on problem-solving processes the investigator used one textbook problem (revised into 2 formats) then interviewed 6 students (3 solved word problem with

problem-solving; 3) analyze the type of problems posed by children; and, 4) display categories of misconceptions exhibited when children did problem posing. The stages

[22] Guillermo Gonzalez, Microwave Transistor Amplifier Analysis and Design: Chapter 4, Noise, Broadband, And High-Power Design Methods, New Jersey, Prentice Hall Inc,

In the Chapter 2, it introduces specification of 802.11a about planning and regulation of the system structure.In the Chapter 3, it introduces the Mixer structure and the

Input data is the window data and the fall motion technique is the machine learning model with the extension of the checkpoint ensemble method...