CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.

Slides:



Advertisements
Similar presentations
Back to Sorting – More efficient sorting algorithms.
Advertisements

Lecture 3: Parallel Algorithm Design
A simple example finding the maximum of a set S of n numbers.
What is divide and conquer? Divide and conquer is a problem solving technique. It does not imply any specific computing problems. The idea is to divide.
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
Divide-and-Conquer Recursive in structure –Divide the problem into several smaller sub-problems that are similar to the original but smaller in size –Conquer.
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
Lecture 2: Divide and Conquer algorithms Phan Thị Hà Dương
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Recursion & Merge Sort Introduction to Algorithms Recursion & Merge Sort CSE 680 Prof. Roger Crawfis.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 4 Some of the sides are exported from different sources.
Lecture 3 Nearest Neighbor Algorithms Shang-Hua Teng.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Lecture 6 Divide and Conquer for Nearest Neighbor Problem Shang-Hua Teng.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 5. Recursive Algorithms.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions Analysis of.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Recurrences The expression: is a recurrence. –Recurrence: an equation that describes a function in terms of its value on smaller functions BIL741: Advanced.
Divide-and-Conquer 7 2  9 4   2   4   7
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CS223 Advanced Data Structures and Algorithms 1 Sorting and Master Method Neil Tang 01/21/2009.
Project 2 due … Project 2 due … Project 2 Project 2.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
1 Designing algorithms There are many ways to design an algorithm. Insertion sort uses an incremental approach: having sorted the sub-array A[1…j - 1],
CSS106 Introduction to Elementary Algorithms M.Sc Askar Satabaldiyev Lecture 05: MergeSort & QuickSort.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
1 Ch.19 Divide and Conquer. 2 BIRD’S-EYE VIEW Divide and conquer algorithms Decompose a problem instance into several smaller independent instances May.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 2 Sorting (insertion Sort, Merge Sort)
Sorting Algorithms Merge Sort Quick Sort Hairong Zhao New Jersey Institute of Technology.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
Sorting Quick, Merge & Radix Divide-and-conquer Technique subproblem 2 of size n/2 subproblem 1 of size n/2 a solution to subproblem 1 a solution to.
1 Overview Divide and Conquer Merge Sort Quick Sort.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
CS6045: Advanced Algorithms Sorting Algorithms. Sorting Input: sequence of numbers Output: a sorted sequence.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Lecture 4 Sorting Networks
Divide-and-Conquer 6/30/2018 9:16 AM
Unit 1. Sorting and Divide and Conquer
Lecture 4 Divide-and-Conquer
Advanced Design and Analysis Techniques
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
CSCE 411 Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
Dynamic Programming 2 Neil Tang 4/22/2010
“Human Sorting” It’s a “Problem Solving” game:
Divide-and-Conquer 7 2  9 4   2   4   7
Topic: Divide and Conquer
CSE 373 Data Structures and Algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
CSE 2010: Algorithms and Data Structures
Divide and Conquer Algorithms Part I
Dynamic Programming 2 Neil Tang 4/22/2008
Divide-and-Conquer 7 2  9 4   2   4   7
Divide and Conquer Neil Tang 4/24/2008
Divide & Conquer Algorithms
Topic: Divide and Conquer
Divide-and-Conquer 7 2  9 4   2   4   7
“Human Sorting” It’s a “Problem Solving” game:
Divide-and-Conquer Divide: the problem into subproblems
Presentation transcript:

CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010

CS223 Advanced Data Structures and Algorithms 2 Class Overview  Basic idea  Quick sort  Merge sort  Integer multiplication  Matrix multiplication

CS223 Advanced Data Structures and Algorithms 3 Basic Idea  Divide: divide the original problem to several sub-problems.  Conquer: Solve the sub-problems recursively.  Combine: Combine the solutions to sub-problems to form a solution for the original problem.

CS223 Advanced Data Structures and Algorithms 4 Merge Sort  Divide: Divide the N-element sequence into 2 subsequences of N/2 each.  Conquer: Sort each subsequence recursively using merge sort.  Combine: Merge two sorted subsequences to produce a single sorted sequence.

CS223 Advanced Data Structures and Algorithms 5 Merge Sort

CS223 Advanced Data Structures and Algorithms 6 Merge Sort  T(N) = 2T(N/2) + N  a=2, b=2, f(N)=N  log 2 2 = 1  So we have case 2, T(N) =  (NlogN).

CS223 Advanced Data Structures and Algorithms 7 Quick Sort  Divide: Divide the sequence into 2 subsequences, s.t. each element in the 1st subsequence is less than or equal to each element in the 2nd subsequence.  Conquer: Sort each subsequence recursively using quick sort.  Combine: no work is needed.

CS223 Advanced Data Structures and Algorithms 8 Quick Sort age 25 people age  25 people age  25 age 23 people age < 23 age 30 people age  30 people age  23 people age < 30

CS223 Advanced Data Structures and Algorithms 9 Quick Sort  T(N) = T(N-1) + N  The Master method does not work.  T(N) = O(N 2 )

CS223 Advanced Data Structures and Algorithms 10 Integer Multiplication  Compute XY, where X and Y are N-digit integers.  Divide: X=X L X R, Y=Y L Y R  Conquer and combine: XY = X L Y L (X L Y R + X R Y L )10 4 +X R Y R

CS223 Advanced Data Structures and Algorithms 11 Integer Multiplication  T(N) = 4T(N/2) +  (N)  a=4, b=2, f(N)=  (N)  log 2 4 = 2   So we have case 1, T(N) =  (N 2 ).

CS223 Advanced Data Structures and Algorithms 12 A Better Algorithm

CS223 Advanced Data Structures and Algorithms 13 Integer Multiplication  T(N) = 3T(N/2) +  (N)  a=3, b=2, f(N)=  (N)  log 2 3 = 1.59   So we have case 1, T(N) =  (N 1.59 ).

CS223 Advanced Data Structures and Algorithms 14 Matrix Multiplication  Compute AB, where A and B are N  N matrix.  Divide: Divide each matrix to 4 quadrants.  Conquer and combine:

CS223 Advanced Data Structures and Algorithms 15 Matrix Multiplication

CS223 Advanced Data Structures and Algorithms 16 Matrix Multiplication  T(N) = 8T(N/2) +  (N 2 )  a=8, b=2, f(N)=  (N 2 )  log 2 8 = 3   So we have case 1, T(N) =  (N 3 ).

CS223 Advanced Data Structures and Algorithms 17 A Better Algorithm

CS223 Advanced Data Structures and Algorithms 18 Matrix Multiplication  T(N) = 7T(N/2) +  (N 2 )  a=7, b=2, f(N)=  (N 2 )  log 2 7 = 2.81   So we have case 1, T(N) =  (N 2.81 ).