data structures and algorithms discrete math review

28
Data Structures and Algorithms Discrete Math Review

Upload: lucy-houston

Post on 31-Dec-2015

236 views

Category:

Documents


0 download

TRANSCRIPT

Data Structures and Algorithms

Discrete Math Review

Discrete Math review

Logarithmic FunctionsLogarithmic Functions SetsSets LogicLogic InductionInduction CountingCounting

Sets

A set is a collection of individual elements in the A set is a collection of individual elements in the domain domain DD. The . The universal set Uuniversal set U contains every contains every element in element in DD . The . The null set null set contains no contains no element. element.

If If AA is a set in the domain is a set in the domain DD , , AA must be a must be a subsetsubset of the universal set of the universal set UU , denoted as , denoted as A A U. U.

If If AA consists of some but not all elements, consists of some but not all elements, AA is is then called a then called a proper subsetproper subset of of UU , denoted as , denoted as

A A U U . .

Sets

A A setset is a collection of definite and separate objects. is a collection of definite and separate objects. TheThe cardinality cardinality of a set is the number of elements in of a set is the number of elements in

the set. the set. AA subset subset of a set is a set comprised of a sub-of a set is a set comprised of a sub-

collection of the elements of the original set. collection of the elements of the original set. Example: Example: Consider the set S = {2, 5, 7}. TheConsider the set S = {2, 5, 7}. The

subsets of S subsets of S are the sets {2} , {5}, {7}, {2,5} , {2,7} are the sets {2} , {5}, {7}, {2,5} , {2,7} , {5,7} , {2, 5, 7}and {} (the empty set). , {5,7} , {2, 5, 7}and {} (the empty set).

Fact: If a set has cardinality = Fact: If a set has cardinality = nn  , then the number   , then the number of subsets = 2of subsets = 2nn . .

Sets

AA proper subset proper subset of a set is a set comprised of a set is a set comprised of a sub-collection of some,of a sub-collection of some, but not all, but not all, of of the elements of the original set. the elements of the original set.

Example: Example: Consider the set S = {2, 5, 7}. Consider the set S = {2, 5, 7}. TheThe proper subsets of S proper subsets of S are the sets {2} , are the sets {2} , {5}, {7}, {2,5} , {2,7} , {5,7} {5}, {7}, {2,5} , {2,7} , {5,7} and {} (the empty set).and {} (the empty set).

S = cardinality of 3 S = cardinality of 3 2 23 3 77 ??

Sets

There are only two different types of sets: There are only two different types of sets: 1.1. 1. An1. An Infinite Set Infinite Set is a is a set that can be placed in a set that can be placed in a

one-to-one correspondence to a proper subset of one-to-one correspondence to a proper subset of itself.itself.

  TThe Basic Infinite Set he Basic Infinite Set is the set of positive whole is the set of positive whole numbers {1, 2, 3, 4, 5,……}. numbers {1, 2, 3, 4, 5,……}. New Notation: The New Notation: The Basic Infinite Set has cardinality =   .Basic Infinite Set has cardinality =   .

AA Finite Set Finite Set is a set that is a set that cannotcannot be placed in a one- be placed in a one-to-one correspondence to a proper subset of itself.to-one correspondence to a proper subset of itself.

Something to think about….2 subsets ? Something to think about….2 subsets ?

Logarithmic Functions

Logarithms were invented about 1614 by John Logarithms were invented about 1614 by John Napier.  The word Napier.  The word logarithm logarithm was derived from was derived from two Greek words, two Greek words, logoslogos, which means "ratio," and , which means "ratio," and arithmosarithmos, which means "number."  , which means "number." 

Before calculators and computers were available, Before calculators and computers were available, common logarithms were used to do certain kinds common logarithms were used to do certain kinds of calculationsof calculations

Growth and decayGrowth and decay Big O notation growth of computational Big O notation growth of computational

complexity complexity

Logarithmic Functions

Logarithms are exponentsLogarithms are exponents A logarithmic function is the A logarithmic function is the inverseinverse of an of an

exponential functionexponential function One way to describe a logarithmic function One way to describe a logarithmic function

is to interchange variables in the equation is to interchange variables in the equation y y = = aaxx

Thus, Thus, x x = = aayy is logarithmic is logarithmic

Logarithmic Functions

For logarithmic functions we use the For logarithmic functions we use the notation lognotation logaa xx

