Divide and Conquer Neil Tang 4/24/2008

Slides:



Advertisements
Similar presentations
Lecture 3: Parallel Algorithm Design
Advertisements

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.
Introduction to Algorithms Jiafen Liu Sept
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
1 Divide-and-Conquer CSC401 – Analysis of Algorithms Lecture Notes 11 Divide-and-Conquer Objectives: Introduce the Divide-and-conquer paradigm Review the.
CS223 Advanced Data Structures and Algorithms 1 Divide and Conquer Neil Tang 4/15/2010.
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.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
Data Structures Review Session 1
CSE 421 Algorithms Richard Anderson Lecture 13 Divide and Conquer.
CSE 421 Algorithms Richard Anderson Lecture 11 Recurrences.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Divide-and-Conquer 7 2  9 4   2   4   7
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]
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],
CS223 Advanced Data Structures and Algorithms 1 Review for Final Neil Tang 04/27/2010.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Divide-and-Conquer. Outline Introduction Merge Sort Quick Sort Closest pair of points Large integer multiplication.
CSE 421 Algorithms Lecture 15 Closest Pair, Multiplication.
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)
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.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
Chapter 2. Divide-and-conquer Algorithms
Introduction to Algorithms: Divide-n-Conquer Algorithms
Lecture 3: Parallel Algorithm Design
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Dynamic Programming 1 Neil Tang 4/20/2010
Lecture 4 Divide-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide and Conquer.
Divide-and-Conquer The most-well known algorithm design strategy:
CSCE 411 Design and Analysis of Algorithms
Growth Functions Algorithms Lecture 8
CS 3343: Analysis of Algorithms
Unit-2 Divide and Conquer
Dynamic Programming 2 Neil Tang 4/22/2010
Punya Biswas Lecture 15 Closest Pair, Multiplication
“Human Sorting” It’s a “Problem Solving” game:
Topological Sort Neil Tang 03/02/2010
Sorting Algorithms Ellysa N. Kosinaya.
Data Structures Review Session
Heapsort and d-Heap Neil Tang 02/11/2010
Topic: Divide and Conquer
CSE 373 Data Structures and Algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
CS200: Algorithms Analysis
CSE 2010: Algorithms and Data Structures
Divide and Conquer Algorithms Part I
Algorithms Dr. Youn-Hee Han April-May 2013
Dynamic Programming 2 Neil Tang 4/22/2008
Divide & Conquer Algorithms
Topic: Divide and Conquer
Topic: Divide and Conquer
Heapsort and d-Heap Neil Tang 02/14/2008
Divide-and-Conquer 7 2  9 4   2   4   7
“Human Sorting” It’s a “Problem Solving” game:
Review for Final Neil Tang 05/01/2008
Divide and Conquer Merge sort and quick sort Binary search
Divide-and-Conquer Divide: the problem into subproblems
Presentation transcript:

Divide and Conquer Neil Tang 4/24/2008 CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Course Survey Please complete the course survey by May 3 (Sat) at: http://www.cs.montana.edu/survey/ CS223 Advanced Data Structures and Algorithms

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

CS223 Advanced Data Structures and Algorithms 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

CS223 Advanced Data Structures and Algorithms 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. The time complexity is O(NlogN) CS223 Advanced Data Structures and Algorithms

CS223 Advanced Data Structures and Algorithms Merge Sort CS223 Advanced Data Structures and Algorithms

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

CS223 Advanced Data Structures and Algorithms 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

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

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

Integer Multiplication Compute XY, where X and Y are N-digit integers. Divide: X=XL104+XR , Y=YL104+YR Conquer and combine: XY = XLYL108 + (XLYR+ XRYL)104+XRYR CS223 Advanced Data Structures and Algorithms

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

CS223 Advanced Data Structures and Algorithms A Better Algorithm CS223 Advanced Data Structures and Algorithms

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

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

Matrix Multiplication CS223 Advanced Data Structures and Algorithms

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

CS223 Advanced Data Structures and Algorithms A Better Algorithm CS223 Advanced Data Structures and Algorithms

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