Divide and Conquer Chapter 6. Divide and Conquer Paradigm Divide the problem into sub-problems of smaller sizes Conquer by recursively doing the same.

Slides:



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

A simple example finding the maximum of a set S of n numbers.
Lecture 4 Divide and Conquer for Nearest Neighbor Problem
Comp 122, Spring 2004 Divide and Conquer (Merge Sort)
Chapter 6 Divide and Conquer  Introduction  Binary Search  Mergesort  The Divide and Conquer Paradigm  Quicksort  Multiplication of Large Integers.
1 Divide & Conquer Algorithms. 2 Recursion Review A function that calls itself either directly or indirectly through another function Recursive solutions.
September 12, Algorithms and Data Structures Lecture III Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Chapter 4: Divide and Conquer Master Theorem, Mergesort, Quicksort, Binary Search, Binary Trees The Design and Analysis of Algorithms.
Recursion & Merge Sort Introduction to Algorithms Recursion & Merge Sort CSE 680 Prof. Roger Crawfis.
ADA: 4. Divide/Conquer1 Objective o look at several divide and conquer examples (merge sort, binary search), and 3 approaches for calculating their.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Divide and Conquer Reading Material: Chapter 6 (except Section 6.9).
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.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
Data Structures, Spring 2004 © L. Joskowicz 1 Data Structures – LECTURE 3 Recurrence equations Formulating recurrence equations Solving recurrence equations.
Lecture 2: Divide and Conquer I: Merge-Sort and Master Theorem Shang-Hua Teng.
CS2420: Lecture 9 Vladimir Kulyukin Computer Science Department Utah State University.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
ALGORITHM ANALYSIS AND DESIGN INTRODUCTION TO ALGORITHMS CS 413 Divide and Conquer Algortihms: Binary search, merge sort.
Divide-and-Conquer1 7 2  9 4   2  2 79  4   72  29  94  4.
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],
File Organization and Processing Week 13 Divide and Conquer.
CompSci 102 Discrete Math for Computer Science April 17, 2012 Prof. Rodger.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Lecture 4 Sorting Networks. Comparator comparator.
Lecture 28 CSE 331 Nov 9, Mini project report due WED.
Divide-and-Conquer UNC Chapel HillZ. Guo. Divide-and-Conquer It’s a technique instead of an algorithm Recursive in structure – Divide the problem into.
Foundations II: Data Structures and Algorithms
2IS80 Fundamentals of Informatics Fall 2015 Lecture 6: Sorting and Searching.
 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.
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.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture3.
Algorithms Sorting – Part 3.
Lecture 2 Algorithm Analysis
Lecture 4 Sorting Networks
UNIT- I Problem solving and Algorithmic Analysis
Divide-and-Conquer 6/30/2018 9:16 AM
Algorithm Design & Analysis
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:
Growth Functions Algorithms Lecture 8
Chapter 4: Divide and Conquer
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
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
Divide and Conquer (Merge Sort)
Divide-and-Conquer 7 2  9 4   2   4   7
Trevor Brown CS 341: Algorithms Trevor Brown
Divide & Conquer Algorithms
Application: Efficiency of Algorithms II
Merge Sort Overview.
CSC 380: Design and Analysis of Algorithms
Application: Efficiency of Algorithms II
Solving recurrence equations
Recurrences.
Divide-and-Conquer 7 2  9 4   2   4   7
Divide-and-Conquer Divide: the problem into subproblems
Presentation transcript:

Divide and Conquer Chapter 6

Divide and Conquer Paradigm Divide the problem into sub-problems of smaller sizes Conquer by recursively doing the same divisions on each part until small manageable (solvable) size is reached. Combine the sub-solutions to form a solution to the original problem. Read section 6.4 for more details.

Examples of divide and Conquer Read the Recursive versions of Min-Max algorithm in Section 6.1 Binary Search algorithm in Section 6.2

Section 6.3: Top-Down MergeSort Alg. Input: A[1..n] Output: A[1..n] sorted non-decreasingly mergesort(A,1,n)

Procedure mergesort(A, low, high) If low < high then mid   (low+high)/2  mergesort(A, low, mid) mergesort(A, mid+1, high) Merge(A, low, mid, high) % seen in Ch 1 End if

View

Top-down vs Bottom-up Bottom-up: iterative, merging is done level by level from bottom to up. Top-down. Recursive, merging is done in DFS (post-order) traversal.

Analysis Theorem: Let n be a power of 2, and C(n) be the number of comparisons in top- down MergeSort on A[1..n]. Then n/2 log n  C(n)  nlog n –n +1 Proof: assume n = 2 k

Best Case C(1)=0, and C(n) = 2 C(n/2) + n/2 = 2 2 C(n/2 2 ) + 2 x n/2 2 + n/2 = 2 2 C(n/2 2 ) + 2 x n /2 = 2 3 C(n/2 3 ) x n/ x n/2 = 2 3 C(n/2 3 ) + 3 x n/2 = 2 k C(n/2 k ) + k x n/2 = 2 k C(1) + k x n/2 = n/2 log n

Worst Case C(1)=0, and C(n) = 2 C(n/2) + n-1 = 2 2 C(n/2 2 ) + n n-2 0 = 2 3 C(n/2 3 ) + n n n-2 0 = 2 k C(n/2 k ) + n-2 k n n-2 0 = k n - 2 k +1 = n log n – n + 1

Theorem Both types of MergeSort use  (n log n) They have same performance if n is a power of 2 But different if n is not a power of 2.