Question : How many different ways are there to climb a staircase with n steps (for example, 100 steps) if you are allowed to skip steps, but not more.

Slides:



Advertisements
Similar presentations
An introduction to Problem Solving Math 110 Iris Yang.
Advertisements

PYTHON FRUITFUL FUNCTIONS CHAPTER 6 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
This number is called the common ratio.
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
Infinite Series 9 Copyright © Cengage Learning. All rights reserved.
Finite Automata with Output
Lecture 1Easy, Hard, Impossible!Handout Easy: Euclid Sequences Form a sequence of number pairs (integers) as follows: Begin with any two positive numbers.
James Tam Non decimal math: doing math with non-base 10 number systems Addition, subtraction and multiplication with binary, octal and hexadecimal.
Sequence A list of objects arranged in a particular order.
1 Python Chapter 4 Branching statements and loops © Samuel Marateck 2010.
Exponential Notation Awesome to the power of ten!.
F A T R N T EP N I D A Much of mathematics is based on patterns, so it is important to study patterns in math. We use patterns to understand our world.
Fibonacci Spiral Richard Kwong MAT 385
Data Structures Using C++ 2E Chapter 6 Recursion.
Advanced Instructions Most PLCs now support more advanced functions such as Floating point math, Boolean operations, Shifting, Sequencing, Program control.
Data Structures Using C++ 2E Chapter 6 Recursion.
Recursion l Powerful Tool l Useful in simplifying a problem (hides details of a problem) l The ability of a function to call itself l A recursive call.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Introduction to Computing Using Python Recursion and Algorithm Development  Introduction to Recursion  Recursion Examples  Run Time Analysis  Search.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data Depends.
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
Logic (continuation) Boolean Logic and Bit Operations.
Edited by Malak Abdullah Jordan University of Science and Technology Data Structures Using C++ 2E Chapter 6 Recursion.
Today’s Plan: -Mental math with decimals -Multiply decimals -Add and Subtract Decimals 11/17/10 Decimals Learning Target: -I can solve problems containing.
Sequences & Series Section 13.1 & Sequences A sequence is an ordered list of numbers, called terms. The terms are often arranged in a pattern.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Spot the Pattern Look for the pattern with the sequence of number and write the next 2 numbers in the pattern. 5, 8, 11, 14, , 10,
Lesson 6.8A: The Binomial Theorem OBJECTIVES:  To evaluate a binomial coefficient  To expand a binomial raised to a power.
Discrete Structure Li Tak Sing( 李德成 ) Lecture 13 1.
Computer Number Systems ACSL.  All computers – from large mainframes to hand-held micros – ultimately can do one thing: detect whether an electrical.
By Austin Laudenslager AN INTRODUCTION TO PYTHON.
Choose a category. You will be given the answer. You must give the correct question. Click to begin.
WRITING ABOUT MATH. FIRST…ANSWER THE QUESTION Question: How can you get the sum of 9 + 4? Answer: You can get the sum of 9+4 by adding 4 to 9, which is.
Section 10.2 Sequences. In mathematics, a sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements or.
What is Matrix Multiplication? Matrix multiplication is the process of multiplying two matrices together to get another matrix. It differs from scalar.
Math Review 4 th Grade. Dates There are 52 weeks in one year. There are 365 days in one year. January, March, May, July, August, October, and December.
Least Common Multiple Greatest Common Factor
Patterns in Sequences. Number patterns Sequences of numbers can have interesting patterns. Here we list the most common patterns and how they are made.
Machine Language Computer languages cannot be directly interpreted by the computer – they are not in binary. All commands need to be translated into binary.
1 7.Algorithm Efficiency These factors vary from one machine/compiler (platform) to another  Count the number of times instructions are executed So, measure.
Lecture 14: Theory of Automata:2014 Finite Automata with Output.
WHAT IS BINARY? Binary is a number system that only uses two digits: 1 and 0. Any information that processed by a computer it is put into sequence of.
Lecturer: Santokh Singh
Logic and Computer Design Fundamentals
Number Systems Write the decimal value of the binary number
More Mathematical Techniques
11.2 Arithmetic Sequences.
I can… Essential Question: How can I use place value?
Patterns and Sequences
Pascal’s Triangle Permission Pending By. Ms. Barnes.
Mathematics Common Math Approaches
More Mathematical Techniques
X-STANDARD MATHEMATICS ONE MARK QUESTIONS
Sequences and Series 4.7 & 8 Standard: MM2A3d Students will explore arithmetic sequences and various ways of computing their sums. Standard: MM2A3e Students.
Number Patterns.
Data Representation – Chapter 3
1.6) Storing Integer:.
Unit 3 Test: Friday.

Kinder Campus Math Bee School Year.
15-110: Principles of Computing
Kindergarten Math Bee Practice.
Multiplication of 10.
More Mathematical Techniques
Kinder Campus Math Bee School Year.
3, 6, 9, 12, __, 18 ____ Pattern What comes next in the pattern?
Recursion Examples.
Presentation transcript:

Question : How many different ways are there to climb a staircase with n steps (for example, 100 steps) if you are allowed to skip steps, but not more than one at a time?

Explore by hand, look for a pattern: n = 1: 1 n = 2: n = 3: way 2 ways 3 ways n = 4: ways? ways! n = 5: ? Too much work!

Use a computer: Generate all sequences of 1s and 2s of length from 1 to n, and count the sequences for which the sum of the elements is equal to n. Generate... – how?!

A better approach: Model the situation in a different way (isomorphism): marks a step we step on; 1 marks a step we skip. A valid path cannot have two 1s in a row, ends with a 0.

Binary number system for x in range (2**n):# Binary digits of x are used as a # sequence of 0s and 1s of length n Bitwise logical operators if x & (x << 1) == 0:# If the binary representation of x # has no two 1s in a row Problem restated: Count all sequences of 0s and 1s of length n with no two 1s in a row &&

def countPaths(n): """ Returns the number of sequences of 0s and 1s of length n with no two 1s in a row """ count = 0 for x in range(2**n): if x & (x << 1) == 0: count += 1 return count for n in range(101): print(n+1, countPaths(n)) Fibonacci numbers! Final program:

def fibonacciList (n): "Returns the list of the first n Fibonacci numbers" fibs = [1, 1] while len(fibs) < n: fibs.append (fibs[-1] + fibs[-2]) return fibs print (fibonacciList (101)) [1, 1, 2, 3, 5, 8, 13,..., ] The answer is 101th Fibonacci number! There is an easier way to compute it, of course, for example:

Back to math: Show mathematically that the number of paths for n steps is the (n+1)th Fibonacci number.