Powering a number. More Divide & Conquer

Similar documents
Introduction to Algorithms 6.046J/18.401J

CMPS 2200 Fall Divide-and-Conquer. Carola Wenk. Slides courtesy of Charles Leiserson with changes and additions by Carola Wenk

Introduction to Algorithms 6.046J/18.401J/SMA5503

Divide-and-Conquer. Reading: CLRS Sections 2.3, 4.1, 4.2, 4.3, 28.2, CSE 6331 Algorithms Steve Lai

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

Linear Algebra Introduction

Algorithm Design and Analysis

Periodic string comparison

Semi-local string comparison

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Nondeterministic Automata vs Deterministic Automata

2. There are an infinite number of possible triangles, all similar, with three given angles whose sum is 180.

M344 - ADVANCED ENGINEERING MATHEMATICS

Ellipses. The second type of conic is called an ellipse.

Chapter 4 State-Space Planning

The Divide-and-Conquer Design Paradigm

Algorithm Design and Analysis

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Similar Right Triangles

Divide-and-conquer algorithm

Section 2.3. Matrix Inverses

Maintaining Mathematical Proficiency

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Intermediate Math Circles Wednesday 17 October 2012 Geometry II: Side Lengths

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Bases for Vector Spaces

Chapter 8 Roots and Radicals

( ) { } [ ] { } [ ) { } ( ] { }

CSE 521: Design and Analysis of Algorithms I

Hybrid Systems Modeling, Analysis and Control

GRAND PLAN. Visualizing Quaternions. I: Fundamentals of Quaternions. Andrew J. Hanson. II: Visualizing Quaternion Geometry. III: Quaternion Frames

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

APPLICATION OF STRASSEN S ALGORITHM IN RHOTRIX ROW-COLUMN MULTIPLICATION

Lecture 20: Numerical Integration III

Matrix Multiplication

Lecture 19: Continuous Least Squares Approximation

Matrices SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics (c) 1. Definition of a Matrix

A Lower Bound for the Length of a Partial Transversal in a Latin Square, Revised Version

CPS 616 DIVIDE-AND-CONQUER 6-1

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Engineering Analysis ENG 3420 Fall Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00

Logic Synthesis and Verification

The Ellipse. is larger than the other.

Data Structures and Algorithms CMPSC 465

Polynomials. Polynomials. Curriculum Ready ACMNA:

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

2.4 Linear Inequalities and Interval Notation

CSE 332. Sorting. Data Abstractions. CSE 332: Data Abstractions. QuickSort Cutoff 1. Where We Are 2. Bounding The MAXIMUM Problem 4

Determinants Chapter 3

Symmetrical Components 1

Stage 11 Prompt Sheet

Homework 5 solutions

PHYS 1114, Lecture 1, January 18 Contents:

1 Caveats of Parallel Algorithms

Data Structures and Algorithm. Xiaoqing Zheng

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Introduction to Olympiad Inequalities

Tutorials. Algorithms and Data Structures Strassen s Algorithm. The Master Theorem for solving recurrences. The Master Theorem (cont d)

Implication Graphs and Logic Testing

Calculus Cheat Sheet. Integrals Definitions. where F( x ) is an anti-derivative of f ( x ). Fundamental Theorem of Calculus. dx = f x dx g x dx

GM1 Consolidation Worksheet

1 Error Analysis of Simple Rules for Numerical Integration

Surds and Indices. Surds and Indices. Curriculum Ready ACMNA: 233,

Quadratic Forms. Quadratic Forms

Chapter 2. Recurrence Relations. Divide and Conquer. Divide and Conquer Strategy. Another Example: Merge Sort. Merge Sort Example. Merge Sort Example

Lecture Notes No. 10

The Master Theorem for solving recurrences. Algorithms and Data Structures Strassen s Algorithm. Tutorials. The Master Theorem (cont d)

Homework Assignment 6 Solution Set

The Area of a Triangle

03 Qudrtic Functions Completing the squre: Generl Form f ( x) x + x + c f ( x) ( x + p) + q where,, nd c re constnts nd 0. (i) (ii) (iii) (iv) *Note t

