unit – 1 : foundations syllabus: sets – relations – equivalence relations partial orders –...

36
Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle – structural induction recursive algorithms – counting – pigeonhole principle permutations and combinations – recurrence relations 1

Upload: lesley-chambers

Post on 31-Dec-2015

241 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Unit – 1 : FOUNDATIONS

Syllabus:

Sets – relations – equivalence relations partial orders – functions – recursive functionssequences – induction principle – structural inductionrecursive algorithms – counting –pigeonhole principle permutations and combinations – recurrence relations

1

Page 2: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

Definition: Set is a well defined collection of objects

2

Page 3: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

3

Page 4: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

4

Page 5: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

5

Page 6: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

6

Page 7: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

7

Page 8: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

8

Page 9: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sets

This n means the number of elements in the set

9

Page 10: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Relations

Definition: Let A and B be sets. A binary relation from A to B is a subset of AB.

In other words, for a binary relation R we have R AB. We use the notation aRb to denote that (a, b)R and aRb to denote that (a, b)R.

Example: Let P be a set of people, C be a set of cars, and D be the relation describing which person drives which car(s).P = {Carl, Suzanne, Peter, Carla}, C = {Mercedes, BMW, tricycle}D = {(Carl, Mercedes), (Suzanne, Mercedes), (Suzanne, BMW), (Peter, tricycle)}This means that Carl drives a Mercedes, Suzanne drives a Mercedes and a BMW, Peter drives a tricycle, and Carla does not drive any of these vehicles.

10

Page 11: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Relations

11

Page 12: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Relations

12

Page 13: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Equivalence Relations

Equivalence relations are used to relate objects that are similar in some way.

Definition: A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive.

Two elements that are related by an equivalence relation R are called equivalent.

13

Page 14: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Partial Orders

A partial order is a binary relation "≤" over a set P which is reflexive, antisymmetric, and transitive, i.e., which satisfies for all a, b, and c in P:

a ≤ a (reflexivity);

if a ≤ b and b ≤ a then a = b (antisymmetry);

if a ≤ b and b ≤ c then a ≤ c (transitivity).

In other words, a partial order is an antisymmetric preorder.

14

Page 15: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Functions

15

Page 16: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Identity functionA function f from a set A

to the same set A stating that f(x) = x for all elements of x in the set A.

Identity function is one one and onto also.

It is a bijective mapping from a set into it self.

16

Page 17: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

One one function

A function f from a set A to set B such that for any element of set B there exists only one preimage in set A. If f(a) = f(b) then a = b for all elements of a,b in set A.

It is also called as injective or some times 1 1.

17

Page 18: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Onto function

A function from a set A to set B such that for all elements of set B there exists at least one element in set B such that f(a) = b.

It is also called as surjective mapping.

Here f(A) = B.All images are have preimages.

18

Page 19: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

One to one function

A function from a set A to set B with the two properties one one and onto.

It is also called as 1to1 or some times bijective mapping

n(A) = n(B)i. e. both the sets have same

number of elements.one element to one image and

one image is for one element.19

Page 20: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Step function

A function f from real numbers set to integers set stating that

f(x) = y where y-1<x<=y

for all real numbers x. where y is an integer.Examples are floor function or ceiling function.

20

Page 21: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Absolute function

A function from real numbers set to real numbers set stating that

x if x is > 0f(x) = -x if x is < 0

0 if x is = 0

21

Page 22: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recursive FunctionsA recursive function is an equation that

recursively defines a sequence, once one or more initial terms are given: each further term of the sequence is defined as a function of the preceding terms.

The term difference equation sometimes (and for the purposes of this article) refers to a specific type of recurrence relation. However, "difference equation" is frequently used to refer to any recurrence relation.Example: We obtain the sequence of Fibonacci numbers which begins:0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...It can be solved by methods described below yielding the closed-form expression which involve powers of the two roots of the characteristic polynomial t2 = t + 1; the generating function of the sequence is the rational function

22

Page 23: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Sequences

A sequence is an ordered list. Like a set, it contains members (also called elements, or terms). The number of ordered elements (possibly infinite) is called the length of the sequence.

Unlike a set, order matters, and exactly the same elements can appear multiple times at different positions in the sequence. Most precisely, a sequence can be defined as a function whose domain is a countable totally ordered set, such as the natural numbers.

For example, (M, A, R, Y) is a sequence of letters with the letter 'M' first and 'Y' last. This sequence differs from (A, R, M, Y). Also, the sequence (1, 1, 2, 3, 5, 8), which contains the number 1 at two different positions, is a valid sequence. 23

Page 24: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Induction Principle

Mathematical induction is a method of mathematical proof typically used to establish a given statement for all natural numbers.

It is done in two steps. The first step, known as the base case, is to

prove the given statement for the first natural number.

The second step, known as the inductive step, is to prove that the given statement for any one natural number implies the given statement for the next natural number.

From these two steps, mathematical induction is the rule from which we infer that the given statement is established for all natural numbers.

24

Page 25: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Structural Induction

