Presentation is loading. Please wait.

Presentation is loading. Please wait.

COT 3100, Spring 2001 Applications of Discrete Structures

Similar presentations


Presentation on theme: "COT 3100, Spring 2001 Applications of Discrete Structures"— Presentation transcript:

1 COT 3100, Spring 2001 Applications of Discrete Structures
Section #1089X - MWF 4th period Dr. Michael P. Frank Lecture #15 Mon., Feb. 12, 2001 2/12/01 Lecture #15

2 Administrivia Quiz #3 question (b) (proving 2 sets equal) being regraded more leniently, to be returned today. Already picked yours up? You can have it regraded. Note: HW #5 repeats some questions from §1.8. Even if you turned some of them in last week, please turn them in again. Lecture today: Finally do uncountable sets topic from §1.7. Start §2.1, Algorithms. 2/12/01 Lecture #15

3 Review: Orders of Growth (§1.8)
Definitions of order-of-growth sets, g:RR O(g)  {f |  c>0 k x>k |f(x)| < |cg(x)|} o(g)  {f | c>0 k x>k |f(x)| < |cg(x)|} (g)  {f | gO(f)} (g)  {f | go(f)} (g)  O(g)  (g) 2/12/01 Lecture #15

4 Infinite Cardinalities (from §1.7)
Using what we learned about functions in §1.6, it’s possible to formally define cardinality for infinite sets. We show that infinite sets come in different sizes of infinite! This gives us some interesting proof examples, in anticipation of chapter 3. 2/12/01 Lecture #15

5 Cardinality: Formal Definition
For any two (possibly infinite) sets A and B, we say that A and B have the same cardinality (written |A|=|B|) iff there exists a bijection (bijective function) from A to B. When A and B are finite, it is easy to see that such a function exists iff A and B have the same number of elements nN. 2/12/01 Lecture #15

6 Countable versus Uncountable
For any set S, if S is finite or |S|=|N|, we say S is countable. Else, S is uncountable. Intuition behind “countable:” we can enumerate (generate in series) elements of S in such a way that any individual element of S will eventually be counted in the enumeration. Examples: N, Z. Uncountable: No series of elements of S (even an infinite series) can include all of S’s elements. Examples: R, R2, P(N) 2/12/01 Lecture #15

7 Countable Sets: Examples
The set Z is countable. Proof: Consider f:ZN where f(i)=2i for i0 and f(i) = 2i1 for i<0. Note f is bijective. The set of all ordered pairs of natural numbers (n,m) is countable. Consider listing the pairs in order by their sum s=n+m, then by n. Every pair appears once in this series; the generating function is bijective. 2/12/01 Lecture #15

8 Uncountable Sets: Example
Show that the open interval [0,1)  {rR|0r <1} is uncountable. Proof by diagonalization: (Cantor, 1891) Assume there is a series {ri} = r1, r2, ... containing all elements r[0,1). Consider listing the elements of {ri} in decimal notation (though any base will do) in order of increasing index: ... 2/12/01 Lecture #15

9 Uncountability of Reals, cont’d
A postulated enumeration of the reals: r1 = 0.d1,1 d1,2 d1,3 d1,4 d1,5 d1,6 d1,7 d1,8… r2 = 0.d2,1 d2,2 d2,3 d2,4 d2,5 d2,6 d2,7 d2,8… r3 = 0.d3,1 d3,2 d3,3 d3,4 d3,5 d3,6 d3,7 d3,8… r4 = 0.d4,1 d4,2 d4,3 d4,4 d4,5 d4,6 d4,7 d4,8… . . . Now, consider a real number generated by taking the digits di,i that lie along the diagonal in this figure and replacing them with different digits (other than 9). That real doesn't appear in the list! 2/12/01 Lecture #15

10 Uncountability of Reals, fin.
E.g., a postulated enumeration of the reals: r1 = … r2 = … r3 = … r4 = … OK, now let’s add 1 to each of the diagonal digits, except change 8’s and 9’s to 0. 0.4103… can’t be on the list anywhere! 2/12/01 Lecture #15

11 Proven impossible to prove or disprove!
Transfinite Numbers The cardinalities of infinite sets are not natural numbers, but special objects called transfinite cardinal numbers. The cardinality of the natural numbers, 0|N|, is the first transfinite cardinal number. (There are none smaller.) The continuum hypothesis claims that |R|=1, the second transfinite cardinal. Proven impossible to prove or disprove! 2/12/01 Lecture #15

12 Do Uncountable Sets Really Exist?
The set of objects that can be defined using finite-length strings of symbols (“descriptions”) is countable. Therefore, any uncountable set must consist mostly of elements which individually have no finite description. Löwenheim-Skolem theorem: No consistent theory forces an interpretation involving uncountables. The “constructivist” school asserts that only objects constructible from finite descriptions exist. (eg R) Most mathematicians are happy to use uncountable sets anyway, because postulating their existence has not led to any demonstrated contradictions (so far). 2/12/01 Lecture #15

13 Countable vs. Uncountable
You should: Know how to define “same cardinality” in the case of infinite sets. Know the definitions of countable and uncountable. Know how to prove (in easy cases) that sets are either countable or uncountable. 2/12/01 Lecture #15

14 Chapter 2: More Fundamentals
§2.1: Algorithms (Formal procedures) §2.2: Complexity of algorithms Analysis using order-of-growth notation. §2.3: The Integers & Division Some basic number theory. §2.6: Matrices Some basic linear algebra. 2/12/01 Lecture #15

15 §2.1: Algorithms The foundation of computer programming.
Most generally, an algorithm just means a definite procedure for performing some sort of task. A computer program is simply a description of an algorithm in a language precise enough for a computer to understand, requiring only operations the computer already knows how to do. We say that a program implements (or “is an implementation of”) its algorithm. 2/12/01 Lecture #15

