Discrete Mathematics CS 2610

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

College of Information Technology & Design
MATH 224 – Discrete Mathematics
CSC 2300 Data Structures & Algorithms March 16, 2007 Chapter 7. Sorting.
Chapter 1 – Basic Concepts
What is an Algorithm? (And how do we analyze one?)
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CSE115/ENGR160 Discrete Mathematics 02/24/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 03/10/11
Analysis of Algorithms CS 477/677
Analysis of Algorithm.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Sorting CS 202 – Fundamental Structures of Computer Science II Bilkent.
CS Discrete Mathematical Structures Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, 9:30-11:30a.
The Fundamentals: Algorithms, the Integers & Matrices.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Lecture 2 MAS 714 Hartmut Klauck
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
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.
Jessie Zhao Course page: 1.
ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
1 Algorithms CS/APMA 202 Rosen section 2.1 Aaron Bloomfield.
Data Structure Introduction.
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.
1 Algorithms CS 202 Epp section ??? Aaron Bloomfield.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
ALGORITHMS.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
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.
Chapter 3 Chapter Summary  Algorithms o Example Algorithms searching for an element in a list sorting a list so its elements are in some prescribed.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
Lecture 2 Algorithm Analysis
CSE15 Discrete Mathematics 03/06/17
Discrete Mathematics CS 2610
Growth of Functions & Algorithms
Applied Discrete Mathematics Week 2: Functions and Sequences
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2012
Analysis of Algorithms
CSE15 Discrete Mathematics 03/13/17
COP 3503 FALL 2012 Shayan Javed Lecture 15
Algorithm Analysis CSE 2011 Winter September 2018.
CS 583 Fall 2006 Analysis of Algorithms
Enough Mathematical Appetizers!
Computation.
Lecture 7 Functions.
CS 2210 Discrete Structures Algorithms and Complexity
Analysis of Algorithms CS 477/677
Linear and Binary Search
Algorithms Chapter 3 With Question/Answer Animations
Algorithm design and Analysis
Analysis Algorithms.
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Applied Discrete Mathematics Week 6: Computation
Sorting … and Insertion Sort.
Discrete Mathematics CS 2610
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Enough Mathematical Appetizers!
Discrete Mathematics and its Applications
Enough Mathematical Appetizers!
Discrete Mathematics 7th edition, 2009
Analysis of Algorithms
CS 583 Analysis of Algorithms
Algorithms.
Presentation transcript:

Discrete Mathematics CS 2610 February 24, 2009 -- part 4

Uncountable sets Theorem: The set of real numbers is uncountable. If a subset of a set is uncountable, then the set is uncountable. The cardinality of a subset is at least as large as the cardinality of the entire set. It is enough to prove that there is a subset of R that is uncountable Theorem: The open interval of real numbers [0,1) = {r  R | 0  r < 1} is uncountable. Proof by contradiction using the Cantor diagonalization argument (Cantor, 1879)

Uncountable Sets: R Proof (BWOC) using diagonalization: Suppose R is countable (then any subset say [0,1) is also countable). So, we can list them: r1, r2, r3, … where r1 = 0.d11d12d13d14… the dij are digits 0-9 r2 = 0.d21d22d23d24… r3 = 0.d31d32d33d34… r4 = 0.d41d42d43d44… etc. Now let r = 0.d1d2d3d4… where di = 4 if dii  4 di = 5 if dii = 4 But r is not equal to any of the items in the list ∴ it’s missing from the list so we can’t list them after all. r differs from ri in the ith position, for all i. So, our assumption that we could list them all is incorrect.

Algorithms An Algorithm is a finite set of precise instructions for performing a computation or for solving a problem. Properties of an algorithm: input: input values are from a specified set output: output values are from a specified set definiteness: each step is precisely defined correctness: correct output produced finiteness: takes a finite number of steps effectiveness: each step is finite & exact generality: applicable to various input sizes

