CSCI-2200 FOUNDATIONS OF COMPUTER SCIENCE Spring 2019 2 - - PowerPoint PPT Presentation

csci 2200 foundations of computer science
SMART_READER_LITE
LIVE PREVIEW

CSCI-2200 FOUNDATIONS OF COMPUTER SCIENCE Spring 2019 2 - - PowerPoint PPT Presentation

1 CSCI-2200 FOUNDATIONS OF COMPUTER SCIENCE Spring 2019 2 Announcements Exam 1 is Wednesday, Feb 13. 6pm 7:50pm If you get special accommodations, you should have received email from Ms. Eberwein with the date, time, and location


slide-1
SLIDE 1

CSCI-2200 FOUNDATIONS OF COMPUTER SCIENCE

Spring 2019

1

slide-2
SLIDE 2

Announcements

  • Exam 1 is Wednesday, Feb 13. 6pm – 7:50pm
  • If you get special accommodations, you should have

received email from Ms. Eberwein with the date, time, and location of your exam.

  • If you did not receive this email, email me asap.
  • Please see slides from Feb. 5 for other announcements

about Exam 1.

  • Will include material up through Feb 8th lecture.
  • Homework 3 is due Feb. 12 at 11:59pm

2

slide-3
SLIDE 3

SET CARDINALITY

Section 2.5

3

slide-4
SLIDE 4

Countable Sets

  • An infinite set S is countable iff there exists a bijective

function f: S → Z+

  • f maps each element of S to exactly one element of Z+.
  • Every element of Z+ is mapped to by some element of S, under f.
  • All infinite countable sets are the same size.
  • They all have the same size as Z+
  • All finite sets are countable.

4

slide-5
SLIDE 5
  • Theorem: The set of positive even integers is countable.

5

slide-6
SLIDE 6

More about countable sets

  • A subset of a countable set is countable.
  • An infinite set is countable if and only if it is possible to list all of

the elements in the set in a sequence.

  • We can enumerate the set.
  • If I read off elements from the sequence, for every element,

there some time in the future at which I will read that element.

  • No element waits infinitely long to be read.

6

slide-7
SLIDE 7

7

Example: The set of positive rational numbers is countable Positive Rational numbers:

! , 8 7 , 4 3 , 2 1

slide-8
SLIDE 8

8

Naïve Approach Rational numbers:

! , 3 1 , 2 1 , 1 1

Positive Integers Correspondence: Doesnt work: we will never count numbers with numerator 2:

! , 3 2 , 2 2 , 1 2

Numerator 1

1, 2, 3

slide-9
SLIDE 9

9

Better Approach

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-10
SLIDE 10

10

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-11
SLIDE 11

11

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-12
SLIDE 12

12

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-13
SLIDE 13

13

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-14
SLIDE 14

14

1 1 2 1 3 1 4 1 1 2 2 2 3 2 1 3 2 3 1 4 ! ! ! !

slide-15
SLIDE 15

15

Rational Numbers:

! , 2 2 , 3 1 , 1 2 , 2 1 , 1 1

Correspondence: Positive Integers:

! , 5 , 4 , 3 , 2 , 1

slide-16
SLIDE 16

16

Theorem: The real numbers are uncountable. A set is uncountable if it is not countable. Definition:

slide-17
SLIDE 17

17

Theorem: If A is countable and B is countable, then A U B is countable.

slide-18
SLIDE 18

Schroder-Bernstein Theorem

  • Theorem: If A and B are sets with |A| ≤ |B| and |B| ≤ |A|,

then |A| = |B|. In other words, if there are injective functions f: A → B and g: B → A, then there is a bijection from A to B (and B to A).

18

slide-19
SLIDE 19
  • Show that | (0,1) | = |(0, 1]|

19

slide-20
SLIDE 20

SEQUENCES AND SUMMATION

Section 2.4

20

slide-21
SLIDE 21

Sequences

  • Imagine a person (with a lot of spare time) who decides to

count her ancestors.

  • She has two parents, four grandparents, eight grand-

grandparents, etc.

  • We can write this in a table
  • Can guess that the kth element is 2k.
  • Just a guess – we would need to prove this.

21

1 2 3 4 5 6 2 4 8 16 32 64

slide-22
SLIDE 22

Sequences

  • A sequence is a ordered list of elements.
  • Each element has a unique position in the list.
  • Formally, a sequence is a function from a subset of the integers to a

