Top Banner
演算法 分析與設計 期末報告
62

Algorithm Final Presentation

Jul 15, 2015

Download

Technology

Johnson Chou
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Algorithm Final Presentation

演算法分析與設計

期末報告

Page 2: Algorithm Final Presentation

銘傳大學資訊工程所 一年級

周家聖E-mail : [email protected]

Page 3: Algorithm Final Presentation

指導老師

徐熊健

老師

Page 4: Algorithm Final Presentation

刪減搜尋法

Prune and Search

Page 5: Algorithm Final Presentation

字面Literal

Page 6: Algorithm Final Presentation

Prune刪減

Page 7: Algorithm Final Presentation

Search搜尋

Page 8: Algorithm Final Presentation

Recurs

ive

遞迴

Page 9: Algorithm Final Presentation

範例Example

Page 10: Algorithm Final Presentation

Selection Problem

選擇問題

Page 11: Algorithm Final Presentation

Output :

The k-th smallest element in S.

Input :

A set elements S and k.

SelectionProblem

Page 12: Algorithm Final Presentation

Step 1.

DivideElements into

[n/5] subsets

Page 13: Algorithm Final Presentation
Page 14: Algorithm Final Presentation

Step 2.

Sort each subset

Page 15: Algorithm Final Presentation

Each 5-elem

ent subset is sorted in non-decreasing sequence.

Page 16: Algorithm Final Presentation

Step 3.

Find a element

Pwhich is the

median of the medians of

the n/5 subsets.

Page 17: Algorithm Final Presentation

M

P

Page 18: Algorithm Final Presentation

Step 4.Partition S into

S1, S2 and S

3,

which contain the elements

less than, equal to, and greater than p,

respectively.

Page 19: Algorithm Final Presentation

Step 5. Case I

If |S1| > k, then

discard S2 and S

3 and

solve the problem that

selects the k-th smallest element from S1

during the next iteration

Page 20: Algorithm Final Presentation

M

P

At least 1/4 of S known to be greater than or equal to P.

Page 21: Algorithm Final Presentation

Step 5. Case II

if |S1| + |S

2| > k

then P is the k-th smallest element of S

Page 22: Algorithm Final Presentation

M

P

Page 23: Algorithm Final Presentation

Step 5. Case III

otherwise,

let k = k - |S1| - |S

2|,

solve the problem that selects the k-th smallest

element from S3

during the next iteration.

Page 24: Algorithm Final Presentation

M

P

At least 1/4 of S known to be less than or equal to P.

Page 25: Algorithm Final Presentation

Time complexity: T(n) = O(n)

step 1: O(n)step 2: O(n)step 3: T(n/5)step 4: O(n)step 5: T(3n/4)

=> T(n) = T(3n/4) + T(n/5) + O(n)

Page 26: Algorithm Final Presentation

Let

T(n) = a0 + a

1n + a

2n2 + … , a

1 != 0

T(3n/4) = a0 + (3/4)a

1n + (9/16)a

2n2 + …

T(n/5) = a0 + (1/5)a1n + (1/25)a2n2 + …

T(3n/4 + n/5) = T(19n/20) = a0 + (19/20)a1n + (361/400)a2n2 + …

thus,

T(3n/4) + T(n/5) <= a0 + T(19n/20)

Page 27: Algorithm Final Presentation

T(n) = T(3n/4) + T(n/5) + O(n)

<= cn + T(19n/20) = cn + (19/20)cn + T((19/20)2n) = cn + (19/20)cn + (19/20)2cn + … + (19/20)pcn + T((19/20)p+1n) , (19/20)p+1n <= 1 <= (19/20)pn =

<= 20cn +b = ...

bcnp

+−

− +