Structural induction is a proof method that is used in mathematical logic (e.g., in the proof of Łoś' theorem), computer science, graph theory, and some other mathematical fields.

It is a generalization of mathematical induction over natural numbers, and can be further generalized to arbitrary Noetherian induction. Structural recursion is a recursion method bearing the same relationship to structural induction as ordinary recursion bears to ordinary mathematical induction.

Structural induction is used to prove that some proposition P(x) holds for all x of some sort of recursively defined structure such as lists or trees.

A well-founded partial order is defined on the structures ("sublist" for lists and "subtree" for trees).

The structural induction proof is a proof that the proposition holds for all the minimal structures, and that if it holds for the immediate substructures of a certain structure S, then it must hold for S also. (Formally speaking, this then satisfies the premises of an axiom of well-founded induction, which asserts that these two conditions are sufficient for the proposition to hold for all x.)

25

Page 26: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recursive AlgorithmsThe Nature of Recursion Algorithms•Problems that lend themselves to a recursive solution have the following characteristics: One or more simple cases of the problem (called stopping cases) have a simple, non-recursive solution.•For the other cases, there is a process (using recursion) for substituting one or more reduced cases of the problem that are closer to a stopping case.•Eventually the problem can be reduced to stopping cases only, all of which are relatively easy to solve.

if (the stopping case is reached)    {         Solve it    }    else    {        Reduce the problem using recursion    }

26

Page 27: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recursive Algorithms

1. To find N!: If N = 1 then N! = 1; Otherwise N! = N x (N - 1)!

2. The Fibonacci sequence is defined below. Fib1 is 1. Fib2 is 1. Fibn is Fibn-2 + Fibn-1, for n > 2.

3. GCD(M, N) is N if N <= M and N divides M. GCD(M, N) is GCD(N, M) if M < N. GCD(M, N) is GCD(N, remainder of M divided by N) otherwise.

27

Page 28: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

CountingCombinatorics is a branch of mathematics concerning

the study of finite or countable discrete structures. Aspects of combinatorics include counting the

structures of a given kind and size (enumerative combinatorics), deciding when certain criteria can be met, and constructing and analyzing objects meeting the criteria (as in combinatorial designs and matroid theory), finding "largest", "smallest", or "optimal" objects (extremal combinatorics and combinatorial optimization), and studying combinatorial structures arising in an algebraic context, or applying algebraic techniques to combinatorial problems (algebraic combinatorics).Counting is the action of finding the number of elements of a

finite set of objects. The traditional way of counting consists of continually increasing a (mental or spoken) counter by a unit for every element of the set, in some order, while marking (or displacing) those elements to avoid visiting the same element more than once, until no unmarked elements are left; if the counter was set to one after the first object, the value after visiting the final object gives the desired number of elements. The related term enumeration refers to uniquely identifying the elements of a finite (combinatorial) set or infinite set by assigning a number to each element.

28

Page 29: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Pigeonhole Principle

Pigeonhole principle : If n items are put into m pigeonholes with n > m, then at least one pigeonhole must contain more than one item. This theorem is exemplified in real-life by truisms like "there must be at least two left gloves or two right gloves in a group of three gloves".

It is an example of a counting argument, and

despite seeming intuitive it can be used to demonstrate possibly unexpected results; for example, that two people inLondon have the same number of hairs on their heads

29

Page 30: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Permutations and Combinations

Permutation means to the act of permuting (rearranging) objects or values. Informally, a permutation of a set of objects is an arrangement of those objects into a particular order.

example, there are six permutations of the set {1,2,3}, namely (1,2,3), (1,3,2), (2,1,3), (2,3,1), (3,1,2), and (3,2,1).

The number of permutations of n distinct objects is "n factorial" usually written as "n!", which means the product of all positive integers less than or equal to n.

30

Page 31: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Permutations and Combinations

• A permutation of a set S of objects is an ordered arrangement of these objects.

• The number of r-permutations of a set with n elements is denoted by P n r

Example:• How many permutations of the letter JKLMNOPQ contain the string JKL?Since the letter JKL must occur in a block, we must consider six objects

namely JKL as one block and M,N,O,P,Q. the six objects can occur in any order and there are 6! = 720 permutations of the letters JKLMNOPQ in which JKL occurs as a block

31

Page 32: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Permutations and Combinations

Combinations• Def:An r-combination of elements of a set S is

simply a subset T of S with r members.

Combinations with repetitions:There are C(n+r-1, r) r-combinations from a

set with n elements when repetition of elementsis allowed.

32

Page 33: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Permutations and Combinations

Combination is a way of selecting several things out of a larger group, where (unlike permutations) order does not matter. In smaller cases it is possible to count the number of combinations.

For example given three fruits, say an apple, an orange and a pear, there are three combinations of two that can be drawn from this set: an apple and a pear; an apple and an orange; or a pear and an orange.

More formally a k-combination of a set S is a subset of k distinct elements of S. If the set has n elements the number of k-combinations is equal to the binomial coefficient

33

Page 34: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recurrence Relations

Recurrence relation is an equation that recursively defines a sequence, once one or more initial terms are given: each further term of the sequence is defined as a function of the preceding terms.

The Fibonacci numbers are the archetype of a linear, homogeneous recurrence relation with constant coefficients (see below). They are defined using the linear recurrence relation

34

Page 35: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recurrence RelationsRecurrence relations are having

fundamental importance in Analysis of Algorithms. If an algorithm is designed so that it will break a problem into smaller sub problems, its running time is described by a recurrence relation.

A simple example is the time an algorithm takes to search an element in an ordered vector with n elements, in the worst case.

A naive algorithm will search from left to right, one element at a time. The worst possible scenario is when the required element is the last, so the number of comparisons is n. 35

Page 36: Unit – 1 : FOUNDATIONS Syllabus: Sets – relations – equivalence relations partial orders – functions – recursive functions sequences – induction principle

Recurrence RelationsA better algorithm is called binary search. It

will first check if the element is at the middle of the vector.

If not, then it will check if the middle element is greater or lesser than the seeked element. At this point, half of the vector can be discarded, and the algorithm can be run again on the other half.

The number of comparisons will be given by

which will be close to 

36