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.

Slides:



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

Garfield AP Computer Science
Divide and Conquer Yan Gu. What is Divide and Conquer? An effective approach to designing fast algorithms in sequential computation is the method known.
CSC 421: Algorithm Design & Analysis
Lecture 3: Parallel Algorithm Design
A simple example finding the maximum of a set S of n numbers.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
HST 952 Computing for Biomedical Scientists Lecture 9.
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.
Divide and Conquer. Divide and Conquer is a technique for designing the algorithms that consists of decomposing the instance to be solved into a number.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
1 Sorting Algorithms (Part II) Overview  Divide and Conquer Sorting Methods.  Merge Sort and its Implementation.  Brief Analysis of Merge Sort.  Quick.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
Fundamental in Computer Science Recursive algorithms 1.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
Lecture 8. How to Form Recursive relations 1. Recap Asymptotic analysis helps to highlight the order of growth of functions to compare algorithms Common.
Sorting HKOI Training Team (Advanced)
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
CSS106 Introduction to Elementary Algorithms M.Sc Askar Satabaldiyev Lecture 05: MergeSort & QuickSort.
Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2.Solve smaller instances.
Divide and Conquer Strategy
 Design and Analysis of Algorithms تصميم وتحليل الخوارزميات (311 عال) Chapter 2 Sorting (insertion Sort, Merge Sort)
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.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
Dynamic Programming. What is Dynamic Programming  A method for solving complex problems by breaking them down into simpler sub problems. It is applicable.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Chapter 6 (Lafore’s Book) Recursion Hwajung Lee.  Definition: An algorithmic technique. To solve a problem on an instance of size n, the instance is:
3.3 Fundamentals of data representation
CMPT 438 Algorithms.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Lecture 3: Parallel Algorithm Design
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
UNIT- I Problem solving and Algorithmic Analysis
Introduction to the Design and Analysis of Algorithms
Lecture 4 Divide-and-Conquer
CSC 421: Algorithm Design & Analysis
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide and Conquer.
Intro to Recursion.
Algorithm Design Methods
Divide-and-Conquer The most-well known algorithm design strategy:
CSCE 411 Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
Unit-2 Divide and Conquer
Sorting Algorithms Ellysa N. Kosinaya.
Searching: linear & binary
Divide-and-Conquer The most-well known algorithm design strategy:
CSE 2010: Algorithms and Data Structures
Divide and Conquer Algorithms Part I
Chapter 4.
Divide-and-Conquer The most-well known algorithm design strategy:
CSC 421: Algorithm Design & Analysis
Sorting.
Divide and Conquer Neil Tang 4/24/2008
Divide & Conquer Algorithms
CSC 421: Algorithm Design & Analysis
ITEC324 Principle of CS III
Divide-and-conquer approach
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

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 a DIFFICULT task to SIMPLE task(s). Solve the simple task(s). Combine the results of simple task(s) for the original task.

A classic example: Counterfeit coin You have 9 coins, in which one is counterfeit (being lighter) You have only one balance. How can you find the counterfeit dollar?

Counterfeit dollar MINDLESS approach: Grab the first one as control, test all others with respect to the first one (i.e. the control). Best case: The 1 st or the 2 nd is counterfeit  1 weighing. Worst case: The 9 th is counterfeit  8 weighing.

R < G G < R G=R Separate the 9 coins into 3 groups, each with 3 coins. Weigh 2 groups: Repeat the same process for the suspicious group.

Best case? Worst case? Divide and Conquer usually gives us a faster approach to the problem, that ’ s why it is useful. Many well known algorithms make use of D&C to formulate. However, please be noted that D&C does not necessarily provide you the best algorithm to solve it. Shell sort, Merge sort, Quick sort, Binary Search, Interpolation Search, Cut Vertices, Cut Edges, etc …

Difficult problem Sub Task 1Sub Task 2Sub Task n … Recombination Sub Tasks must be simpler Solution readily known or obtained by D&C again. Sol n of Task 1Sol n of Task 2Sol n of Task n …

Some terms:TermsMeaningRemarkD&C Divide and Conquer Problem solving technique Simpler 1. Algorithm already known Reduced problem 2. Answer already known Base cases 3. Same problem, smaller in size Recursive approach Faster Faster in worst case Best and average cases are not our main concern

L-Block Filling You are given an n X n square board, in which one cell is marked. Find a way to cover the board with L blocks. n is a power of 2  n = 2 k

L-block filling 4 smaller sub-problems

L-block filling What is the base case? It is very important to know that for any recursive approach, there must be a base case! An equally important note is that the way you design your recursion should gradually progress to your base case (s). Function Hello(n : integer) : Integer; Begin If n = 1 Then Hello := n Else Hello := Hello(n-2); End; What is the problem of this recursion?