2 0191

)2019(1 1

Page 28: Algorithm Final Presentation

O(n)

Page 29: Algorithm Final Presentation

Prune and Search

定義

Page 30: Algorithm Final Presentation

Many Iterations

很多回合

Page 31: Algorithm Final Presentation

Prunes away a fraction, each iteration

刪除部分每回合

Page 32: Algorithm Final Presentation

so small,solved directly in constant time c

量少常數時間內

解決

Page 33: Algorithm Final Presentation

T(n) <= T((1 - f ) n) + cnk for sufficiently large n.

<= T((1 - f )2n) + cnk + c(1 - f )knk

...

<= c’+ cnk + c(1 - f )knk + c(1 - f )2knk + ... + c(1 - f )pknk

= c’+ cnk(1 + (1 - f )k + (1 - f )2k + ... + (1 - f ) pk).

Since 1 - f < 1, as n ,

T(n) = O(nk)

Thus, the whole time-complexityis as the same order as the time-complexity

each iteration.

所以 ...

Page 34: Algorithm Final Presentation

1-Center

Problem

Page 35: Algorithm Final Presentation

Given n planar points, find a smallest circle to cover these n points.

Page 36: Algorithm Final Presentation

Constrained

1-Center Problem

Page 37: Algorithm Final Presentation

The center is restricted to lying on a straight line.

y = 0

Lij

Pi

Pj

xij

xmx*

Page 38: Algorithm Final Presentation

Constrained1-Center

Problem

Input :

n points and a straight line y = y'

Output :

The constrained center on the line y = y'

Page 39: Algorithm Final Presentation

Step 1: If n is no more than 2, solve this problem by a

brute-force method.

Step 2: Form disjoint pairs of points (p1, p

2),

(p3, p

4), …,(p

n-1, p

n). If there are odd number of points, just let

the final pair be (pn, p

1).

Step 3: For each pair of points, (pi, p

i+1), find the point

xi,i+1

on the line y = y’ such that

d(pi, x

i,i+1) = d(p

i+1, x

i,i+1).

Step 4: Find the median of the all xi,i+1

’s.

Denote it as xm

.

Page 40: Algorithm Final Presentation

Step 5 :

Calculate the distance between pi and x

m for all i. Let p

j be

the point which is farthest from xm. Let x

j denote the projection

of pj onto y = y'.

If xj is to the left (right) of x

m, then the optimal solution, x*,

must be to the left (right) of xm.

Step 6: If x* < x

m, for each x

i,i+1 > x

m, prune the point p

i

if pi is closer to x

m than p

i+1, otherwise prune the point p

i+1;

If x* > xm, do similarly.

Step 7: Go to Step 1.

Page 41: Algorithm Final Presentation

By the constrained 1-center algorithm, we can determine the center

(x*,0) on the line y=0.

Time complexity : O(n)

Page 42: Algorithm Final Presentation
Page 43: Algorithm Final Presentation

We can do more

不只這樣

Page 44: Algorithm Final Presentation

Let (xs, y

s) be the center of the optimum circle.

We can determine whether

ys > 0, y

s < 0 or y

s = 0.

Similarly, we can also determine whether

xs > 0, x

s < 0 or x

s = 0.

Page 45: Algorithm Final Presentation

The Sign of Optimal y

Let I be the set of points which are farthest from (x*, 0).

Page 46: Algorithm Final Presentation

Case 1:

I contains one point P = (xp, y

p).

ys has the same sign as that of y

p.

Page 47: Algorithm Final Presentation

Case 2 :

I contains more than one point.

Find the smallest arc spanning all points in I.

Let P1

= (x1, y

1) and P

2 = (x

2, y

2)

be the two end points of the arc.

Page 48: Algorithm Final Presentation

If this arc >= 180o , then y

s = 0.

y = 0

P1

P3P2

(x*, 0)

(a)

Page 49: Algorithm Final Presentation

else ys has the same sign as that of .

y = 0

P3P4

P1

P2

(x*, 0)

(b)

221 yy +

Page 50: Algorithm Final Presentation

1-Center

Problem

Page 51: Algorithm Final Presentation

1-Center

Problem

Input:

A set S = {p1, p

2, …, p

n} of n points.

Output:

The smallest enclosing circle for S.

Page 52: Algorithm Final Presentation

Step 1:

If S contains no more than 16 points,

solve the problem by a

brute-force

method.

Page 53: Algorithm Final Presentation

Step 2:

Form disjoint pairs of points, (p

1, p

2), (p

3, p

4), …,(p

n-1, p

n).

For each pair of points, (pi, p

i+1),

find the perpendicular bisector of line segment .

Denote them as Li/2, for i = 2, 4, …, n,

and compute their slopes.

Let the slope of Lk be denoted as s

k,

for k = 1, 2, 3, …, n/2.

1ii pp +

Page 54: Algorithm Final Presentation

Step 3: Compute the median of sk’s, and

denote it by sm

.

Step 4: Rotate the coordinate system

so that the x-axis coincide with

y = smx.

Let the set of Lk's with positive (negative) slopes be

I+ (I-). (Both of them are of size n/4.)

Page 55: Algorithm Final Presentation

Step 5: Construct disjoint pairs of lines,

(Li+, L

i-) for i = 1, 2, …, n/4,

where Li+ in I+ and L

i- in I-.

Find the intersection of each pair and denote it by

(ai, b

i), for i = 1, 2, …, n/4.

¿

Page 56: Algorithm Final Presentation

Step 6: Find the median of bi’s.

Denote it as y*.

Apply the constrained 1-center subroutine to S, requiring that the center of circle be located on

y=y*.

Let the solution of this constrained 1-center

problem be (x', y*).

Page 57: Algorithm Final Presentation

Step 7: Determine whether

(x', y*)

is the optimal solution.

If it is, exit;

otherwise, record ys > y* or y

s < y*.

Page 58: Algorithm Final Presentation

Step 8: If ys > y*, find the median of a

i’s for

those (ai, b

i)’s where bi < y*.

If ys < y*, find the median of a

i's of those t hose

(ai, b

i)’s where bi > y*.

Denote the median as x*.

Apply the constrained 1-center algorithm to S, requiring

that the center of circle be located on x = x*.

Let the solution of this contained 1-center problem be

(x*, y').

Page 59: Algorithm Final Presentation

Step 9: Determine whether

(x*, y')

is the optimal solution.

If it is, exit;

otherwise, record xs > x* or x

s < x*.

Page 60: Algorithm Final Presentation

Case 1: xs > x* and y

s > y*.

Find all (ai, b

i)'s such that a

i < x* and b

i < y*.

Let (ai, b

i) be the intersection of L

i+ and L

i-.

Let Li- be the bisector of p

j and p

k.

Prune away pj(p

k) if p

j(p

k) is closer to (x*, y*) than p

k(p

j).

Case 2: xs < x* and y

s > y*. Do similarly.

Case 3: xs < x* and y

s < y*. Do similarly.

Case 4: xs > x* and y

s > y*. Do similarly.

Step 11: Let S be the set of the remaining points. Go to Step 1.

Step 10:

Page 61: Algorithm Final Presentation

Time complexity

T(n) = T(15n/16)+O(n) = O(n)

Page 62: Algorithm Final Presentation

感謝聆聽E

nd

Thanks for your listening