Functions - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Functions

Description:

Using a formula such as f(x) = expression, example: f (x) = 2x 2. Illustration as in the ... Running time functions are ordered using the O notation. Example T1 ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 25
Provided by: elearni7
Category:

less

Transcript and Presenter's Notes

Title: Functions


1
Functions
  • A function f from a set X to a set Y is a
    relation from X to Y such that x ? X is related
    to one and only one y ? Y
  • X is called the domain Y is called the range.
    We say x is mapped into y.
  • f (a, 3), (b, 3), (c, 5), (d, 1)

2
Function description
  • Functions are described as
  • Set of ordered pairs, example f as given before
  • Using a formula such as f(x) expression,
    example f (x) 2x 2
  • Illustration as in the example below

3
Properties of functions
  • A function is called one to one or (injection) if
    different elements in the domain are related to
    different elements in the range.

4
Properties of functions
  • A function is called onto or a surjection if each
    element of the range is related to at least one
    element in the domain.

5
Properties of functions
  • A function is called bijection if it is one to
    one onto
  • For each element in the domain there is one and
    only one element in the range
  • Number of elements in the domain equals that in
    the range

6
Sequences
  • A sequence is a function with domain is a set of
    consecutive integers.
  • Example S(i) i2 for i 1
  • The ith term of the sequence i2 is denoted by Si
  • What is the second term of the sequence 22 4
  • The fourth is 42 16

7
Finite infinite Sequences
  • If the domain of the sequence is finite, then the
    elements can be listed as a tuple for example
  • If the domain of the previous example S(i) is 1,
    2, 3,., 9, 10, then the sequence elements are
    1, 4, 9, 16, 25, 36, 49, 64, 81, 100
  • The domain of S(i) is the integers, in this case
    the sequence elements are infinite 1, 4, 9, ,
    i2, .,

8
Summing Finite Sequence
  • Example If n 3, then the sum 14
  • Is there a formula to compute the sum of finite
    sequence elements? For the example S(i).
  • How about the sequence 1 2 3 . n

9
Identity function
  • For any domain X, the identity function IX?X is
    the unique function such that ?a?X I(a)a.
  • Note that the identity function is both
    one-to-one and onto (bijective).

10
Identity Function Illustrations
  • The identity function

Domain and range
11
Other Functions
  • In discrete math, we will frequently use the
    following functions over real numbers
  • ?x? (floor of x) is the largest (most positive)
    integer ? x.
  • ?x? (ceiling of x) is the smallest (most
    negative) integer ? x.

12
Visualizing Floor Ceiling
  • Real numbers fall to their floor or rise to
    their ceiling.
  • Note that if x?Z,??x? ? ? ?x? ??x? ? ? ?x?
  • Note that if x?Z, ?x? ?x? x.

3
.
?1.6?2
2
.
1.6
.
1
?1.6?1
0
.
??1.4? ?1
?1
.
?1.4
.
?2
??1.4? ?2
.
.
.
?3
?3
??3???3? ?3
13
Cartesian graphs of relations Functions
  • Discovering properties of relations and functions
    from graphs
  • Example

This is a relation but not a function vertical
line crosses the graph in two points
14
Plotting floor function
  • Plot of graph of function f(x) ?x/3?

f(x)
Set of points (x, f(x))
2
x
?3
3
?2
15
Comparing functions
  • A function f gt g for finite number of points but
    less than for others
  • Example the identity function and x2

16
Growth rate function
  • The time needed to execute a program depends on
    several factors among them the number of input
    values.
  • If T is the running time then it is given as a
    function of number of input elements as T(n)
  • For example if L is a list of elements it is
    needed to search L for some value. The running
    time depends on the size of L.

17
A linear time algorithm
  • The running time T(n) is of the form of the line
    equation. T(n) an b
  • Searching the list L for a given value
  • Start with the first position
  • Compare the key with the list element in the
    first position if found then, DONE and exit
  • If not found try the next position and repeat the
    above step

18
A linear time algorithm
  • What is the number of comparisons needed to find
    out that the key is not found in the list?
  • What is the number of comparisons to find the key
    in the first position?
  • What is the average time of finding the key using
    this algorithm?
  • A program that implements the algorithm takes
    linear time.

19
One more linear algorithm
  • Let L be a list of integer values. Is it possible
    to find the smallest element and then bring it to
    the first position?
  • Start from the second position
  • For each position i from 2 to n
  • If the element in the ith position is less than
    the one in the first exchange it with the number
    in position 1
  • Next i

Continue
20
Linear algorithm
  • What is the number of comparisons that will be
    made to accomplish the task of producing the
    list with the smallest number in the first
    position? If each comparison needs a time then,
    the time needed will be (n-1)a
  • If each exchange needs b time, then
  • If no exchange takes place, then T(n)(n-1)a
  • If the exchange takes place each time, then
  • T(n) (n-1)a (n-1)b (n-1)(ab)
  • So (n-1)a T(n) (n-1)(ab)

21
A sorting algorithm
  • If the process in the previous example is
    repeated and the smallest integer in the
    remaining values is placed in the second
    position, then in the same way this process needs
    n-2 number of comparisons.
  • Repeating the process for the third, fourth so
    on. Leads to SORTING the list in ascending order

22
T(n) for the sorting algorithm
  • T(n) in the minimum needs
  • (n-1)a (n-2)a (n-3)a 1a
  • T(n) in the maximum needs
  • (n-1)(ab) (n-2)(ab) 1(ab)

23
Comparison between the algorithms
  • How the two algorithms are compared?
  • If T1(n) an b (linear)
  • T2(n) an2 bn c (quadratic), then
  • how do they compare?
  • Example T1(n) 100n 50 and T2(n) n2.

24
Order of running time
  • A function f(n) is of order O(g(n) if there is a
    constant c and a number n0 such that for all n gt
    n0, f(n) c g(n)
  • Running time functions are ordered using the O
    notation.
  • Example T1 comes before T2 in the previous
    example.
  • The order of the functions constant, log,
    linear, nlog(n), n2, n3, .2n, .
Write a Comment
User Comments (0)
About PowerShow.com