1 cos. cos cos cos cos MAT 126H Solutions Take-Home Exam 4. Problem 1

Numbers and indices. 1.1 Fractions. GCSE C Example 1. Handy hint. Key point

Algorithm Design and Analysis

5. Every rational number have either terminating or repeating (recurring) decimal representation.

12.4 Similarity in Right Triangles

Where did dynamic programming come from?

Automatic Synthesis of New Behaviors from a Library of Available Behaviors

Surface maps into free groups

First Midterm Examination

Laboratory for Foundations of Computer Science. An Unfolding Approach. University of Edinburgh. Model Checking. Javier Esparza

QUADRATIC EQUATION. Contents

Reference : Croft & Davison, Chapter 12, Blocks 1,2. A matrix ti is a rectangular array or block of numbers usually enclosed in brackets.

6. Suppose lim = constant> 0. Which of the following does not hold?

Math 154B Elementary Algebra-2 nd Half Spring 2015

Individual Group. Individual Events I1 If 4 a = 25 b 1 1. = 10, find the value of.

Divide and Conquer Strategy

Math 32B Discussion Session Week 8 Notes February 28 and March 2, f(b) f(a) = f (t)dt (1)

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30,

5: The Definite Integral

Linear Programming and Halfplane Intersection

7-1: Zero and Negative Exponents

Learning Objectives of Module 2 (Algebra and Calculus) Notes:

Fast Convolution; Strassen s Method

Matrix Algebra. Matrix Addition, Scalar Multiplication and Transposition. Linear Algebra I 24

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

THE JOHN ELLIPSOID THEOREM. The following is a lecture given in the functional analysis seminar at the University of South Carolina.

HOMEWORK FOR CLASS XII ( )

Searching. Sorting. Lambdas

Logic Synthesis and Verification

Transcription:

CS 4 -- Spring 29 Powering numer Prolem: Compute n, where n N. Nive lgorithm: Θ(n). ore Divide & Conquer Crol Wenk Slides ourtesy of Chrles Leiserson with smll hnges y Crol Wenk 2//9 CS 4 nlysis of lgorithms Divide-nd-onquer lgorithm: (reursive squring) n/2 n/2 if n is even; n = (n )/2 (n )/2 if n is odd. T(n) = T(n/2) + Θ() T(n) = Θ(log n). 2//9 CS 4 nlysis of lgorithms 2 Fioni numers Reursive definition: if n = ; F n = if n = ; F n + F n 2 if n 2. 2 8 2 4 L Nive reursive lgorithm: Ω(φ n ) (exponentil time), where φ = ( + )/2 is the golden rtio. 2//9 CS 4 nlysis of lgorithms Computing Fioni numers Nive reursive squring: F n = φ n / rounded to the nerest integer. Reursive squring: Θ(log n) time. This method is unrelile, sine floting-point rithmeti is prone to round-off errors. ottom-up (one-dimensionl dynmi progrmming): Compute F, F, F 2,, F n in order, forming eh numer y summing the two previous. Running time: Θ(n). 2//9 CS 4 nlysis of lgorithms 4

Convex Hull Convex Hull: Divide & Conquer Given set of pins on pinord nd ruer nd round them How does the ruer nd look when it snps tight? We represent onvex hull s the sequene of points on the onvex hull polygon, in ounter-lokwise order. 6 4 2 Preproessing: sort the points y x- oordinte Divide the set of points into two sets nd : ontins the left n/2 points, ontins the right n/2 points Reursively ompute the onvex hull of Reursively ompute the onvex hull of erge the two onvex hulls 2//9 CS 4 nlysis of lgorithms 2//9 CS 4 nlysis of lgorithms 6 erging Finding the lower tngent Find upper nd lower tngent With those tngents the onvex hull of n e omputed from the onvex hulls of nd the onvex hull of in O(n) liner time = rightmost point of = leftmost point of while T= not lower tngent to oth onvex hulls of nd do{ while T not lower tngent to onvex hull of do{ =- while T not lower tngent to onvex hull of do{ =+ n e heked in onstnt time 4 =2 4= 6 7 2 right turn or left turn? 2//9 CS 4 nlysis of lgorithms 7 2//9 CS 4 nlysis of lgorithms 8

