The Divide-and-Conquer Strategy

Slides:



Advertisements
Similar presentations
4 -1 Chapter 4 The Divide-and-Conquer Strategy A simple example finding the maximum of a set S of n numbers.
Advertisements

The Divide-and-Conquer Strategy
The Divide-and-Conquer Strategy
Convex Hull Problem Presented By Erion Lin. Outline Convex Hull Problem Voronoi Diagram Fermat Point.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
Section 1.2 Describing Distributions with Numbers 用數字描述分配.
指導教授:陳淑媛 學生:李宗叡 李卿輔.  利用下列三種方法 (Edge Detection 、 Local Binary Pattern 、 Structured Local Edge Pattern) 來判斷是否為場景變換,以方便使用者來 找出所要的片段。
: Boxes ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11003: Boxes 解題者:蔡欣燁 解題日期: 2007 年 3 月 19 日.
: Road Construction ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 10724: Road Construction 解題者:徐文宏 解題日期: 2011 年 4 月 20 日 題意:給一個座標圖 (-1000~1000)
Lecture 8 Median and Order Statistics. Median and Order Statistics2 Order Statistics 問題敘述 在 n 個元素中,找出其中第 i 小的元素。 i = 1 ,即為找最小值。 i = n ,即為找最大值。 i = 或 ,即為找中位數。
Review of Chapter 3 - 已學過的 rules( 回顧 )- 朝陽科技大學 資訊管理系 李麗華 教授.
:New Land ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11871: New Land 解題者:施博修 解題日期: 2011 年 6 月 8 日 題意:國王有一個懶兒子,為了勞動兒子,他想了一個 辦法,令他在某天早上開始走路,直到太陽下山前,靠.
:Quarter-Finals with Brazil!? No!!! ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11041: Quarter-Finals with Brazil!? No!!! 解題者:呂彥澂 解題日期:
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
: Matrix Decompressing ★★★★☆ 題組: Contest Volumes with Online Judge 題號: 11082: Matrix Decompressing 解題者:蔡權昱、劉洙愷 解題日期: 2008 年 4 月 18 日 題意:假設有一矩陣 R*C,
Part 1 Understanding Data Chapter 1 Examining Distributions Chapter 2 Examining Relationships Chapter 3 Producing Data.
: The Playboy Chimp ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10611: The Playboy Chimp 解題者:蔡昇宇 解題日期: 2010 年 2 月 28 日 題意:給一已排序的數列 S( 升冪.
: Nails ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 11096:Nails 解題者:蘇育彣 解題日期: 2007 年 3 月 13 日 題意:給定一個正整數 n (0
Monte Carlo Simulation Part.2 Metropolis Algorithm Dept. Phys. Tunghai Univ. Numerical Methods C. T. Shih.
10215: The Largest/Smallest Box... ★ 題組: Problem Set Archive with Online Judge 題號: 10215: The Largest/Smallest Box... 解題者:張維珊 解題日期: 2006 年 4 月 17 日 題意:
2009fallStat_samplec.i.1 Chap10 Sampling distribution (review) 樣本必須是隨機樣本 (random sample) ,才能代表母體 Sample mean 是一隨機變數,隨著每一次抽出來的 樣本值不同,它的值也不同,但會有規律性 為了要知道估計的精確性,必需要知道樣本平均數.
Network Connections ★★★☆☆ 題組: Contest Archive with Online Judge 題號: Network Connections 解題者:蔡宗翰 解題日期: 2008 年 10 月 20 日 題意:給你電腦之間互相連線的狀況後,題.
: Make a Crystal ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11094: Make a Crystal 解題者:呂彥澂 解題日期: 2007 年 4 月 17 日 題意:在 N*N*N 的空間中 (N 為偶數.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
3-3 使用幾何繪圖工具 Flash 的幾何繪圖工具包括線段工具 (Line Tool) 、橢圓形工具 (Oval Tool) 、多邊星形 工具 (Rectangle Tool) 3 種。這些工具畫出 來的幾何圖形包括了筆畫線條和填色區域, 將它們適當地組合加上有技巧地變形與配 色, 不但比鉛筆工具簡單,
Matlab Assignment Due Assignment 兩個 matlab 程式 : Eigenface : Eigenvector 和 eigenvalue 的應用. Fractal : Affine transform( rotation, translation,
: IIUC HexWorld ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11092: IIUC HexWorld 解題者:江秀桂 解題日期: 2007 年 3 月 6 日.
: Point of View in Flatland ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 11037: Point of View in Flatland 解題者:黃士庭 解題日期: 2007 年 5 月 15 日 題意:在座標平面上給三個圓,找一個點使從這.
: Playing War ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11061: Playing War 解題者:陳盈村 解題日期: 2008 年 3 月 14 日 題意:在此遊戲中,有一類玩家一旦開始攻擊, 就會不停攻擊同一對手,直到全滅對方或無法再.
: Problem A : MiniMice ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11411: Problem A : MiniMice 解題者:李重儀 解題日期: 2008 年 9 月 3 日 題意:簡單的說,題目中每一隻老鼠有一個編號.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
: Count DePrimes ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11408: Count DePrimes 解題者:李育賢 解題日期: 2008 年 9 月 2 日 題意: 題目會給你二個數字 a,b( 2 ≦ a ≦ 5,000,000,a.
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
資料結構實習-一 參數傳遞.
: Efficient Solutions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11020: Efficient Solutions 解題者:陳宜佐 解題日期: 2007 年 4 月 24 日 題意:給定 M 個 case.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
演算法 8-1 最大數及最小數找法 8-2 排序 8-3 二元搜尋法.
: Expect the Expected ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11427: Expect the Expected 解題者:李重儀 解題日期: 2008 年 9 月 21 日 題意:玩一種遊戲 (a game.
逆向選擇和市場失調. 定義  資料不對稱 在交易其中,其中一方較對方有多些資料。  逆向選擇 出現在這個情況下,就是當買賣雙方隨意在 市場上交易,與比較主動交易者作交易為佳 。
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Chapter 10 m-way 搜尋樹與B-Tree
演算法課程 (Algorithms) 國立聯合大學 資訊管理學系 陳士杰老師 Course 7 貪婪法則 Greedy Approach.
學習理論與整合模式 這章節所討論的兩大教學理論 ( 指導 / 建構 ) 有 何差異性 ? 當學習愈上瓶頸 指導是與建構式的解決方式各 是什麼 ? 指導式的教學理論解決什麼樣的教學問題 ? 科 技在教學上的運用又如何這樣的理想 ? 建構式的教學理論解決什麼樣的教學問題 ? 科 技在教學上的運用又如何這樣的理想.
質數 (Prime) 相關問題 (III) — 如何找出相對大的質數 Date: May 27, 2009 Introducer: Hsing-Yen Ann.
: Expressions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10157: Expressions 解題者:張庭愿 解題日期: 2009 年 8 月 16 日 題意:所有的括號必須成對,且必須先出現過左 括號後才能出現右括號,如果有.
Chapter 7 Sampling Distribution
: Sum-up the Primes ★★★★☆ 題組: Problem A 題號: 10419: Sum-up the Primes 解題者:林一帆 解題日期: 2006 年 5 月 15 日 題意: 評斷一個給予的數字是否是由給予個數 的質數所組成的.
: Problem E Antimatter Ray Clearcutting ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11008: Problem E Antimatter Ray Clearcutting 解題者:林王智瑞.
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
指導教授 : 林啟芳 教授 組員 : 邱秉良 林育賢. 何謂 GPS  GPS 即全球定位系統,是一個中距離圓 型軌道衛星導航系統。它可以為地球表面 絕大部分地區( 98% )提供準確的定位、 測速和高精度的時間標準。
: Place the Guards ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11080: Place the Guards 解題者:陳盈村 解題日期: 2008 年 3 月 26 日 題意:有一個國王希望在他的城市裡佈置守衛,
: SAM I AM ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11419: SAM I AM 解題者:李重儀 解題日期: 2008 年 9 月 11 日 題意: 簡單的說,就是一個長方形的廟裡面有敵人,然 後可以橫的方向開砲或縱向開砲,每次開砲可以.
牽涉兩個變數的 Data Table 汪群超 11/1/98. Z=-X 2 +4X-Y 2 +6Y-7 觀察 Z 值變化的 X 範圍 觀察 Z 值變化的 Y 範圍.
: Finding Paths in Grid ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11486: Finding Paths in Grid 解題者:李重儀 解題日期: 2008 年 10 月 14 日 題意:給一個 7 個 column.
:Rings and Glue ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10301: Rings and Glue 解題者:施博修 解題日期: 2011 年 5 月 18 日 題意:小約翰有了個大麻煩,他不小心將 rings.
幼兒行為觀察與記錄 第八章 事件取樣法.
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
1 柱體與錐體 1. 找出柱體與錐體的規則 2. 柱體的命名與特性 3. 柱體的展開圖 4. 錐體的命名與特性 5. 錐體的展開圖
Voronoi Diagram and Delaunay Triangulation
5 -1 Chapter 5 The Divide-and-Conquer Strategy A simple example finding the maximum of a set S of n numbers.
Face Recognition by Support Vector Machines 指導教授 : 王啟州 教授 學生 : 陳桂華 Guodong Guo, Stan Z. Li, and Kapluk Chan School of Electrical and Electronic Engineering.
4-3~ 鄭力瑋. concave polygon:convex polygon: Convex polygons 「凸」的定義是:圖形內任意兩點的連線不會經過圖形外部。
Convex Hull 2012/10/23. Convex vs. Concave A polygon P is convex if for every pair of points x and y in P, the line xy is also in P; otherwise, it is.
The Divide-and-Conquer Strategy
Presentation transcript:

The Divide-and-Conquer Strategy 5-1 The 2-Dimensional maxima finding problem 5-2 The Closest pair problem 5-3 The Convex hull problem 指導教授:徐熊健 教授 報告者:陳琨

Divide-and-Conquer 精神 : 什麼樣的問題適用 ? 分裂並各個擊破 一個問題如果能切割成兩個獨立的小問題,且解小問題與解原始問題是一樣的,差別只在於 size 的大小時

A General Divide-and-Conquer Algorithm Step 1: If the problem size is small, solve this problem directly; otherwise, split the original problem into 2 sub-problems with equal sizes. Step 2: Recursively solve these 2 sub-problems by applying this algorithm. Step 3: Merge the solutions of the 2 sub-problems into a solution of the original problem.

A General Divide-and-Conquer Illustration - 1 Step 1 If small else 直接解

A General Divide-and-Conquer Illustration - 2 Step 2

A General Divide-and-Conquer Illustration - 3 Step 3

Time Complexity of the General Algorithm time of splitting constant time of merging

A Simple Example Finding the maximum 29 14 15 01 06 10 32 12 29 14 15

A Simple Example (cont.) Finding the maximum 32 29 32 29 15 10 32 29 14 15 01 06 10 32 12

Time Complexity Time Complexity Assume n = 2k T(n) = 2T(n/2)+1 … = 2k-1T(2)+2k-2+…+4+2+1 = 2k-1+2k-2+…+4+2+1 = 2k-1 = n-1

5-1 The 2-Dimesional Maxima Finding Problem 何謂 Dominates ? A point (x1, y1) dominates (x2, y2) if x1 > x2 and y1 > y2. Y A A dominates B B X

5-1 The 2-Dimesional Maxima Finding Problem (cont.) A point is called a maxima if no other point dominates it. Y 兩兩比較 Time Complexity:O(n2) X

Maxima Finding Algorithm Input: A set S of n planar points. Output: The maximal points of S. Step 1: If S contains only one point, return it as the maxima. Otherwise, find a line L perpendicular to the X-axis which separates S into SLand SR, with equal sizes. Step 2: Recursively find the maximal points of SL and SR . Step 3: Find the largest y-value of SR, denoted as yR. Discard each of the maximal points of SL if its y-value is less than yR.

Maxima Finding Algorithm Illustration - 1 Step 1 If only one point else Time Complexity:O(n) X Y Y X L SL SR maxima

Maxima Finding Algorithm Illustration - 2 Step 2 Time Complexity:2T(n/2) Y X L L SL SR

Maxima Finding Algorithm Illustration - 3 Step 3 Time Complexity: => O(nlogn) Y L SL SR => O(n) (presorting) X

Maxima Finding Time complexity Time complexity: T(n) Step 1: O(n) Step 2: 2T(n/2) Step 3: O(nlogn) Assume n = 2k

Maxima Finding Time complexity (cont.) After presorting Time complexity: O(nlogn)+T(n) Step 1: O(n) Step 2: 2T(n/2) Step 3: O(n) Assume n = 2k Time complexity = O(nlogn)+T(n) = O(nlogn)+O(nlogn) = O(nlogn)

5-2 The Closest Pair Problem Given a set S of n points, find a pair of points which are closest together (在一個有 n 個點的集合 S 中,找最靠近的兩個點) 1-D version: 2-D version: X Y X Time Complexity:O(nlogn)

Closest Pair Algorithm Input: A set S of n planar points. Output: The distance between two closest points. Step 1: Sort points in S according to their y-values. Step 2: If S contains only one point, return infinity as its distance. Step 3: Find a median line L perpendicular to the X-axis to divide S into SL and SR, with equal sizes. Step 4: Recursively apply Steps 2 and 3 to solve the closest pair problems of SL and SR. Let dL(dR) denote the distance between the closest pair in SL (SR). Let d = min(dL, dR).

Closest Pair Algorithm Illustration - 1 Step 1 先針對每個點X軸的值和Y軸的值做排序 Step 2 Step 3 If only one point Time Complexity:O(n) X Y Y X L SL SR d = ∞

Closet Pair Algorithm Illustration - 2 Step 4 Time Complexity:2T(n/2) Y X L L SL SR

Closet Pair Algorithm Illustration - 3 Step 5 Y X L SL SR dL dR L-d L+d d=min(dL,dR)

Closet Pair Algorithm Illustration - 4 Y 2d P d X

Closest Pair Time complexity Step 1: O(nlogn) Step 2~5: T(n) = 2T(n/2)+S(n)+M(n) Total time-complexity = O(nlogn)+T(n) = O(nlogn)+O(nlogn) = O(nlogn)

5-3 The Convex Hull Problem 何謂 Convex polygon (凸多邊形) ? Concave polygon (凹多邊形): Convex polygon :

5-3 The Convex Hull Problem (Cont.) The Convex hull of a set of planar points is defined as the smallest convex polygon containing all of the points. (在平面上的一組點,用最小面積的凸多邊形將所有點包起來)

Convex Hull Algorithm Input : A set S of planar points Output : A convex hull for S Step 1: If S contains no more than five points, use exhaustive searching to find the convex hull and return. Step 2: Find a median line perpendicular to the X-axis which divides S into SL and SR, with equal sizes. Step 3: Recursively construct convex hulls for SL and SR, denoted as Hull(SL) and Hull(SR), respectively. Step 4: Apply the merging procedure to merge Hull(SL) and Hull(SR) together to form a convex hull.

Use Divide-and-Conquer to Solve Y SL SR Use Graham scan X

Graham Scan Algorithm Step 1: Select an interior point as the origin. Step 2: Each other point forms a polar angle, and all points sorted by polar angles Step 3: Examines the points cause reflexive angles Step 4: The remaining points are convex hull vertices

The Graham scan (Illustration) Y P2 P1 P P0 P3 P5 P4 X

Eliminates points (Illustration) Y 令 P0,P1,P2 座標各為 (x0,y0) (x1,y1) (x2,y2) P4 P3 P2 P5 If det < 0 than 逆時針 If det > 0 than 順時針 If det = 0 than 三點共線 P1 P0 X

Use Divide-and-Conquer to Solve Y 找小於π/2 最大的 SL SR d j i e c k p f h g b a 找大於 3π/2 最小的 X

Use Divide-and-Conquer to Solve Time Complexity: T(n) = 2T(n/2) + O(n) = O(nlogn) Y SL SR d j i e c k f h g b a X

The End