CPSC 490 Problem Solving in Computer Science

Size: px
Start display at page:

Download "CPSC 490 Problem Solving in Computer Science"

Transcription

1 CPSC 490 Problem Solving in Computer Science Lecture 6: Recovering Solutions from DP, Bitmask DP, Matrix Exponentiation David Zheng and Daniel Du Based on CPSC490 slides from /01/23

2 Announcements Presentations Presentation choices due Monday, January 29th Presentation dates are February 13th, 15th

3 Revisiting Knapsack You have n items, each with weight w i and value v i You can carry maximum weight W Maximize total value you can carry, taking at most one of each item. Value (v) Weight (w) If W = 9 then maximum total value = 11 Now what if we wanted to know which items we need to take to attain the maximum value? What if we wanted to minimize the number of items we took as well?

4 Backtracking in Knapsack Idea: Store how we got to the state. Value (v) Weight (w) Use an array to store the index of the last thing you took. To minimize the number of items, store also the minimum number of items you took to reach the state and update with the item you took to minimize the number of items taken.

5 Remember This Problem? How many ways are there to tile a 2 n grid with 2 1 tiles? Constraint: n 1, 000, 000 Solution: f (0) = f (1) = 1, f (n) = f (n 1) + f (n 2)

6 Problem 1 A Harder Problem How many ways are there to tile a 3 n grid with 2 1 tiles? Constraint: n 1, 000, 000 Notice that f (n) = number of ways to fill 3 n grid does not work.

7 A New Kind of DP State f (n) = number of ways to fill 3 n grid does NOT work because after filling a single column, the right most column may not be full! We need more information: configuration of the right most column! Represent right most column by a bitmask: 1 = filled, 0 = not filled.

8 Review of Bitmask and Bit Operations A bitmask represents a set: i-th bit is 1 if the i-th element is in set. In most programming languages, you have bitwise operations on integers: ^, ~, <<, >>, &, What bitwise operations correspond to these set operations? Union of two sets x and y: x y Intersection: x & y Symmetric difference: x ^ y A singleton set i: (1 << i) Checking if i x: x & (1<<i) The element in x with the smallest label: x & (-x) More bit-twiddling hacks:

9 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C

10 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C Base case: f (0, 000) = 1, f (0, z) = 0 for z 0

11 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C Base case: f (0, 000) = 1, f (0, z) = 0 for z 0 Recurrence: try to fill last unfilled column don t double count!

12 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C Base case: f (0, 000) = 1, f (0, z) = 0 for z 0 Recurrence: try to fill last unfilled column don t double count! f (k, 000) = f (k 2, 000) + f (k 1, 001) + f (k 1, 100) f (k, 001) = f (k 1, 000) + f (k 1, 110) f (k, 100) = f (k 1, 000) + f (k 1, 011) f (k, 110) = f (k 1, 001) f (k, 011) = f (k 1, 100)

13 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C Base case: f (0, 000) = 1, f (0, z) = 0 for z 0 Recurrence: try to fill last unfilled column don t double count! f (k, 000) = f (k 2, 000) + f (k 1, 001) + f (k 1, 100) f (k, 001) = f (k 1, 000) + f (k 1, 110) f (k, 100) = f (k 1, 000) + f (k 1, 011) f (k, 110) = f (k 1, 001) f (k, 011) = f (k 1, 100) Answer: f (n, 000)

14 Problem 1 Solution DP State: f (k, C) = number of ways to fill the first k columns such that column k + 1 has configuration equal to bitmask C Base case: f (0, 000) = 1, f (0, z) = 0 for z 0 Recurrence: try to fill last unfilled column don t double count! f (k, 000) = f (k 2, 000) + f (k 1, 001) + f (k 1, 100) f (k, 001) = f (k 1, 000) + f (k 1, 110) f (k, 100) = f (k 1, 000) + f (k 1, 011) f (k, 110) = f (k 1, 001) f (k, 011) = f (k 1, 100) Answer: f (n, 000) Time Complexity: O(n)

15 Problem 2 An Even Harder Problem How many ways are there to tile a 4 n grid with 2 1 tiles? Constraint: n 1, 000, 000 What about 5 n, 6 n,..., or in general k n?

16 Problem 2 An Even Harder Problem How many ways are there to tile a 4 n grid with 2 1 tiles? Constraint: n 1, 000, 000 What about 5 n, 6 n,..., or in general k n? Solution: find the recurrence with O(2 2k ) BFS!

17 Problem 3 Even Harder! How many ways are there to tile a k n grid with 2 1 tiles? Constraints: 2 k 10, 0 n 10 18

18 Skipping Recurrence Steps Quickly Consider the case of k = 2, i.e. f n = f n 1 + f n 2

19 Skipping Recurrence Steps Quickly Consider the case of k = 2, i.e. f n = f n 1 + f n 2 Expand the term f n 1 we get 2-step recurrence f n = f n 2 + f n 3 + f n 2 = 2f n 2 + f n 3

