Data Structures and Algorithms

Similar documents
4.3 Growth Rates of Solutions to Recurrences

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

Algorithms and Data Structures Lecture IV

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

) n. ALG 1.3 Deterministic Selection and Sorting: Problem P size n. Examples: 1st lecture's mult M(n) = 3 M ( È

Data Structures Lecture 9

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

Model of Computation and Runtime Analysis

Analysis of Algorithms -Quicksort-

Algorithms Design & Analysis. Divide & Conquer

Model of Computation and Runtime Analysis

Average-Case Analysis of QuickSort

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Data Structures and Algorithm. Xiaoqing Zheng

Test One (Answer Key)

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Analysis of Algorithms. Introduction. Contents

Similar idea to multiplication in N, C. Divide and conquer approach provides unexpected improvements. Naïve matrix multiplication

Fundamental Algorithms

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

Examples: data compression, path-finding, game-playing, scheduling, bin packing

COMP285 Midterm Exam Department of Mathematics

CS / MCS 401 Homework 3 grader solutions

Merge and Quick Sort

Real Variables II Homework Set #5

COMP26120: More on the Complexity of Recursive Programs (2018/19) Lucas Cordeiro

Mathematics review for CSCI 303 Spring Department of Computer Science College of William & Mary Robert Michael Lewis

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

Lecture 4 Recursive Algorithm Analysis. Merge Sort Solving Recurrences The Master Theorem

Chapter 6. Advanced Counting Techniques

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

Math 155 (Lecture 3)

Recurrence Relations

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

Algorithm Analysis. Chapter 3

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Sums, products and sequences

Chapter 2. Asymptotic Notation

Exponential Functions and Taylor Series

2. ALGORITHM ANALYSIS

MA131 - Analysis 1. Workbook 2 Sequences I

Section 1 of Unit 03 (Pure Mathematics 3) Algebra

Solutions to Final Exam

Discrete Mathematics Recurrences

Advanced Course of Algorithm Design and Analysis

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

Design and Analysis of Algorithms

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

CSE 202 Homework 1 Matthias Springer, A Yes, there does always exist a perfect matching without a strong instability.

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University

6.046 Recitation 5: Binary Search Trees Bill Thies, Fall 2004 Outline

CS 5150/6150: Assignment 1 Due: Sep 23, 2010

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

10.1 Sequences. n term. We will deal a. a n or a n n. ( 1) n ( 1) n 1 2 ( 1) a =, 0 0,,,,, ln n. n an 2. n term.

Recurrences: Methods and Examples

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

Machine Learning for Data Science (CS 4786)

6.3 Testing Series With Positive Terms

COMM 602: Digital Signal Processing

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

An Introduction to Randomized Algorithms

Math 451: Euclidean and Non-Euclidean Geometry MWF 3pm, Gasson 204 Homework 3 Solutions

Merge Sort. Outline and Reading. Divide-and-Conquer. Divide-and-conquer paradigm ( 4.1.1) Merge-sort ( 4.1.1)

MATH 1910 Workshop Solution

Lecture 23 Rearrangement Inequality

TR/46 OCTOBER THE ZEROS OF PARTIAL SUMS OF A MACLAURIN EXPANSION A. TALBOT

Math 299 Supplement: Real Analysis Nov 2013

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 12

CS537. Numerical Analysis and Computing

Lecture 4 Recursive Algorithm Analysis. Merge Sort Solving Recurrences The Master Theorem

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 19 11/17/2008 LAWS OF LARGE NUMBERS II THE STRONG LAW OF LARGE NUMBERS

MA541 : Real Analysis. Tutorial and Practice Problems - 1 Hints and Solutions

Read carefully the instructions on the answer book and make sure that the particulars required are entered on each answer book.

3.2 Properties of Division 3.3 Zeros of Polynomials 3.4 Complex and Rational Zeros of Polynomials

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

NEW FAST CONVERGENT SEQUENCES OF EULER-MASCHERONI TYPE

The picture in figure 1.1 helps us to see that the area represents the distance traveled. Figure 1: Area represents distance travelled

MATH 324 Summer 2006 Elementary Number Theory Solutions to Assignment 2 Due: Thursday July 27, 2006

3. Z Transform. Recall that the Fourier transform (FT) of a DT signal xn [ ] is ( ) [ ] = In order for the FT to exist in the finite magnitude sense,

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

Math 475, Problem Set #12: Answers

MATHEMATICS. 61. The differential equation representing the family of curves where c is a positive parameter, is of

LINEAR RECURSION RELATIONS - LESSON FOUR SECOND-ORDER LINEAR RECURSION RELATIONS

5. Solving recurrences

Linear Regression Demystified

You may work in pairs or purely individually for this assignment.

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced

CHAPTER 1 SEQUENCES AND INFINITE SERIES

Definition An infinite sequence of numbers is an ordered set of real numbers.

Math 113 Exam 3 Practice

Lecture 6 Chi Square Distribution (χ 2 ) and Least Squares Fitting

Lesson 10: Limits and Continuity

Solutions to Math 347 Practice Problems for the final

Transcription:

Data Structures ad Algorithms Autum 2017-2018

Outlie 1 Sortig Algorithms (cotd)

Outlie Sortig Algorithms (cotd) 1 Sortig Algorithms (cotd)