Convex Hull: Runtime Convex Hull: Runtime Preproessing: sort the points y x- oordinte Divide the set of points into two sets nd : ontins the left n/2 points, ontins the right n/2 points Reursively ompute the onvex hull of Reursively ompute the onvex hull of erge the two onvex hulls O(n log n) just one O() T(n/2) T(n/2) O(n) Runtime Reurrene: T(n) = 2 T(n/2) + n Solves to T(n) = Θ(n log n) 2//9 CS 4 nlysis of lgorithms 9 2//9 CS 4 nlysis of lgorithms n trix multiplition Input: = [ ij ], = [ ij ]. Output: C = [ ij ] =. 2 2 L n L = 2 O L nn n ij = 2 n L n L 2 O L nn n 2//9 CS 4 nlysis of lgorithms ik k= kj i, j =, 2,, n. 2 L n L O L nn Stndrd lgorithm for i to n do for j to n do ij for k to n do ij ij + ik kj Running time = Θ(n ) 2//9 CS 4 nlysis of lgorithms 2

Divide-nd-onquer lgorithm IDE: n n mtrix = 2 2 mtrix of (n/2) (n/2) sumtries: r = e+ g s = f+ h t = e+d g u = f +d h r t s = u e d g C = f h 8 reursive mults of (n/2) (n/2) sumtries 4 dds of (n/2) (n/2) sumtries 2//9 CS 4 nlysis of lgorithms nlysis of D&C lgorithm # sumtries T(n) = 8 T(n/2) + Θ(n 2 ) sumtrix size work dding sumtries n log = n log 2 8 = n CSE T(n) = Θ(n ). No etter thn the ordinry lgorithm. 2//9 CS 4 nlysis of lgorithms 4 Strssen s ide ultiply 2 2 mtries with only 7 reursive mults. P = ( f h) P 2 = ( + ) h P = ( + d) e P 4 = d (g e) P = ( + d) (e + h) P 6 = ( d) (g + h) P 7 = ( ) (e + f ) r = P + P 4 P 2 + P 6 s = P + P 2 t = P + P 4 u = P + P P P 7 7 mults, 8 dds/sus. Note: No reline on ommuttivity of mult! Strssen s ide ultiply 2 2 mtries with only 7 reursive mults. P = ( f h) P 2 = ( + ) h P = ( + d) e P 4 = d (g e) P = ( + d) (e + h) P 6 = ( d) (g + h) P 7 = ( ) (e + f ) r = P + P 4 P 2 + P 6 =( + d)(e + h) + d (g e) ( + ) h + ( d)(g + h) = e + h + de + dh + dg de h h + g + h dg dh = e + g 2//9 CS 4 nlysis of lgorithms 2//9 CS 4 nlysis of lgorithms 6

Strssen s lgorithm. Divide: Prtition nd into (n/2) (n/2) sumtries. Form P-terms to e multiplied using + nd. 2. Conquer: Perform 7 multiplitions of (n/2) (n/2) sumtries reursively.. Comine: Form C using + nd on (n/2) (n/2) sumtries. T(n) = 7 T(n/2) + Θ(n 2 ) 2//9 CS 4 nlysis of lgorithms 7 nlysis of Strssen T(n) = 7 T(n/2) + Θ(n 2 ) n log = n log 2 7 n 2.8 CSE T(n) = Θ(n log 7 ). The numer 2.8 my not seem muh smller thn, ut euse the differene is in the exponent, the impt on running time is signifint. In ft, Strssen s lgorithm ets the ordinry lgorithm on tody s mhines for n or so. est to dte (of theoretil interest only): Θ(n 2.76L ). 2//9 CS 4 nlysis of lgorithms 8 Conlusion Divide nd onquer is just one of severl powerful tehniques for lgorithm design. Divide-nd-onquer lgorithms n e nlyzed using reurrenes nd the mster method (so prtie this mth). Cn led to more effiient lgorithms 2//9 CS 4 nlysis of lgorithms 9