20 Skipping Recurrence Steps Quickly Consider the case of k = 2, i.e. f n = f n 1 + f n 2 Expand the term f n 1 we get 2-step recurrence f n = f n 2 + f n 3 + f n 2 = 2f n 2 + f n 3 Now use the above two formulas, we get 4-step recurrence f n = 4f n 4 + 2f n 5 + f n 4 + f n 5 = 5f n 4 + 3f n 5

21 Skipping Recurrence Steps Quickly Consider the case of k = 2, i.e. f n = f n 1 + f n 2 Expand the term f n 1 we get 2-step recurrence f n = f n 2 + f n 3 + f n 2 = 2f n 2 + f n 3 Now use the above two formulas, we get 4-step recurrence f n = 4f n 4 + 2f n 5 + f n 4 + f n 5 = 5f n 4 + 3f n 5 Do this again, we get 8-step recurrence f n = 34f n f n 9

22 Skipping Recurrence Steps Quickly Consider the case of k = 2, i.e. f n = f n 1 + f n 2 Expand the term f n 1 we get 2-step recurrence f n = f n 2 + f n 3 + f n 2 = 2f n 2 + f n 3 Now use the above two formulas, we get 4-step recurrence f n = 4f n 4 + 2f n 5 + f n 4 + f n 5 = 5f n 4 + 3f n 5 Do this again, we get 8-step recurrence f n = 34f n f n 9 This seems tedious can we automate this procedure efficiently?

23 Matrix Multiplication Why did it work? The recurrence was linear! For k = 2 [ ] [ ] [ ] 0 1 fn 2 fn 1 = 1 1 f n 1 f n In other words, [ ] n 1 [ ] [ ] 0 1 f0 fn 1 = 1 1 f 1 f n

24 Matrix Multiplication k = 3 is a bit more complicated f n 2, f n 1, f n 1, f n 1,4 = f n 1, f n 1,5 f n 1,0 f n,0 f n,1 f n,4 f n,6 f n,5

25 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time!

26 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time! If we know M, then we can square it to get M 2, but squaring that again gives M 4, and then M 8, and so on...

27 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time! If we know M, then we can square it to get M 2, but squaring that again gives M 4, and then M 8, and so on... We can compute M 2k with O(k) matrix multiplications

28 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time! If we know M, then we can square it to get M 2, but squaring that again gives M 4, and then M 8, and so on... We can compute M 2k with O(k) matrix multiplications Matrix multiplication is associative, so we can break up the exponent into sum of powers of two by using its base-2 representation: M 30 = M = M 16 M 8 M 4 M 2

29 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time! If we know M, then we can square it to get M 2, but squaring that again gives M 4, and then M 8, and so on... We can compute M 2k with O(k) matrix multiplications Matrix multiplication is associative, so we can break up the exponent into sum of powers of two by using its base-2 representation: M 30 = M = M 16 M 8 M 4 M 2 compute M 2k for 0 k log n, and then multiply the appropriate ones together in a total of O(log n) multiplications!

30 Fast Matrix Exponentiation All we need now is a way to get M n quickly in O(log n) time! If we know M, then we can square it to get M 2, but squaring that again gives M 4, and then M 8, and so on... We can compute M 2k with O(k) matrix multiplications Matrix multiplication is associative, so we can break up the exponent into sum of powers of two by using its base-2 representation: M 30 = M = M 16 M 8 M 4 M 2 compute M 2k for 0 k log n, and then multiply the appropriate ones together in a total of O(log n) multiplications! alternatively, we can use divide and conquer to also get O(log n).

31 Fast Matrix Exponentiation 1 FAST _ POW (M, n): 2 initialize A = Identity matrix 3 for k from 0 to log _2( n): 4 if n AND 2^ k!= 0: 5 A = A * M 6 M = M * M 7 return A 1 FAST _ POW _ REC (M, n): 2 if n ==0: 3 return Identity matrix 4 A = FAST _ POW _ REC (M, n /2) 5 A = A * A 6 if n is odd : 7 A = A * M 8 return A

32 Next Class Strings!

Announcements. Problem Set 6 due next Monday, February 25, at 12:50PM. Midterm graded, will be returned at end of lecture.

Announcements. Problem Set 6 due next Monday, February 25, at 12:50PM. Midterm graded, will be returned at end of lecture. Turing Machines Hello Hello Condensed Slide Slide Readers! Readers! This This lecture lecture is is almost almost entirely entirely animations that that show show how how each each Turing Turing machine

More information

Dynamic Programming( Weighted Interval Scheduling)