16 Algorithms You Already Know
Grade school arithmetic algorithms: How to add any two natural numbers written in decimal on paper using carries. Similar: Subtraction using borrowing. Multiplication & long division. Your favorite cooking recipe. How to register for classes at UF. 2/12/01 Lecture #15

17 Programming Languages
Some common programming languages: Newer: Java, C, C++, Visual Basic, JavaScript, Perl, Tcl, Pascal Older: Fortran, Cobol, Lisp, Basic Assembly languages, for low-level coding. In this class we will use an informal, Pascal-like “pseudo-code” language. You should know at least 1 real language! 2/12/01 Lecture #15

18 Algorithm Example (English)
Task: Given a sequence {ai}=a1,…,an, aiN, say what its largest element is. Set the value of a temporary variable v (largest element seen so far) to a1’s value. Look at the next element ai in the sequence. If ai>v, then re-assign v to the number ai. Repeat previous 2 steps until there are no more elements in the sequence, & return v. 2/12/01 Lecture #15

19 Executing an Algorithm
When you start up a piece of software, we say the program or its algorithm are being run or executed by the computer. Given a description of an algorithm, you can also execute it by hand, by working through all of its steps on paper. Before ~WWII, “computer” meant a person whose job was to run algorithms! 2/12/01 Lecture #15

20 Executing the Max algorithm
Let {ai}=7,12,3,15,8. Find its maximum… Set v = a1 = 7. Look at next element: a2 = 12. Is a2>v? Yes, so change v to 12. Look at next element: a2 = 3. Is 3>12? No, leave v alone…. Is 15>12? Yes, v=15… 2/12/01 Lecture #15

21 Algorithm Characteristics
Some important features of algorithms: Input. Information or data that comes in. Output. Information or data that goes out. Definiteness. Precisely defined. Correctness. Outputs correctly relate to inputs. Finiteness. Won’t take forever to describe or run. Effectiveness. Individual steps are all do-able. Generality. Works for many possible inputs. Efficiency. Takes little time & memory to run. 2/12/01 Lecture #15

22 Our Pseudocode Language: §A2
Procedure declaration: procedure name(argument: type) Imperative statements: variable := expression informal statement begin statements end {comment} if condition then statement [else statement] for variable := initial value to final value statement while condition statement procname(arguments) 2/12/01 Lecture #15

23 procedure procname(arg: type)
Declares that the following text defines a procedure named procname that takes inputs (arguments) named arg which are data objects of the type type. Example: procedure maximum(L: list of integers) [statements defining maximum…] 2/12/01 Lecture #15

24 variable := expression
An assignment statement evaluates the expression expression, then reassigns the variable variable to the value that results. Example: v := 3x (If x is 2, changes v to 13.) In pseudocode (but not real code), the expression might be informal: x := largest integer in the list L 2/12/01 Lecture #15

25 Informal statement Sometimes we may write a statement as an informal English imperative, if the meaning is still clear and precise. Keep in mind that real programming languages never allow this. When we ask for an algorithm to do so-and-so, writing “Do so-and-so” isn’t enough! Break down algorithm into detailed steps. 2/12/01 Lecture #15

26 begin statements end Groups a sequence of statements together: begin statement statement … statement n end Allows sequence to be used like a single statement. Might be used: After a procedure declaration. In an if statement after then or else. In the body of a for or while loop. 2/12/01 Lecture #15

27 {comment} Not executed.
Natural-language text explaining some aspect of the procedure to the reader. Also called a remark in some real programming languages. Example: {Note that v is the largest integer seen so far.} 2/12/01 Lecture #15

28 if condition then statement
Evaluate the propositional expression condition. If the resulting truth value is true, then execute the statement statement; otherwise, just skip ahead to the next statement. Variant: if cond then stmt1 else stmt2 Like before, but iff truth value is false, executes stmt2. 2/12/01 Lecture #15

29 while condition statement
Evaluate the propositional expression condition. If the resulting value is true, then execute statement. Evaluate the condition again, and repeat over and over until finally the condition evaluates to false. 2/12/01 Lecture #15

30 while condition statement
Also equivalent to infinite nested ifs: if condition begin statement if condition begin statement … end end 2/12/01 Lecture #15

31 for var := initial to final stmt
Initial is an integer expression. Final is another integer expression. Repeatedly execute stmt, first with variable var=initial, then with var=initial+1, then with var=initial+2, etc., then finally with var=final. What happens if stmt changes the value that initial or final evaluates to? 2/12/01 Lecture #15

32 for var := initial to final stmt
For can be defined in terms of while as: begin var := initial while var  final begin stmt var := var end end 2/12/01 Lecture #15

33 procedure(argument) A procedure call statement invokes the named procedure, giving it as its input the value of the argument expression. Various real programming languages refer to procedures as functions (the notation is similar to function application f(x)), or as subroutines, or methods. 2/12/01 Lecture #15

34 Max procedure in pseudocode
procedure max(a1, a2, …, an: integers) v := a1 {largest element so far} for i := 2 to n if v < ai then v := ai {at this point v’s value is the largest integer in the list} 2/12/01 Lecture #15

35 Another example task Problem of searching an ordered list.
Given a list L of n elements that are sorted into a definite order (e.g., numeric, alphabetical), And given a particular element x, Determine whether x appears in the list, and if so, return its index (position) in the list. Problem occurs often in many contexts. Let’s find an efficient algorithm! 2/12/01 Lecture #15

36 Search alg. 1: Linear Search
procedure linear search (x: integer, a1, a2, …, an: distinct integers) i := 1 while (i  2/12/01 Lecture #15


Download ppt "COT 3100, Spring 2001 Applications of Discrete Structures"

Similar presentations


Ads by Google