Heapsort Sortig Algorithms (cotd) Have see that we ca build a heap i liear time usig /2 calls of trickledow() If we ow call deletemi() times, we will get the elemets i smallest-to-largest (o-decreasig) order Where to store them as we peel them off? Do we eed a extra array? No Each time a deletemi() is called, place the result i the slot just opeed up by the shruk array Problem with this is that after deletemi()s the elemets ow appear largest-to-smallest (o-icreasig) Two solutios: 1 Use a (max)heap with the deletemax() operatio 2 After the deletemi()s reverse the cotets of the array to get it smallest-to-largest; reversig a array ca be doe i O()-time usig just O(1) additioal storage

Mergesort Sortig Algorithms (cotd) Mergesort strategy: To sort a array of umbers Sort the first half of the array Sort the secod half of the array Merge the two halves of the array Ruig time aalysis: Sortig a array comprisig oe elemet takes uit time To sort umbers we perform two sorts o /2 umbers ad the merge the resultig arrays Mergig two arrays of legth /2 each takes time sice we ca make oe (sychroised) pass over the two halves, copyig the appropriate elemet as we go

Mergesort (cotd) Sortig Algorithms (cotd) 2 2 2 k 2 k 2 2 2 + 2 2 2 + + + i=0 2 2 2 k O 0 () O 1 () O 2 () + + + + = O 2 k k=lg () ( k ) ( k ) = O 2 i = O( lg ) 2 i O = O(k ) i=0 = = = + + + +

Mergesort (cotd) Sortig Algorithms (cotd) Recurrece relatio: T (1) = 1 T () = 2T (/2) + Assume is a power of 2 ( = 2 k, k = log ) Ca argue the, that if is ot a power of 2, it falls betwee two powers of two: 2 k < < 2 k Two techiques to solvig the recurrece T () = 2T (/2) +

Mergesort Solutio 1 Divide through by, T () ad lettig T () = T ()/ = T (/2) 2 T () = T (/2) + 1 + 1 = T (/4) + 1 + 1 Thus, = T (1) + 1 + + 1 }{{} k T () = T ()/ = 1 + log T () = + log = O( log )

Mergesort Solutio 2 Therefore T () = 2T (/2) +, ad so, T (/2) = 2T (/4) + /2 T () = 2(2T (/4) + /2) + = 4T (/4) + 2 T () = 2 k T (/2 k ) + k Whe k = log, /2 k = 1 (sice = 2 k for some k) T () = T (1) + log = + log = O( log )

Did you kow? Sortig Algorithms (cotd) a log c = (c log c a ) log c = c log c a log c = c log c log c a = (c log c ) log c a = log c a I summary a log c = log c a

Outlie Sortig Algorithms (cotd) 1 Sortig Algorithms (cotd)

Geeral Solutios to Divide ad Coquer How do we solve recurreces of the form T () = at ( c ) + b T (1) = b Sice we are dividig by c, we will assume that is a power of c; that is, = c k or, k = log c Of course, this is ot the case i geeral but it is always the case that is sadwiched betwee two adjacet powers of c: c k c k+1

Geeral Solutios to Divide ad Coquer (cotd) T () = at ( c ) + b = a[at ( c 2 ) + b c ] + b = a 2 T ( c 2 ) + b a c + b = a 2 [at ( c 3 ) + b c 2 ] + b a c + b = a 3 T ( c 3 ) + b a2 c 2 + b a c + b = a log c T (1) + b[ alogc 1 c logc 1 + + a c + 1]

Geeral Solutios to Divide ad Coquer (cotd) T () = a log c T (1) + b log c 1 i=0 = a log c b log c 1 + b = b alog c c log c + b = b log c i=0 ( a c ) i i=0 log c 1 i=0 [( a ) logc ] +1 c 1 = b a c 1, ( a c ) i ( a c ( a c ) i, sice T (1) = b ) i, sice c log c = a c 1

Geeral Solutios to Divide ad Coquer (cotd) There are three cases to cosider with this expressio for T () ❶ a = c (eg mergesort; Alg 3 of MSS) ❷ a < c (quickselect() (described later)) ❸ a > c (Strasse matrix mult alg, a = 7, c = 2) I each case we will reduce the expressio as much as we ca ad the argue that sice is always bouded from above ad below by a power of c, the T () will be Θ of the fuctio of that we derive See also the Master Theorem page o Wikipedia

Geeral Solutios to Divide ad Coquer (cotd) Case ❶ a c = 1 (a = c) the T () = b [log c + 1] = Θ( log c )

Geeral Solutios to Divide ad Coquer (cotd) Case ❷ a c < 1 (a < c) the ( a ) logc +1 lim 0 c b [( a c ) logc ] +1 1 a c 1 ) logc +1 [ ( 1 a c = b 1 a c [ ] 1 b c a c = b c c a = Θ() ]

Geeral Solutios to Divide ad Coquer (cotd) Case ❸ a c > 1 (a > c) the ( a ) logc +1 lim c so the remaiig terms are isigificat, ad the ruig time should grow very rapidly Usig the Did you kow? fact, a log c = log c a ( a ) logc +1 T () = b c = b a ( a ) logc c c = ab c logc a = Θ( log c a )

Related Recurreces What if, istead of b work beig required at every level of recursio, it was a more geeral (complicated) expressio? For example, what about solvig where f () =, say? T () = at (/c) + f () The two Extra otes 1 liks i Week08 of the class resource matrix discuss recursio ad more geeral recurreces that arise The recurrece tree i the secod lik is a very useful way of thikig about solvig recurreces 1 With thaks to Jeff Erickso, Uiversity of Illiois, USA