Recitation 1. Solving Recurrences. 1.1 Announcements. Welcome to 15210!

Similar documents
Maximum Contiguous Subsequences

Lecture 4: Divide and Conquer

On the Optimality of a Family of Binary Trees Techical Report TR

CSE 21 Winter 2016 Homework 6 Due: Wednesday, May 11, 2016 at 11:59pm. Instructions

2 all subsequent nodes. 252 all subsequent nodes. 401 all subsequent nodes. 398 all subsequent nodes. 330 all subsequent nodes

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Introduction to Greedy Algorithms: Huffman Codes

Probability. An intro for calculus students P= Figure 1: A normal integral

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

MAC Learning Objectives. Learning Objectives (Cont.)

Fibonacci Heaps Y Y o o u u c c an an s s u u b b m miitt P P ro ro b blle e m m S S et et 3 3 iin n t t h h e e b b o o x x u u p p fro fro n n tt..

MA 1125 Lecture 05 - Measures of Spread. Wednesday, September 6, Objectives: Introduce variance, standard deviation, range.

Chapter 16. Binary Search Trees (BSTs)

Numerical Descriptive Measures. Measures of Center: Mean and Median

Chapter 15: Dynamic Programming

Fundamental Algorithms - Surprise Test

Sublinear Time Algorithms Oct 19, Lecture 1

AVL Trees. The height of the left subtree can differ from the height of the right subtree by at most 1.

Optimization Prof. A. Goswami Department of Mathematics Indian Institute of Technology, Kharagpur. Lecture - 18 PERT

Microeconomics of Banking: Lecture 5

Yao s Minimax Principle

Max Registers, Counters and Monotone Circuits

Homework #4. CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class

CMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS

The Binomial Theorem. Step 1 Expand the binomials in column 1 on a CAS and record the results in column 2 of a table like the one below.

COMP Analysis of Algorithms & Data Structures

Outline for this Week

Successor. CS 361, Lecture 19. Tree-Successor. Outline

CSCE 750, Fall 2009 Quizzes with Answers

Outline for this Week

Empirical and Average Case Analysis

Harvard School of Engineering and Applied Sciences CS 152: Programming Languages

Data Structures and Algorithms February 10, 2007 Pennsylvania State University CSE 465 Professors Sofya Raskhodnikova & Adam Smith Handout 10

CEC login. Student Details Name SOLUTIONS

CS227-Scientific Computing. Lecture 6: Nonlinear Equations

On the Optimality of a Family of Binary Trees

Outline for Today. Quick refresher on binomial heaps and lazy binomial heaps. An important operation in many graph algorithms.

Week 2 Quantitative Analysis of Financial Markets Hypothesis Testing and Confidence Intervals

Approximate Revenue Maximization with Multiple Items

The two meanings of Factor

Lecture 17: More on Markov Decision Processes. Reinforcement learning

lecture 31: The Secant Method: Prototypical Quasi-Newton Method

Econ 551 Government Finance: Revenues Winter 2018

CS473-Algorithms I. Lecture 12. Amortized Analysis. Cevdet Aykanat - Bilkent University Computer Engineering Department

15-451/651: Design & Analysis of Algorithms October 23, 2018 Lecture #16: Online Algorithms last changed: October 22, 2018

Equalities. Equalities

Lecture 5: Tuesday, January 27, Peterson s Algorithm satisfies the No Starvation property (Theorem 1)

Mixed Strategies. Samuel Alizon and Daniel Cownden February 4, 2009

Developmental Math An Open Program Unit 12 Factoring First Edition

Economics 101 Fall 2016 Answers to Homework #1 Due Thursday, September 29, 2016

1 Overview. 2 The Gradient Descent Algorithm. AM 221: Advanced Optimization Spring 2016

SET 1C Binary Trees. 2. (i) Define the height of a binary tree or subtree and also define a height balanced (AVL) tree. (2)

Textbook: pp Chapter 11: Project Management

APPM 2360 Project 1. Due: Friday October 6 BEFORE 5 P.M.

FINITE MATH LECTURE NOTES. c Janice Epstein 1998, 1999, 2000 All rights reserved.

6.042/18.062J Mathematics for Computer Science November 30, 2006 Tom Leighton and Ronitt Rubinfeld. Expected Value I

X ln( +1 ) +1 [0 ] Γ( )

LECTURE 2: MULTIPERIOD MODELS AND TREES

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.265/15.070J Fall 2013 Lecture 19 11/20/2013. Applications of Ito calculus to finance

Proof Techniques for Operational Semantics. Questions? Why Bother? Mathematical Induction Well-Founded Induction Structural Induction

A very simple model of a limit order book

Asymptotic results discrete time martingales and stochastic algorithms

ECON 459 Game Theory. Lecture Notes Auctions. Luca Anderlini Spring 2017

Algorithmic Game Theory and Applications. Lecture 11: Games of Perfect Information