Therefore, The following are equivalent.Therefore, The following are equivalent.

1.1. x x = = aayy;  and ;  and

2.2. y =y = log logaa x x

Logarithmic Functions

Definition of LogarithmDefinition of Logarithm Suppose Suppose bb> 0 and .  For > 0 and .  For n n > 0, there is a > 0, there is a

number number pp such that log such that logbb nn = = pp if and only if if and only if

bbpp = = nn. . loglog22 256256 = = ? ? 2 2pp = = 256256

loglog1010 10001000 = = ? ? 10 10pp = = 10001000

loglog77 24012401 = = ? ? 7 7pp = = 24012401

LogicExamples: Boolean functions: NOT, AND, OR, XOR, . . .Examples: Boolean functions: NOT, AND, OR, XOR, . . .

a NOT( a)a NOT( a)

0 10 1

1 01 0

LogicExamples: Boolean functions: NOT, AND, ORExamples: Boolean functions: NOT, AND, OR

a a NOT( a)NOT( a)

0 10 1

1 01 0

a b AND( a, b)

0 0 0

0 1 0

1 0 0

1 1 1

a b OR( a, b)

0 0 0

0 1 1

1 0 1

1 1 1

LogicExamples: Boolean functions: XOR, XNOR, NORExamples: Boolean functions: XOR, XNOR, NOR

a b XOR( a, b)

0 0 0

0 1 1

1 0 1

1 1 0

a b XNOR( a, b)

0 0 1

0 1 0

1 0 0

1 1 1

a b NOR( a, b)

0 0 1

0 1 0

1 0 0

1 1 0

LogicBoolean SimplificationBoolean Simplification

Express Express FF in terms of in terms of AA and and BB

A B A B FF

0 1 0 1 00

1 0 1 0 11

1 1 1 1 11

F = AB + AB

A ( B + B ) = F

Using the uniting theorem

SeriesArithmeticArithmetic

One common type of series is the arithmetic series (also called an One common type of series is the arithmetic series (also called an arithmetic progression). Each new term in an arithmetic series is the arithmetic progression). Each new term in an arithmetic series is the previous term plus a given number. For example this is an arithmetic previous term plus a given number. For example this is an arithmetic series: 1+4+7+10+13+....series: 1+4+7+10+13+....

In this case each term is the previous term plus 3. The difference In this case each term is the previous term plus 3. The difference between each term (the 3 in this case) is called the "common between each term (the 3 in this case) is called the "common difference" and is generally denoted by the letter difference" and is generally denoted by the letter dd..

There are many arithmetic series that have d=3. To specify which There are many arithmetic series that have d=3. To specify which series we mean, we need to know one more piece of information: the series we mean, we need to know one more piece of information: the value of the first term (usually called "value of the first term (usually called "aa"). ").

Series

ArithmeticArithmetic If we're given If we're given aa and and dd, then, that specifies a , then, that specifies a

unique arithmetic series. All arithmetic unique arithmetic series. All arithmetic series therefore have the following form: series therefore have the following form: a+(a+d)+(a+2d)+(a+3d)+.... a+(a+d)+(a+2d)+(a+3d)+....

So in general we can say that the value of So in general we can say that the value of the nth term is the nth term is a+(n-1)da+(n-1)d

SeriesGeometricGeometric

Another common type of series is the geometric series (also called a Another common type of series is the geometric series (also called a geometric progression). In this case, each term is the previous term geometric progression). In this case, each term is the previous term multiplied bymultiplied by a given number. a given number.

Here's a geometric series, for example:Here's a geometric series, for example:2+6+18+54+...2+6+18+54+...

In this case, each term is the previous term multiplied by 3. The In this case, each term is the previous term multiplied by 3. The number you multiply by (in this case 3) is called the "common ratio" number you multiply by (in this case 3) is called the "common ratio" and is generally denoted by and is generally denoted by rr..

There are many geometric series that have There are many geometric series that have r=3r=3. To specify which . To specify which series we mean, again we need to know one more piece of series we mean, again we need to know one more piece of information: the value of the first term (usually called "information: the value of the first term (usually called "aa"). ").

Series

GeometricGeometric A geometric series is uniquely specified by the values

of a and r. Every geometric series has the following form:

a+ar+ar2+ar3+....... Writing the series in this way we can see the formula

for working out the value of any term. The first term is just a. The second term is a multiplied by r once. The third term is a multiplied by r twice, and so on. So the nth term must be a multiplied by r (n-1) times, that's arn-1.

