2.3 Functions A function is an assignment of each element of one set to a specific element of some other set. Synonymous terms: function, assignment, map.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

Part 5. Computational Complexity (3)
CompSci 102 Discrete Math for Computer Science
Discrete Structures & Algorithms Functions & Asymptotic Complexity.
CSE115/ENGR160 Discrete Mathematics 02/22/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 02/21/12
25 June 2015Comp 122, Spring 2004 Asymptotic Notation, Review of Functions & Summations.
CSE115/ENGR160 Discrete Mathematics 03/10/11
1 Section 1.8 Functions. 2 Loose Definition Mapping of each element of one set onto some element of another set –each element of 1st set must map to something,
CS 2210 (22C:019) Discrete Structures Sets and Functions Spring 2015 Sukumar Ghosh.
Functions.
Chapter 7 Functions Dr. Curry Guinn. Outline of Today Section 7.1: Functions Defined on General Sets Section 7.2: One-to-One and Onto Section 7.3: The.
Functions, Sequences, and Sums
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Time Complexity Dr. Jicheng Fu Department of Computer Science University of Central Oklahoma.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
Sequences and Summations
Discrete Mathematics Algorithms. Introduction  An algorithm is a finite set of instructions with the following characteristics:  Precision: steps are.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
1.2. Comparing Algorithms. Learning outcomes Understand that algorithms can be compared by expressing their complexity as a function relative to the size.
DISCRETE MATHEMATICS I CHAPTER 11 Dr. Adam Anthony Spring 2011 Some material adapted from lecture notes provided by Dr. Chungsim Han and Dr. Sam Lomonaco.
February 12, 2015Applied Discrete Mathematics Week 2: Functions and Sequences 1Exercises Question 1: Given a set A = {x, y, z} and a set B = {1, 2, 3,
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
ICS 253: Discrete Structures I
22C:19 Discrete Structures Algorithms and Complexity Fall 2014 Sukumar Ghosh.
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesFunctions.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
Chapter 2: Basic Structures: Sets, Functions, Sequences, and Sums (2)
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Copyright  The McGraw-Hill Companies, Inc. Permission required for reproduction.
MSU/CSE 260 Fall Functions Read Section 1.8.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
321 Section, Week 3 Natalie Linnell. Functions A function from A to B is an assignment of exactly one element of B to each element of A. We write f(a)
1.4 Sets Definition 1. A set is a group of objects . The objects in a set are called the elements, or members, of the set. Example 2 The set of positive.
Example Prove that: “IF 3n + 2 is odd, then n is odd” Proof by Contradiction: -p = 3n + 2 is odd, q = n is odd. -Assume that ~(p  q) is true OR -(p 
Functions Reading: Chapter 6 (94 – 107) from the text book 1.
Basic Structures: Functions Muhammad Arief download dari
CompSci 102 Discrete Math for Computer Science January 31, 2012 Prof. Rodger Slides modified from Rosen AB a b c d x y z.
Chapter Algorithms 3.2 The Growth of Functions 3.3 Complexity of Algorithms 3.4 The Integers and Division 3.5 Primes and Greatest Common Divisors.
Functions Section 2.3. Section Summary Definition of a Function. – Domain, Cdomain – Image, Preimage Injection, Surjection, Bijection Inverse Function.
MATH 224 – Discrete Mathematics
3.3 Complexity of Algorithms
Basic Structures: Sets, Functions, Sequences, and Sums.
ALGORITHMS.
LIMITATIONS OF ALGORITHM POWER
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
FUNCTIONS COSC-1321 Discrete Structures 1. Function. Definition Let X and Y be sets. A function f from X to Y is a relation from X to Y with the property.
Copyright © 2014 Curt Hill Algorithm Analysis How Do We Determine the Complexity of Algorithms.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Section 2.3. Section Summary  Definition of a Function. o Domain, Cdomain o Image, Preimage  One-to-one (Injection), onto (Surjection), Bijection 
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
FUNCTIONS.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
Relations, Functions, and Matrices
CS 2210:0001 Discrete Structures Sets and Functions
MATH 224 – Discrete Mathematics
Enough Mathematical Appetizers!
Computation.
Lecture 7 Functions.
CS 2210 Discrete Structures Algorithms and Complexity
CSE15 Discrete Mathematics 02/27/17
CS100: Discrete structures
Week #3 – 9/11/13 September 2002 Prof. Marie desJardins
CS 2210 Discrete Structures Algorithms and Complexity
Applied Discrete Mathematics Week 6: Computation
Discrete Mathematics CS 2610
Enough Mathematical Appetizers!
Enough Mathematical Appetizers!
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

2.3 Functions A function is an assignment of each element of one set to a specific element of some other set. Synonymous terms: function, assignment, map Examples: –Each pixel on this screen is assigned exactly one integer: its color as a mixture of various levels of red, green, and blue. –Each person is assigned exactly one birth mother. –Each non-negative real number is assigned exactly one square root.

Notations and Drawings

a b c d 2 1 AB a b c d 2 1 A B a b c d A B a b c d A B

Domain and Codomain Range Image Pre-image

“Arithmetic” on Functions If f 1 and f 2 are functions whose codomain is the real numbers, then we can define f 1 + f 2 and f 1 f 2

Image of a Set

One-to-One (Injective) Functions: Onto (Surjective) Functions:

One-to-One Correspondences and Inverse Functions

f is increasing provided whenever f is decreasing provided whenever f is strictly increasing provided whenever f is strictly decreasing provided whenever

Examples: Proving functions are 1-1, onto and bijections

Composition of Functions

The “Graph” of a Function

Some Important Functions “floor” and “ceiling” functions

2.4 Sequences and Summations Sequences and sequence notation

Geometric progressions Arithmetic progressions

Finding the pattern… –Examples: 3, 10, 31, 94, … … 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, …

Summations and Summation Notation

Sum of a finite geometric series

Summation over members of a set Double summation

Other useful sums

Cardinality

Countability of the Rationals

3.1 Algorithms “A precise set of written instructions for performing a computation or for solving a problem”

Example: x= π↓ x =

Pseudo-code The style of the text is Pascal-like. Example: procedure maxOf3(a, b, c: integers) max := a if b > max then max := b if c > max then max := c {max now contains the largest of a, b, and c}

Properties of an Algorithm Input Output Definiteness Correctness Finiteness Effectiveness Generality

Algorithm 1: Finding the Maximum Element in a Finite Sequence

Greedy Algorithms A greedy algorithm is a class of algorithm used when a problem can be solved by making a sequence of decisions, and each such decision moves us closer to an overall solution to the problem The greedy algorithm, at any given stage, always makes the decision that moves us closest to that overall solution Do greedy algorithms always produce the “best” solution?

Greedy Algorithm for Travelling from one City to Another start finish 10km 6km 3km 7km 4km 13km 12km

Example: Describe an algorithm that puts the first three terms of a sequence of integers of arbitrary length in increasing order

Example: Describe an algorithm for determining whether a string of n characters is a palindrome.

Example: Devise an algorithm that finds the first term of a sequence of integers that equals some previous term in the sequence.

3.2 The Growth of Functions

Example

Functions of the Same Order

Use a Simpler Function as a “Yardstick” Whenever possible, we want to use as our g(x) function a relatively simple function whose behavior we are quite familiar with. Examples: g(x) = 1 g(x) = x g(x) = x 2 g(x) = log x etc.

Theorem

Some Important “Ideal Functions” g(n) = 1 g(n) = n g(n) = n 2 (and other polynomial functions n 3, n 4, etc.) g(n) = log n g(n) = n log n g(n) = 2 n g(n) = a n (any constant a > 1) g(n) = n! g(n) = n n

Combinations If f(x) = f 1 (x)+f 2 (x) where f 1 (x) = O(g 1 (x)) and f 2 (x) = O(g 2 (x)), then f(x) is O(max(g 1 (x),g 2 (x)). Example: f(x) = 2 x + log x is If f(x) = f 1 (x)f 2 (x) where f 1 (x) = O(g 1 (x)) and f 2 (x) = O(g 2 (x)), then f(x) is O(g 1 (x)g 2 (x)). Example: f(n) = (log n + 17)n 2 is

More Examples

3.3 Complexity of Algorithms Complexity is loosely defined as the degree of sensitivity of an algorithm to the size of the problem to be solved –Time complexity –Space complexity

The “Size of the Problem”

Critical Operations In any algorithm there is usually at least one critical operation, i.e. an operation which is performed at least as often as any other operation appearing in the algorithm Examples: –Comparison –Swap –Arithmetic operation such as +, *, etc.

Operation Count Analysis

Example procedure search(x, a 1, a 2, …, a n : integers) index := 0 i := 1 while index = 0 and i ≤ n do begin if x = a i then index := i i := i+1 end { ‘index’ contains 0 if x is not in the list; otherwise index is the first value of i between 1 and n for which a i = x. } Using comparison for equality as the critical operation, what is the worst-case critical operation count f(n)?

procedure search(x, a 1, a 2, …, a n : integers) index := 0 i := 1 while index = 0 and i ≤ n do begin if x = a i then index := i i := i+1 end { ‘index’ contains 0 if x is not in the list; otherwise index is the first value of i between 1 and n for which a i = x. }

Worst-Case and Average-Case Analysis for Linear Search Both are for the simple linear search algorithm. (As a matter of fact both are.)

Another Example procedure SelectionSort(a 1, a 2, …, a n : integers) for i:=1 to n-1 do begin s := i for j:=i+1 to n do if a j < a s then s := j swap a i and a s end {The elements a 1, a 2, …, a n are now in ascending order.} Using comparisons for order (, ≤, ≥) as the critical operation, what is the worst-case critical operation count f(n)?

procedure SelectionSort(a 1, a 2, …, a n : integers) for i:=1 to n-1 do begin s := i for j:=i+1 to n do if a j < a s then s := j t := a i a i := a s a s := t end {The elements a 1, a 2, …, a n are now in ascending order.}

Worst-Case, Average-Case, and Best- Case Analyses for Selection Sort All analyses are and for Selection Sort

Example 2 procedure BetterInsertionSort(a 1, a 2, …, a n : integers) for j := 2 to n do begin m  := a j { Insert a j into the sorted sequence a 1, a 2, …, a j-1 } i := j-1 while i > 0 and a i > m do begin a i+1 := a i i := i-1 a i+1 := m end { The sequence a 1, a 2, …, a n now contains all the original values, but in nondecreasing order. }

Worst-Case and Average-Case Analysis for Insertion Sort Worst-Case is Average-Case is “Best-Case” is

Commonly Used Terminology for the Complexity of Algorithms ComplexityTerminology Constant Complexity Logarithmic Complexity Linear Complexity Polynomial Complexity Exponential Complexity Factorial Complexity

Classes of Problems Intractable problem: A problem is intractable if there is a mathematical proof that no polynomial algorithm exists for solving it Unsolvable problem: A problem is unsolvable if there is a mathematical proof that no algorithm at all exists for solving it.

Classes P and NP Class P: A problem is in class P if there is a known algorithm that solves the problem in polynomial time Class NP: A problem is in class NP if there is no known polynomial algorithm for solving it, but it is known that a non- deterministic Turing Machine can check the correctness of a potential solution in polynomial time

Class NP-Complete A problem is in class NP-Complete if it belongs to a certain set of NP problems for which, if any one of them is found to be solvable with a polynomial algorithm, then all of them can be solved in polynomial time Examples –Traveling salesman problem –3-coloring problem