Lecture 5 Leadership and Reputation

IEOR E4004: Introduction to OR: Deterministic Models

Fibonacci Heaps CLRS: Chapter 20 Last Revision: 21/09/04

Finding the Sum of Consecutive Terms of a Sequence

15-451/651: Design & Analysis of Algorithms November 9 & 11, 2015 Lecture #19 & #20 last changed: November 10, 2015

FE670 Algorithmic Trading Strategies. Stevens Institute of Technology

Pro Strategies Help Manual / User Guide: Last Updated March 2017

Interpolation. 1 What is interpolation? 2 Why are we interested in this?

Issues. Senate (Total = 100) Senate Group 1 Y Y N N Y 32 Senate Group 2 Y Y D N D 16 Senate Group 3 N N Y Y Y 30 Senate Group 4 D Y N D Y 22

CS599: Algorithm Design in Strategic Settings Fall 2012 Lecture 6: Prior-Free Single-Parameter Mechanism Design (Continued)

Mohammad Hossein Manshaei 1394

Unit 3: Writing Equations Chapter Review

Math 101, Basic Algebra Author: Debra Griffin

Wage Determinants Analysis by Quantile Regression Tree

Lecture l(x) 1. (1) x X

Terminology. Organizer of a race An institution, organization or any other form of association that hosts a racing event and handles its financials.

CSE 100: TREAPS AND RANDOMIZED SEARCH TREES

Homework Assignment #3. 1 Demonstrate how mergesort works when sorting the following list of numbers:

5.6 Special Products of Polynomials

Charter Savings Bank Cash ISAs

Monetary Economics Measuring Asset Returns. Gerald P. Dwyer Fall 2015

Elementary Statistics

PROFITING WITH FOREX: BONUS REPORT

Module 4: Point Estimation Statistics (OA3102)

Descriptive Statistics (Devore Chapter One)

Chapter 6.1: Introduction to parabolas and solving equations by factoring

Advanced Numerical Methods

Copyright 1973, by the author(s). All rights reserved.

THE TRAVELING SALESMAN PROBLEM FOR MOVING POINTS ON A LINE

We begin, however, with the concept of prime factorization. Example: Determine the prime factorization of 12.

CS 3331 Numerical Methods Lecture 2: Functions of One Variable. Cherung Lee

16 MAKING SIMPLE DECISIONS

Design and Analysis of Algorithms 演算法設計與分析. Lecture 8 November 16, 2016 洪國寶

The days ahead or the daze ahead?

Best Reply Behavior. Michael Peters. December 27, 2013

4.3 The money-making machine.

Transcription:

Recitation 1 Solving Recurrences 1.1 Announcements Welcome to 1510! The course website is http://www.cs.cmu.edu/ 1510/. It contains the syllabus, schedule, library documentation, staff contact information, and other useful resources. We will be using Piazza (https://piazza.com/ as a hub for course announcements and general questions pertaining to the course. Please check it frequently to make sure you don t miss anything. The office hours schedule is posted on the course website as well as Piazza. Come meet all of your TAs! The first homework assignment, IntegralLab, has been released! It s due Friday at 5pm, but don t worry it s quite short. Homeworks will be distributed through Autolab (https://autolab.andrew.cmu. edu/. Most homework assignments will be released on Fridays and will be due one week later. You will submit coding tasks on Autolab. This semester, we will begin integrating Diderot (https://diderot-cmu.appspot. com/ into the course. Interactive lecture notes will be available on Diderot, as well as possibly written assignments. 1

