Divide and Conquer.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

MATH 224 – Discrete Mathematics
CS 206 Introduction to Computer Science II 02 / 27 / 2009 Instructor: Michael Eckmann.
Lecture 3: Parallel Algorithm Design
Types of Algorithms.
Lecture 10 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Instructor: Shengyu Zhang 1. Example 1: Merge sort 2.
Algorithms Recurrences. Definition – a recurrence is an equation or inequality that describes a function in terms of its value on smaller inputs Example.
Algorithm Strategies Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 4 Some of the sides are exported from different sources.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Topic 9B – Array Sorting and Searching
CS 206 Introduction to Computer Science II 10 / 08 / 2008 Instructor: Michael Eckmann.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
CSCE350 Algorithms and Data Structure Lecture 17 Jianjun Hu Department of Computer Science and Engineering University of South Carolina
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Data Structures and Algorithms A. G. Malamos
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Solving Polynomial Functions involving Complex Numbers.
A Different Solution  alternatively we can use the following algorithm: 1. if n == 0 done, otherwise I. print the string once II. print the string (n.
CMPT 238 Data Structures More on Sorting: Merge Sort and Quicksort.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
NUMERICAL ANALYSIS I. Introduction Numerical analysis is concerned with the process by which mathematical problems are solved by the operations.
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Algorithm Design Techniques, Greedy Method – Knapsack Problem, Job Sequencing, Divide and Conquer Method – Quick Sort, Finding Maximum and Minimum, Dynamic.
3.3 Fundamentals of data representation
Introduction to Algorithms: Divide-n-Conquer Algorithms
Introduction to Algorithms
Lecture 3: Parallel Algorithm Design
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Modeling with Recurrence Relations
Decrease-and-Conquer Approach
Recursion notes Chapter 8.
Chapter 4 Divide-and-Conquer
MA/CSSE 473 Day 17 Divide-and-conquer Convex Hull
Introduction Algorithms Order Analysis of Algorithm
Chapter 6 Transform-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Hubert Chan (Chapters 1.6, 1.7, 4.1)
Divide and Conquer.
Binary and Ternary Search
CS 3343: Analysis of Algorithms
Types of Algorithms.
Orthogonal Range Searching and Kd-Trees
Divide-and-Conquer The most-well known algorithm design strategy:
Searching CSCE 121 J. Michael Moore.
CSCE 411 Design and Analysis of Algorithms
CS 3343: Analysis of Algorithms
Chapter 6 Transform and Conquer.
Types of Algorithms.
Divide-and-Conquer The most-well known algorithm design strategy:
Recurrences (Method 4) Alexandra Stefan.
Solving Recurrence Relations
Divide-and-Conquer The most-well known algorithm design strategy:
Incremental Problem Solving for CS1100
CSC 380: Design and Analysis of Algorithms
Types of Algorithms.
CPS120: Introduction to Computer Science
Divide & Conquer Algorithms
CPS120: Introduction to Computer Science
CSC 380: Design and Analysis of Algorithms
David Kauchak cs161 Summer 2009
Divide and Conquer Merge sort and quick sort Binary search
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

Divide and Conquer

Divide and Conquer Probably most well-known technique in Computer Science Basis for many common algorithms Binary search Quicsort/Mergesort Tree data structures Numerous individual/specialized algorithms Basic idea Split problem into one or more smaller problems Solve the smaller (simpler) problem If needed, combine results from smaller problems to get answer Generally reduces O(n) to O(lg n)

Binary Search: the basic algorithm Also called “Decrease and Conquer” since you have just one subproblem Can be used any time there is a sorted range to search over Typical case: an array of sorted values More general case: a range of discrete values Can be thought of as an array with 1 of each Even more general case: a range of continuous values General idea here is root finding

Root Finding as Binary Search Also called bisection Idea is to find the “zero” of a function Need “transverse” intersection of the function – transition between positive and negative Assumes all positive on one side, all negative on the other. The “function” could be a complex problem that is not as easy to analyze e.g. it fails below some value or succeeds above some value. Can perform binary search on the values Take middle value, determine if positive or negative Keep half the interval remaining Should stop in some tolerance of exact answer If you know the range you begin with and the tolerance, you know exactly how many evaluations you will need!

Another example: computing powers If you need to compute xn, could do it with n multiplications But, it is faster to compute xn/2 * xn/2 Need to account for the cases where n is odd: x*xn/2*xn/2 More generally, notice that x can be things other than numbers (e.g. a matrix) and * does not have to be standard multiplication

One more example: binary search a data structure Can sometimes convert one data structure to another that is easier to search Valuable if you will perform multiple searches Searches can be made binary instead of linear Example: generate lists for all paths in tree from root to leaves Creates large set of lists But, can search those lists in O(lg n) time, once created See book example in 3.3.1 for generating lists