set S.

  • Usually maps from the set {0, 1, 2, 3, 4, …..} or {1, 2, 3, 4, ….} to the

set S.

  • We do not write f(n) for an element in a sequence.
  • Instead, the notation an is used to denote the image of the integer n.
  • The sequence is {a0, a1, a2, a3, …}
  • We call an a term of the sequence.

22

slide-23
SLIDE 23

Example of Sequence

23

slide-24
SLIDE 24

Formula for a Sequence?

  • Can we find an explicit formula for the nth term given only the first few

elements of a sequence?

  • Examples:
  • 7, 11, 15, 19, 23, 27, 31, 35, ...
  • 3, 6, 11, 18, 27, 38, 51, 66, 83, ...
  • 0, 2, 8, 26, 80, 242, 728, 2186, 6560, 19682, ...
  • O, T, T, F, F, S, S, E, ...
  • To do this, try to find a pattern
  • Are terms obtained from previous terms by adding the same

amount, or an amount that depends on position in the sequence?

  • Are terms obtained from previous terms by multiplying by a

particular amount?

  • Are terms obtained by combining previous terms in a certain way?

24

slide-25
SLIDE 25

Arithmetic Progression

  • An arithmetic progression is a sequence of the form:

where the initial term a and the common difference d are real numbers.

  • Another way to write this is

Examples:

1.

Let a = −1 and d = 4:

1.

Let a = 7 and d = −3:

25

a + nd, n = 0, 1, 2, . . .

slide-26
SLIDE 26

Geometric Progression

  • A geometric progression is a sequence of the form:

where the initial term a and the common ratio r are real numbers.

  • Another way to write this is

Examples: Let a = 1 and r = −1. Let a = 2 and r = 5. Let a = 6 and r = 1/3.

26

tn = arn, n = 0, 1, 2, . . .

slide-27
SLIDE 27

Recurrence Relations

  • A recurrence relation for the sequence {an} is an equation that

expresses an in terms of one or more of the previous terms of the sequence.

  • The initial conditions for a sequence specify the terms that

precede the first term where the recurrence relation takes effect.

  • Example:
  • a0 = 2

an = an-1 + 3 for n = 1,2,3,4,….

  • What are a1, a2 and a3?

27

slide-28
SLIDE 28

Example Recurrence Relation

  • Let {an} be a sequence that satisfies the recurrence

relation an = an-1 – an-2 for n = 2, 3, 4, ….

  • The initial conditions are a0 = 3 and a1 = 5.
  • What are a2 and a3?

28

slide-29
SLIDE 29

Fibonacci Sequence

Define the Fibonacci sequence f0 ,f1 ,f2,…, by:

  • Initial Conditions: f0 = 0, f1 = 1
  • Recurrence Relation: fn = fn-1 + fn-2

Example: Find f2 ,f3 ,f4 , and f5.

29

slide-30
SLIDE 30

Solving Recurrence Relations

  • Finding a formula for the nth term of the sequence generated

by a recurrence relation is called solving the recurrence relation.

  • Such a formula is called a closed formula.
  • Example:
  • Let {an} be a sequence that satisfies the recurrence

relation an = 2an-1 – an-2 for n = 2,3,4,….

  • Is an = 3n is a solution?

30

slide-31
SLIDE 31

Solving Recurrence Relations (cont.)

  • Let {an} be a sequence that satisfies the recurrence relation

an = 2an-1 – an-2 for n = 2,3,4,….

  • Is an = 2n a solution?
  • Is an = 5 a solution?

31

slide-32
SLIDE 32

Iterative Solution Example

Let {an} be a sequence that satisfies the recurrence relation an = an-1 + 3 for n = 2,3,4,…. Suppose that a1 = 2. Finding a Solution - Method 1: forward substitution

32

slide-33
SLIDE 33

Iterative Solution Example

  • Let {an} be a sequence that satisfies the recurrence relation

an = an-1 + 3 for n = 2,3,4,…. Suppose that a1 = 2.

  • Find a Solution – Method 2: backward substitution

33

slide-34
SLIDE 34

Compound Interest Example

  • Suppose a person deposits $10,000 in a savings account at a

bank yielding 11% per year with interest compounded annually. How much will be in the account after 30 years?

34

slide-35
SLIDE 35

Good Problems to Review

  • Section 2.4: 1, 3, 9, 11, 13, 15, 17, 19, 21, 23

35