RECITATION 1. SOLVING RECURRENCES 1. The Tree Method The cost analysis of our algorihms usually comes down to finding a closed form for a recurrence. Using the tree method to derive the closed form consists of finding a cost bound for each level of the recursion tree and then summing the costs over the levels. Task 1.1. Using the tree method, solve the following recurrences: f(n = 4f + n f(n = f(n 1 + 1 f(n = f + n 1 4 f(n = 4f + n Counting from level i = 0 at the root, the ith level of the recursion tree has 4 i nodes. Each of these nodes performs i work. Thus, each level i of the tree has a cost of 4 i i = n. Summing up across log n levels as the problem size decreases by every time, we obtain the final answer: log n 1 i=0 n = n log n Θ(n log n. f(n = f(n 1 + 1 In this recurrence, the ith level of the recursion tree has i nodes. Each of these nodes has a cost of 1. Thus, each level has a cost of i at level i. As the problem size decreases by 1 each time, there are n levels. Summing across the n levels: n 1 i=0 i = 1 n 1 = n 1 Θ( n.

1.. THE TREE METHOD 3 f(n = f + n 1 4 The ith level of the recursion tree in this example also has i nodes. Each of these nodes has a cost of i frac14. Each level then costs i i frac14, which simplifies to ( 3 4 i n 1 4. As the problem size is divided by each time, the number of levels is log n. Summing across the levels to find the closed form: log n 1 i=0 ( 3 4 i n 1 4 = n 1 4 n 1 4 1 ( 3 4 log n 1 3 4 = n 1 4 n 3 4 1 3 4 1 Θ(n. log n 1 i=0 ( 3 4 i =

4 RECITATION 1. SOLVING RECURRENCES 1.3 The Brick Method If the cost at every successive level is a multiplicative factor away from the cost of the previous level, we can use the brick method. First, determine whether the recurrence conforms to one of the three cases below and then apply the next step for that case. Otherwise, use the tree or the substitution method. Definition 1.. Balanced The cost of every level is roughly equal. With a maximum cost of L and d levels, the total cost will be O(dL. Root Dominated Each level is a constant factor smaller than the previous level. With a cost of L at the root, the total cost will be O(L. Leaf Dominated Each level is a constant factor larger than the previous level. With a cost of L d at the bottom-most (dth level, the total cost will be O(L d. Task 1.3. Solve the following recurrences using the brick method: f(n = f + n 4 f(n = f( n + log n f(n = f( n + 1 f(n = f + n 4 We start from level i = 0. The ith level of the recursion tree has i nodes. Each node has a cost of n 4 i. The cost of each level is then i n 4 i = i i n = n. Since each level has the same cost, the recursion tree is balanced. Following the definition, with n cost per level and log 4 n levels, the final answer is Θ( n log n. f(n = f( n + log n Starting at level i = 0, there is 1 node at each level. The cost of that node is log (n 1 i, or simplified 1 i log n.

1.3. THE BRICK METHOD 5 Thus, each following level has a cost of 1 root dominated. of the previous level and the recursion tree is The final result is simply the cost at the root of the tree: Θ(log n. f(n = f( n + 1 There are once more i nodes at each level i, from i = 0. The cost at each node is 1. The cost at each level is then the number of nodes: i. In other words, each following level has twice the work of the previous level. As the cost at each level geometrically increases, this recurrence is leaf dominated and the total cost is the number of leaves at the last level d, d. How many levels are there if the problem size has a square root function applied to it? When the problem size is divided and we are trying to find out the number of levels, we are solving the problem n = 1 for d where d is the lowest level. In other words, we are d solving for how many divisions we need to make until the problem size is 1. In this case, we can use the same approach, but to find when the problem size is for simplicity: n 1 d = log n 1 d = log 1 d log n = 1 log n = d log log n = d log log n The number of leaves at the log log nth level is = Θ(log n. log n; the final answer is

6 RECITATION 1. SOLVING RECURRENCES 1.4 The Substitution Method. We can also use mathematical induction to solve recurrences. If you want to go via this route (and you don t know the answer a priori, you ll need to guess the answer first and check it. Since this technique relies on guessing an answer, you can sometimes fool yourself by giving a false proof. The following are some tips: 1. Spell out the constants. Do not use big-o we need to be precise about constants, so big-o makes it super easy to fool ourselves.. Be careful that the induction goes in the right direction. 3. Add additional lower-order terms, if necessary, to make the induction go through. Task 1.4. Solve the following recurrence using (strong induction: W (n = W + O(n Theorem 1.5. Let a constant k > 0 be given. If W (n W (n/ + k n for n > 1 and W (1 k for n 1, then we can find constants κ 1 and κ such that W (n κ 1 n lg n + κ. Proof. Let κ 1 = k and κ = k. For the base case (n = 1, we check that W (1 k κ. For the inductive step (n > 1, we assume that W (n/ κ 1 n lg + κ, And we ll show that W (n κ 1 n lg n + κ. To show this, we substitute an upper bound for W (n/ from our assumption into the recurrence, yielding W (n W (n/ + k n (κ 1 n lg + κ + k n = κ 1 n(lg n 1 + κ + k n = κ 1 n lg n + κ + (k n + κ κ 1 n κ 1 n lg n + κ, where the final step follows because k n + κ κ 1 n 0 as long as n > 1.

1.5. ADDITIONAL EXERCISES 7 1.5 Additional Exercises Exercise 1.6. There is a well known deterministic linear-work algorithm for finding the kth smallest value of a set of values. It uses the median of medians as the pivot. (The median value is the value v such that if the values are sorted, v would be in the middle. You don t need to understand why the algorithm works, but to be able to analyze its costs based on a description of its steps: 1. If the input has 5 or fewer values, find the median by brute force, otherwise:. Group the input into n/5 groups of 5 and find the median of each group in parallel. 3. Find the median of the n/5 medians recursively. Call this p. 4. Use p to filter out 3/10 th s of the values in Θ(n work and Θ(log n span. 5. Recurse on the remaining 7/10 th s of the values. Task 1.7. Write down recurrences for work and span. Solve the recurrence for work in terms of Θ. Solve the recurrence for span in terms of Θ. Warning: this is pretty hard.

8 RECITATION 1. SOLVING RECURRENCES.