Dynamic Programming( Weighted Interval Scheduling) Dynamic Programming( Weighted Interval Scheduling) 17 November, 2016 Dynamic Programming 1 Dynamic programming algorithms are used for optimization (for example, finding the shortest path between two points,

More information

Lecture 2: Divide and conquer and Dynamic programming

Lecture 2: Divide and conquer and Dynamic programming Chapter 2 Lecture 2: Divide and conquer and Dynamic programming 2.1 Divide and Conquer Idea: - divide the problem into subproblems in linear time - solve subproblems recursively - combine the results in

More information

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms CompSci 102 Discrete Math for Computer Science Announcements Read for next time Chap. 3.1-3.3 Homework 3 due Tuesday We ll finish Chapter 2 first today February 7, 2012 Prof. Rodger Chap. 3.1 Algorithms

More information

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 CS17 Integrated Introduction to Computer Science Klein Contents Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018 1 Tree definitions 1 2 Analysis of mergesort using a binary tree 1 3 Analysis of

More information

Tricks of the Trade in Combinatorics and Arithmetic

Tricks of the Trade in Combinatorics and Arithmetic Tricks of the Trade in Combinatorics and Arithmetic Zachary Friggstad Programming Club Meeting Fast Exponentiation Given integers a, b with b 0, compute a b exactly. Fast Exponentiation Given integers

More information

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015 CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015 Today Registration should be done. Homework 1 due 11:59pm next Wednesday, April 8 th. Review math

More information

Dynamic Programming (CLRS )

Dynamic Programming (CLRS ) Dynamic Programming (CLRS.-.) Today we discuss a technique called dynamic programming. It is neither especially dynamic nor especially programming related. We will discuss dynamic programming by looking

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2019 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2019 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Optimisation and Operations Research

Optimisation and Operations Research Optimisation and Operations Research Lecture 12: Algorithm Analysis and Complexity Matthew Roughan http://www.maths.adelaide.edu.au/matthew.roughan/ Lecture_notes/OORII/

More information

CSI2101-W08- Recurrence Relations

CSI2101-W08- Recurrence Relations Motivation CSI2101-W08- Recurrence Relations where do they come from modeling program analysis Solving Recurrence Relations by iteration arithmetic/geometric sequences linear homogenous recurrence relations

More information

Digital Design for Multiplication

Digital Design for Multiplication Digital Design for Multiplication Norman Matloff October 15, 2003 c 2003, N.S. Matloff 1 Overview A cottage industry exists in developing fast digital logic to perform arithmetic computations. Fast addition,

More information

Quick Sort Notes , Spring 2010

Quick Sort Notes , Spring 2010 Quick Sort Notes 18.310, Spring 2010 0.1 Randomized Median Finding In a previous lecture, we discussed the problem of finding the median of a list of m elements, or more generally the element of rank m.

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo

CSE 431/531: Analysis of Algorithms. Dynamic Programming. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo CSE 431/531: Analysis of Algorithms Dynamic Programming Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Paradigms for Designing Algorithms Greedy algorithm Make a

More information

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018

CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis. Ruth Anderson Winter 2018 CSE332: Data Structures & Parallelism Lecture 2: Algorithm Analysis Ruth Anderson Winter 2018 Today Algorithm Analysis What do we care about? How to compare two algorithms Analyzing Code Asymptotic Analysis

More information

Generating Function Notes , Fall 2005, Prof. Peter Shor

Generating Function Notes , Fall 2005, Prof. Peter Shor Counting Change Generating Function Notes 80, Fall 00, Prof Peter Shor In this lecture, I m going to talk about generating functions We ve already seen an example of generating functions Recall when we

More information

Intractable Problems Part Two

Intractable Problems Part Two Intractable Problems Part Two Announcements Problem Set Five graded; will be returned at the end of lecture. Extra office hours today after lecture from 4PM 6PM in Clark S250. Reminder: Final project goes

More information

NP-Complete and Non-Computable Problems. COMP385 Dr. Ken Williams

NP-Complete and Non-Computable Problems. COMP385 Dr. Ken Williams NP-Complete and Non-Computable Problems COMP385 Dr. Ken Williams Start by doing what s necessary; then do what s possible; and suddenly you are doing the impossible. Francis of Assisi Our Goal Define classes

More information

CSCI Honor seminar in algorithms Homework 2 Solution

CSCI Honor seminar in algorithms Homework 2 Solution CSCI 493.55 Honor seminar in algorithms Homework 2 Solution Saad Mneimneh Visiting Professor Hunter College of CUNY Problem 1: Rabin-Karp string matching Consider a binary string s of length n and another

More information

Advanced topic: Space complexity

Advanced topic: Space complexity Advanced topic: Space complexity CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2016 1/28 Review: time complexity We have looked at how long it takes to

More information

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013

Big O 2/14/13. Administrative. Does it terminate? David Kauchak cs302 Spring 2013 /4/3 Administrative Big O David Kauchak cs3 Spring 3 l Assignment : how d it go? l Assignment : out soon l CLRS code? l Videos Insertion-sort Insertion-sort Does it terminate? /4/3 Insertion-sort Loop

More information

P, NP, NP-Complete, and NPhard

P, NP, NP-Complete, and NPhard P, NP, NP-Complete, and NPhard Problems Zhenjiang Li 21/09/2011 Outline Algorithm time complicity P and NP problems NP-Complete and NP-Hard problems Algorithm time complicity Outline What is this course

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 601.433/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17 12.1 Introduction Today we re going to do a couple more examples of dynamic programming. While

More information

CS173 Lecture B, November 3, 2015

CS173 Lecture B, November 3, 2015 CS173 Lecture B, November 3, 2015 Tandy Warnow November 3, 2015 CS 173, Lecture B November 3, 2015 Tandy Warnow Announcements Examlet 7 is a take-home exam, and is due November 10, 11:05 AM, in class.

More information

CSC236 Week 11. Larry Zhang

CSC236 Week 11. Larry Zhang CSC236 Week 11 Larry Zhang 1 Announcements Next week s lecture: Final exam review This week s tutorial: Exercises with DFAs PS9 will be out later this week s. 2 Recap Last week we learned about Deterministic

More information

a 1 a 2 a 3 a 4 v i c i c(a 1, a 3 ) = 3

a 1 a 2 a 3 a 4 v i c i c(a 1, a 3 ) = 3 AM 221: Advanced Optimization Spring 2016 Prof. Yaron Singer Lecture 17 March 30th 1 Overview In the previous lecture, we saw examples of combinatorial problems: the Maximal Matching problem and the Minimum

More information

Math 231E, Lecture 25. Integral Test and Estimating Sums

Math 231E, Lecture 25. Integral Test and Estimating Sums Math 23E, Lecture 25. Integral Test and Estimating Sums Integral Test The definition of determining whether the sum n= a n converges is:. Compute the partial sums s n = a k, k= 2. Check that s n is a convergent

More information

Problem Set 1. CSE 373 Spring Out: February 9, 2016

Problem Set 1. CSE 373 Spring Out: February 9, 2016 Problem Set 1 CSE 373 Spring 2016 Out: February 9, 2016 1 Big-O Notation Prove each of the following using the definition of big-o notation (find constants c and n 0 such that f(n) c g(n) for n > n o.

More information

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February) Algorithms and Data Structures 016 Week 5 solutions (Tues 9th - Fri 1th February) 1. Draw the decision tree (under the assumption of all-distinct inputs) Quicksort for n = 3. answer: (of course you should

More information

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010 Announcements CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010 Project 1 posted Section materials on using Eclipse will be very useful if you have never used

More information

COMP 382: Reasoning about algorithms

COMP 382: Reasoning about algorithms Fall 2014 Unit 4: Basics of complexity analysis Correctness and efficiency So far, we have talked about correctness and termination of algorithms What about efficiency? Running time of an algorithm For

More information

1 Sequences and Summation

1 Sequences and Summation 1 Sequences and Summation A sequence is a function whose domain is either all the integers between two given integers or all the integers greater than or equal to a given integer. For example, a m, a m+1,...,

More information

C3 Revision and Exam Answers: Simpson s Rule

C3 Revision and Exam Answers: Simpson s Rule C3 Revision and Exam Answers: Simpson s Rule Simpson s Rule is a way of accurately finding the area under a curve It is more accurate than the Trapezium Rule which we have seen before You start it the

More information

Adam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course

Adam Blank Spring 2017 CSE 311. Foundations of Computing I. * All slides are a combined effort between previous instructors of the course Adam Blank Spring 2017 CSE 311 Foundations of Computing I * All slides are a combined effort between previous instructors of the course HW 3 De-Brief HW 3 De-Brief PROOFS! HW 3 De-Brief Proofs This is

More information

11 The Max-Product Algorithm

11 The Max-Product Algorithm Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.438 Algorithms for Inference Fall 2014 11 The Max-Product Algorithm In the previous lecture, we introduced

More information

You separate binary numbers into columns in a similar fashion. 2 5 = 32

You separate binary numbers into columns in a similar fashion. 2 5 = 32 RSA Encryption 2 At the end of Part I of this article, we stated that RSA encryption works because it s impractical to factor n, which determines P 1 and P 2, which determines our private key, d, which

More information

Basic Principles of Algebra

Basic Principles of Algebra Basic Principles of Algebra Algebra is the part of mathematics dealing with discovering unknown numbers in an equation. It involves the use of different types of numbers: natural (1, 2, 100, 763 etc.),

More information

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n

Aside: Golden Ratio. Golden Ratio: A universal law. Golden ratio φ = lim n = 1+ b n = a n 1. a n+1 = a n + b n, a n+b n a n Aside: Golden Ratio Golden Ratio: A universal law. Golden ratio φ = lim n a n+b n a n = 1+ 5 2 a n+1 = a n + b n, b n = a n 1 Ruta (UIUC) CS473 1 Spring 2018 1 / 41 CS 473: Algorithms, Spring 2018 Dynamic

More information

Continuing discussion of CRC s, especially looking at two-bit errors

Continuing discussion of CRC s, especially looking at two-bit errors Continuing discussion of CRC s, especially looking at two-bit errors The definition of primitive binary polynomials Brute force checking for primitivity A theorem giving a better test for primitivity Fast

More information

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

Divide and Conquer. CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, Divide and Conquer CSE21 Winter 2017, Day 9 (B00), Day 6 (A00) January 30, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Merging sorted lists: WHAT Given two sorted lists a 1 a 2 a 3 a k b 1 b 2 b 3 b

More information

CS 591, Lecture 9 Data Analytics: Theory and Applications Boston University

CS 591, Lecture 9 Data Analytics: Theory and Applications Boston University CS 591, Lecture 9 Data Analytics: Theory and Applications Boston University Babis Tsourakakis February 22nd, 2017 Announcement We will cover the Monday s 2/20 lecture (President s day) by appending half

More information

Solutions BAPC October University of Amsterdam. Solutions BAPC 2017 October / 31

Solutions BAPC October University of Amsterdam. Solutions BAPC 2017 October / 31 Solutions BAPC 2017 University of Amsterdam October 2017 Solutions BAPC 2017 October 2017 1 / 31 Falling Apart (54/77) Sort the input in descending order (a 1 a 2 a n ). Output a 1 + a 3 + a 5 +... and

More information

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication

CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication CS/COE 1501 cs.pitt.edu/~bill/1501/ Integer Multiplication Integer multiplication Say we have 5 baskets with 8 apples in each How do we determine how many apples we have? Count them all? That would take

More information

Exponential and Logarithmic Functions

Exponential and Logarithmic Functions Contents 6 Exponential and Logarithmic Functions 6.1 The Exponential Function 2 6.2 The Hyperbolic Functions 11 6.3 Logarithms 19 6.4 The Logarithmic Function 27 6.5 Modelling Exercises 38 6.6 Log-linear

More information

Let s Do Algebra Tiles

Let s Do Algebra Tiles Let s Do Algebra Tiles Algebra Tiles Algebra tiles can be used to model operations involving integers. Let the small green square represent +1 and the small pink square represent -1. The green and pink

More information

CS Data Structures and Algorithm Analysis

CS Data Structures and Algorithm Analysis CS 483 - Data Structures and Algorithm Analysis Lecture VII: Chapter 6, part 2 R. Paul Wiegand George Mason University, Department of Computer Science March 22, 2006 Outline 1 Balanced Trees 2 Heaps &

More information

If you have completed your extra credit opportunity, please place it on your inbox.

If you have completed your extra credit opportunity, please place it on your inbox. Warm-Up If you have completed your extra credit opportunity, please place it on your inbox. On everyone s desk should be paper and a pencil for notes. We are covering all of Quarter 1 in one day, so we

More information

Lecture 2 September 4, 2014

Lecture 2 September 4, 2014 CS 224: Advanced Algorithms Fall 2014 Prof. Jelani Nelson Lecture 2 September 4, 2014 Scribe: David Liu 1 Overview In the last lecture we introduced the word RAM model and covered veb trees to solve the

More information

Lecture 3 Sept. 4, 2014

Lecture 3 Sept. 4, 2014 CS 395T: Sublinear Algorithms Fall 2014 Prof. Eric Price Lecture 3 Sept. 4, 2014 Scribe: Zhao Song In today s lecture, we will discuss the following problems: 1. Distinct elements 2. Turnstile model 3.

More information

CS1800: Sequences & Sums. Professor Kevin Gold

CS1800: Sequences & Sums. Professor Kevin Gold CS1800: Sequences & Sums Professor Kevin Gold Moving Toward Analysis of Algorithms Today s tools help in the analysis of algorithms. We ll cover tools for deciding what equation best fits a sequence of

More information

A new dichotomic algorithm for the uniform random generation of words in regular languages

A new dichotomic algorithm for the uniform random generation of words in regular languages A new dichotomic algorithm for the uniform random generation of words in regular languages Johan Oudinet 1,2, Alain Denise 1,2,3, and Marie-Claude Gaudel 1,2 1 Univ Paris-Sud, Laboratoire LRI, UMR8623,

More information

Lecture 18: P & NP. Revised, May 1, CLRS, pp

Lecture 18: P & NP. Revised, May 1, CLRS, pp Lecture 18: P & NP Revised, May 1, 2003 CLRS, pp.966-982 The course so far: techniques for designing efficient algorithms, e.g., divide-and-conquer, dynamic-programming, greedy-algorithms. What happens

More information

#29: Logarithm review May 16, 2009

#29: Logarithm review May 16, 2009 #29: Logarithm review May 16, 2009 This week we re going to spend some time reviewing. I say re- view since you ve probably seen them before in theory, but if my experience is any guide, it s quite likely

More information

Recursion: Introduction and Correctness

Recursion: Introduction and Correctness Recursion: Introduction and Correctness CSE21 Winter 2017, Day 7 (B00), Day 4-5 (A00) January 25, 2017 http://vlsicad.ucsd.edu/courses/cse21-w17 Today s Plan From last time: intersecting sorted lists and

More information

Homework 1 Submission

Homework 1 Submission Homework Submission Sample Solution; Due Date: Thursday, May 4, :59 pm Directions: Your solutions should be typed and submitted as a single pdf on Gradescope by the due date. L A TEX is preferred but not

More information

Partial Fractions. June 27, In this section, we will learn to integrate another class of functions: the rational functions.

Partial Fractions. June 27, In this section, we will learn to integrate another class of functions: the rational functions. Partial Fractions June 7, 04 In this section, we will learn to integrate another class of functions: the rational functions. Definition. A rational function is a fraction of two polynomials. For example,

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 9 Divide and Conquer Merge sort Counting Inversions Binary Search Exponentiation Solving Recurrences Recursion Tree Method Master Theorem Sofya Raskhodnikova S. Raskhodnikova;

More information

Turing Machines Part II

Turing Machines Part II Turing Machines Part II Problem Set Set Five Five due due in in the the box box up up front front using using a late late day. day. Hello Hello Condensed Slide Slide Readers! Readers! This This lecture

More information

O Notation (Big Oh) We want to give an upper bound on the amount of time it takes to solve a problem.

O Notation (Big Oh) We want to give an upper bound on the amount of time it takes to solve a problem. O Notation (Big Oh) We want to give an upper bound on the amount of time it takes to solve a problem. defn: v(n) = O(f(n)) constants c and n 0 such that v(n) c f(n) whenever n > n 0 Termed complexity:

More information

L11.P1 Lecture 11. Quantum statistical mechanics: summary

L11.P1 Lecture 11. Quantum statistical mechanics: summary Lecture 11 Page 1 L11.P1 Lecture 11 Quantum statistical mechanics: summary At absolute zero temperature, a physical system occupies the lowest possible energy configuration. When the temperature increases,

More information

Finite Mathematics : A Business Approach

Finite Mathematics : A Business Approach Finite Mathematics : A Business Approach Dr. Brian Travers and Prof. James Lampes Second Edition Cover Art by Stephanie Oxenford Additional Editing by John Gambino Contents What You Should Already Know

More information

Operations Research Lecture 6: Integer Programming

Operations Research Lecture 6: Integer Programming Operations Research Lecture 6: Integer Programming Notes taken by Kaiquan Xu@Business School, Nanjing University May 12th 2016 1 Integer programming (IP) formulations The integer programming (IP) is the

More information

Mining Data Streams. The Stream Model. The Stream Model Sliding Windows Counting 1 s

Mining Data Streams. The Stream Model. The Stream Model Sliding Windows Counting 1 s Mining Data Streams The Stream Model Sliding Windows Counting 1 s 1 The Stream Model Data enters at a rapid rate from one or more input ports. The system cannot store the entire stream. How do you make

More information

Econ Slides from Lecture 1

Econ Slides from Lecture 1 Econ 205 Sobel Econ 205 - Slides from Lecture 1 Joel Sobel August 23, 2010 Warning I can t start without assuming that something is common knowledge. You can find basic definitions of Sets and Set Operations

More information

Introduction to Cryptology. Lecture 20

Introduction to Cryptology. Lecture 20 Introduction to Cryptology Lecture 20 Announcements HW9 due today HW10 posted, due on Thursday 4/30 HW7, HW8 grades are now up on Canvas. Agenda More Number Theory! Our focus today will be on computational

More information

GRE Workshop Quantitative Reasoning. February 13 and 20, 2018

GRE Workshop Quantitative Reasoning. February 13 and 20, 2018 GRE Workshop Quantitative Reasoning February 13 and 20, 2018 Overview Welcome and introduction Tonight: arithmetic and algebra 6-7:15 arithmetic 7:15 break 7:30-8:45 algebra Time permitting, we ll start

More information

Math Lecture 23 Notes

Math Lecture 23 Notes Math 1010 - Lecture 23 Notes Dylan Zwick Fall 2009 In today s lecture we ll expand upon the concept of radicals and radical expressions, and discuss how we can deal with equations involving these radical

More information

COMS 6100 Class Notes

COMS 6100 Class Notes COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran

More information

Decision Theory: Q-Learning

Decision Theory: Q-Learning Decision Theory: Q-Learning CPSC 322 Decision Theory 5 Textbook 12.5 Decision Theory: Q-Learning CPSC 322 Decision Theory 5, Slide 1 Lecture Overview 1 Recap 2 Asynchronous Value Iteration 3 Q-Learning

More information

Take the Anxiety Out of Word Problems

Take the Anxiety Out of Word Problems Take the Anxiety Out of Word Problems I find that students fear any problem that has words in it. This does not have to be the case. In this chapter, we will practice a strategy for approaching word problems

More information

2.2 BEGINS: POLYNOMIAL

2.2 BEGINS: POLYNOMIAL CHAPTER 2.2 HIGHER DEGREE POLY S 2.2 BEGINS: POLYNOMIAL Graphs of Polynomial Functions Polynomial functions are continuous. What this means to us is that the graphs of polynomial functions have no breaks,

More information

Advanced Analysis of Algorithms - Midterm (Solutions)

Advanced Analysis of Algorithms - Midterm (Solutions) Advanced Analysis of Algorithms - Midterm (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV {ksmani@csee.wvu.edu} 1 Problems 1. Solve the following recurrence using substitution:

More information

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh

CS 2210 Discrete Structures Advanced Counting. Fall 2017 Sukumar Ghosh CS 2210 Discrete Structures Advanced Counting Fall 2017 Sukumar Ghosh Compound Interest A person deposits $10,000 in a savings account that yields 10% interest annually. How much will be there in the account

More information

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes ) CSE548, AMS54: Analysis of Algorithms, Spring 014 Date: May 1 Final In-Class Exam ( :35 PM 3:50 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your relative

More information

CS173 Running Time and Big-O. Tandy Warnow

CS173 Running Time and Big-O. Tandy Warnow CS173 Running Time and Big-O Tandy Warnow CS 173 Running Times and Big-O analysis Tandy Warnow Today s material We will cover: Running time analysis Review of running time analysis of Bubblesort Review

More information

Some Review Problems for Exam 2: Solutions

Some Review Problems for Exam 2: Solutions Math 5366 Fall 017 Some Review Problems for Exam : Solutions 1 Find the coefficient of x 15 in each of the following: 1 (a) (1 x) 6 Solution: 1 (1 x) = ( ) k + 5 x k 6 k ( ) ( ) 0 0 so the coefficient

More information

COM S 330 Lecture Notes Week of Feb 9 13

COM S 330 Lecture Notes Week of Feb 9 13 Monday, February 9. Rosen.4 Sequences Reading: Rosen.4. LLM 4.. Ducks 8., 8., Def: A sequence is a function from a (usually infinite) subset of the integers (usually N = {0,,, 3,... } or Z + = {,, 3, 4,...

More information

Week of March 5 th to March 9 th, rd 9 weeks Algebra 1 (Periods 1, 2, 3, 4)

Week of March 5 th to March 9 th, rd 9 weeks Algebra 1 (Periods 1, 2, 3, 4) Week of March 5 th to March 9 th, 2018 3 rd 9 weeks 3/05 Chapter 9 Quadratic Functions and Equations 9-7 Linear Quadratic, and Exponential Models 3/06 Chapter 9 Quadratic Functions and Equations 9-8 Systems

More information

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016 CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis Hunter Zahn Summer 2016 Today Finish discussing stacks and queues Review math essential to algorithm analysis Proof by

More information

CIS Spring 2018 (instructor Val Tannen)

CIS Spring 2018 (instructor Val Tannen) CIS 160 - Spring 018 (instructor Val Tannen) Lecture 11 Tuesday, February 0 PROOFS: STRONG INDUCTION Example 1.1 Any integer n can be written as the product of one or more (not necessarily distinct) prime

More information

FIT100 Spring 01. Project 2. Astrological Toys

FIT100 Spring 01. Project 2. Astrological Toys FIT100 Spring 01 Project 2 Astrological Toys In this project you will write a series of Windows applications that look up and display astrological signs and dates. The applications that will make up the

More information

Dynamic Programming. Shuang Zhao. Microsoft Research Asia September 5, Dynamic Programming. Shuang Zhao. Outline. Introduction.

Dynamic Programming. Shuang Zhao. Microsoft Research Asia September 5, Dynamic Programming. Shuang Zhao. Outline. Introduction. Microsoft Research Asia September 5, 2005 1 2 3 4 Section I What is? Definition is a technique for efficiently recurrence computing by storing partial results. In this slides, I will NOT use too many formal

More information

Advanced Counting Techniques. Chapter 8

Advanced Counting Techniques. Chapter 8 Advanced Counting Techniques Chapter 8 Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence Relations Nonhomogeneous Recurrence Relations Divide-and-Conquer

More information

Chapter 2: The Basics. slides 2017, David Doty ECS 220: Theory of Computation based on The Nature of Computation by Moore and Mertens

Chapter 2: The Basics. slides 2017, David Doty ECS 220: Theory of Computation based on The Nature of Computation by Moore and Mertens Chapter 2: The Basics slides 2017, David Doty ECS 220: Theory of Computation based on The Nature of Computation by Moore and Mertens Problem instances vs. decision problems vs. search problems Decision

More information

Lecture 4 Thursday Sep 11, 2014

Lecture 4 Thursday Sep 11, 2014 CS 224: Advanced Algorithms Fall 2014 Lecture 4 Thursday Sep 11, 2014 Prof. Jelani Nelson Scribe: Marco Gentili 1 Overview Today we re going to talk about: 1. linear probing (show with 5-wise independence)

More information

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n.

Every subset of {1, 2,...,n 1} can be extended to a subset of {1, 2, 3,...,n} by either adding or not adding the element n. 11 Recurrences A recurrence equation or recurrence counts things using recursion. 11.1 Recurrence Equations We start with an example. Example 11.1. Find a recurrence for S(n), the number of subsets of

More information

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2

Announcements. CompSci 230 Discrete Math for Computer Science. The Growth of Functions. Section 3.2 CompSci 230 Discrete Math for Computer Science Announcements Read Chap. 3.1-3.3 No recitation Friday, Oct 11 or Mon Oct 14 October 8, 2013 Prof. Rodger Section 3.2 Big-O Notation Big-O Estimates for Important

More information

CMPSCI 250: Introduction to Computation. Lecture 11: Proof Techniques David Mix Barrington 5 March 2013

CMPSCI 250: Introduction to Computation. Lecture 11: Proof Techniques David Mix Barrington 5 March 2013 CMPSCI 250: Introduction to Computation Lecture 11: Proof Techniques David Mix Barrington 5 March 2013 Proof Techniques Review: The General Setting for Proofs Types of Proof: Direct, Contraposition, Contradiction

More information

MA/CSSE 473 Day 05. Factors and Primes Recursive division algorithm

MA/CSSE 473 Day 05. Factors and Primes Recursive division algorithm MA/CSSE 473 Day 05 actors and Primes Recursive division algorithm MA/CSSE 473 Day 05 HW 2 due tonight, 3 is due Monday Student Questions Asymptotic Analysis example: summation Review topics I don t plan

More information

Recurrence Relations

Recurrence Relations Recurrence Relations Winter 2017 Recurrence Relations Recurrence Relations A recurrence relation for the sequence {a n } is an equation that expresses a n in terms of one or more of the previous terms

More information

1 Closest Pair of Points on the Plane

1 Closest Pair of Points on the Plane CS 31: Algorithms (Spring 2019): Lecture 5 Date: 4th April, 2019 Topic: Divide and Conquer 3: Closest Pair of Points on a Plane Disclaimer: These notes have not gone through scrutiny and in all probability

More information

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes )

CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11. In-Class Midterm. ( 7:05 PM 8:20 PM : 75 Minutes ) CSE548, AMS542: Analysis of Algorithms, Fall 2017 Date: October 11 In-Class Midterm ( 7:05 PM 8:20 PM : 75 Minutes ) This exam will account for either 15% or 30% of your overall grade depending on your

More information

Pythagoras theorem (8 9)

Pythagoras theorem (8 9) Pythagoras theorem (8 9) Contents 1 The theorem 1 1.1 Using Pythagoras in context........................... 2 1.2 Distance between points............................. 4 1.3 Harder questions.................................

More information

Dynamic Programming: Matrix chain multiplication (CLRS 15.2)

Dynamic Programming: Matrix chain multiplication (CLRS 15.2) Dynamic Programming: Matrix chain multiplication (CLRS.) The problem Given a sequence of matrices A, A, A,..., A n, find the best way (using the minimal number of multiplications) to compute their product.

More information

Proving languages to be nonregular

Proving languages to be nonregular Proving languages to be nonregular We already know that there exist languages A Σ that are nonregular, for any choice of an alphabet Σ. This is because there are uncountably many languages in total and

More information

Math Circle: Recursion and Induction

Math Circle: Recursion and Induction Math Circle: Recursion and Induction Prof. Wickerhauser 1 Recursion What can we compute, using only simple formulas and rules that everyone can understand? 1. Let us use N to denote the set of counting

More information

Essential facts about NP-completeness:

Essential facts about NP-completeness: CMPSCI611: NP Completeness Lecture 17 Essential facts about NP-completeness: Any NP-complete problem can be solved by a simple, but exponentially slow algorithm. We don t have polynomial-time solutions

More information

Chapter 3 Math Toolkit

Chapter 3 Math Toolkit Chapter 3 Math Toolkit Problems - any Subtitle: Error, where it comes from, how you represent it, and how it propagates into your calculations. Before we can start talking chemistry we must first make

More information

Mining Data Streams. The Stream Model Sliding Windows Counting 1 s

Mining Data Streams. The Stream Model Sliding Windows Counting 1 s Mining Data Streams The Stream Model Sliding Windows Counting 1 s 1 The Stream Model Data enters at a rapid rate from one or more input ports. The system cannot store the entire stream. How do you make

More information