Series

Are there others?Are there others?

The P word….Induction

The Principle of Mathematical InductionThe Principle of Mathematical Induction

Suppose we have an assertion P(n) about the positive Suppose we have an assertion P(n) about the positive integers. integers.

Then if we show both of (i) and (ii) below, then P(n) is Then if we show both of (i) and (ii) below, then P(n) is true for all n >= 1. true for all n >= 1. (i). P(1) is true (i). P(1) is true (ii). For each k >= 1: If P(k) is true, then P(k+1) is true. (ii). For each k >= 1: If P(k) is true, then P(k+1) is true.

The P word….Induction

Prove that Prove that 1+2+3+…+ n1+2+3+…+ n = =

n(n+1)2

Prove that Prove that 1+3+5+…+ (2n – 1)1+3+5+…+ (2n – 1) = = nn22

Counting

Product Rule: Product Rule: nn ways to do ways to do mm tasks = tasks = nmnm ways.ways.

How many different bit strings are there of How many different bit strings are there of length 7?length 7?

Counting

Pigenhole Principle: If Pigenhole Principle: If NN objects are placed into k objects are placed into k boxes, then there is at least one box containing at boxes, then there is at least one box containing at least [least [N/kN/k] objects.] objects.

Ten persons were born on the 1Ten persons were born on the 1st, st, 1111th th and the 27and the 27thth of the months of May, August and November. of the months of May, August and November. How many share the exact same birthday?How many share the exact same birthday?

Tells us nothing of the date. Asserts only that one Tells us nothing of the date. Asserts only that one exists!exists!

CountingPermutations and CombinationsPermutations and Combinations

Permutations: Given that position is important, if Permutations: Given that position is important, if one has 4 different objects (e.g. A, B, C and D), one has 4 different objects (e.g. A, B, C and D), how many unique ways can they be placed in 3 how many unique ways can they be placed in 3 positions (e.g. ABD, ACD, BDA, DBA, BAD, positions (e.g. ABD, ACD, BDA, DBA, BAD, ADB, ADC, DCA, DAC, CDA etc.)ADB, ADC, DCA, DAC, CDA etc.)

An ordered arrandement of An ordered arrandement of rr elements of a set is elements of a set is called a called a rr-permutation.-permutation.

n!(n – r)!

P( n, r ) =

CountingPermutations and CombinationsPermutations and Combinations

Combinations: If one has 4 different objects (e.g. Combinations: If one has 4 different objects (e.g. A, B, C and D) how many ways can they be A, B, C and D) how many ways can they be grouped as 2 objects when position does not grouped as 2 objects when position does not matter (e.g. AB, AC, AD are correct but DA is not matter (e.g. AB, AC, AD are correct but DA is not ok as is equal to AD.)ok as is equal to AD.)

An An rr-combination is simply a subset of the set -combination is simply a subset of the set with with rr elements. elements.

C ( n, r ) = n!

r! ( n-r )!

Base Conversion The base value of a number system is the number The base value of a number system is the number

of different values the set has before repeating of different values the set has before repeating itself. For example, decimal has a base of ten itself. For example, decimal has a base of ten values, 0 to 9. values, 0 to 9. Binary = 2 (0, 1) Binary = 2 (0, 1) Octal = 8 (0 - 7) Octal = 8 (0 - 7) Decimal = 10 (0 - 9) Decimal = 10 (0 - 9) Duodecimal = 12 (used for some purposes by the Romans) Duodecimal = 12 (used for some purposes by the Romans) Hexadecimal = 16 (0 - 9, A-F) Hexadecimal = 16 (0 - 9, A-F) Vigesimal = 20 (used by the Mayans) Vigesimal = 20 (used by the Mayans) Sexagesimal = 60 (used by the Babylonians) Sexagesimal = 60 (used by the Babylonians)

Base Conversion

Successive DivisionSuccessive Division 37371010 base 6 base 6

37/6 = 6 r 137/6 = 6 r 16/6 = 1 r 06/6 = 1 r 01/6 = 0 r 11/6 = 0 r 137371010 base 6 = 101 base 6 = 101

Base Conversion

1011016 6 base 10base 10 1x61x600+0x6+0x611+1x6+1x62 2 = 1+0+36 = 37= 1+0+36 = 37

58581010base4base4

1111111010base13base13