Analysis of Algorithms Analyzing an algorithm Time complexity Space complexity Running time needed by an algorithm as a function of the size of the input Denoted as T(N) We are interested in measuring how fast the time complexity increases as the input size grows Asymptotic Time Complexity of an Algorithm

Pseudocode procedure procName(argument: type) variable := expression informal statement begin statements end {comment} if condition then statement1 [else statement2] for variable := initial value to final value statement while condition statement return expression procName(arg1,..,argn)

Algorithm Complexity Worst Case Analysis Average Case Analysis Largest number of operations to solve a problem of a specified size. Analyze the worst input case for each input size. Upper bound of the running time for any input. Most widely used. Average Case Analysis Average number of operations over all inputs of a given size Sometimes it’s too complicated

Example: Max Algorithm procedure max(a1, a2, …, an: integers) v := a1 for i := 2 to n if ai > v then v := ai return v 1 n n - 1 ? 0, 1, .., n -1 1 How many times is each step executed ? Worst-Case: the input sequence is a strictly increasing sequence

Searching Algorithms Searching Algorithms Problem: Find an element x in a list a1,…an (not necessarily ordered) Linear Search Strategy: Examine the sequence one element after another until all the elements have been examined or the current element being examined is the element x.

Example: Linear Search procedure linear search (x: integer, a1, a2, …, an: distinct integers) i := 1 while (i  n  x  ai) i := i + 1 if i  n then location := i else location := 0 return location Worst-Case occurs when x is the last element in the sequence Best Case occurs when x is the first element in the sequence

Example: Linear Search Average Case: x is the first element: 1 loop comparison x is the second element 2 loop comparisons, 1 iteration of the loop x is the third element 3 loop comparisons, 2 iterations of the loop x is n-th element n loop comparisons, n-1 iterations of the loop

Binary Search Problem: Locate an element x in a sequence of sorted elements in non-decreasing order. Strategy: On each step, look at the middle element of the remaining list to eliminate half of it, and quickly zero in on the desired element.

Binary Search Suppose n=2k procedure binary search (x:integer, a1, a2, …, an: integer) {a1, a2, …, an are distinct integers sorted smallest to largest} i := 1 {start of search range} j := n {end of search range} while i < j begin m := (i +j)/2 if x > am then i := m + 1 else j := m end if x = ai then location := i else location := 0 return location Suppose n=2k

Binary Search Binary Search The loop is executed k times k=log2(n)

Linear Search vs. Binary Search Linear Search Time Complexity: T(n) is O(n) Binary Search Time Complexity: T(n) is O(log2n)

Sorting Algorithms Problem: Given a sequence of numbers, sort the sequence in weakly increasing order. Sorting Algorithms: Input: A sequence of n numbers a1, a2, …, an Output: A reordering of the input sequence (a’1, a’2, …, a’n) such that a’1  a’2  …  a’n

Bubble Sort Smallest elements “float” up to the top (front) of the list, like bubbles in a container of liquid Largest elements sink to the bottom (end). See the animation at: http://math.hws.edu/TMCM/java/xSortLab

Example: Bubble Sort procedure bubblesort (a1, a2, …, an: distinct integers) for i = 1 to n-1 for j = 1 to n-i if (aj > aj+1) then swap aj and aj+1 Worst-Case: The sequence is sorted in decreasing order At step i The loop condition of the inner loop is executed n – i + 1 times. The body of the loop is executed n – i times

Algorithm- Insertion Sort For each element: The elements on its left are already sorted Shift the element with the element on the left until it is in the correct place. See animation http://math.hws.edu/TMCM/java/xSortLab/

Algorithm- Insertion Sort procedure insertSort (a1, a2, …, an: distinct integers) for j=2 to n begin i=j - 1 while i > 0 and ai > ai+1 swap ai and ai+1 i=i-1 end Worst-Case: The sequence is in decreasing order At step j, the while loop condition is executed j times the body of the loop is executed j-1 times