Chapter 3 3.1 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.

Slides:



Advertisements
Similar presentations
22C:19 Discrete Math Algorithms and Complexity
Advertisements

College of Information Technology & Design
College of Information Technology & Design
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithms Example Algorithms Algorithmic Paradigms Growth of Functions Big-O and other Notation.
Algorithms Chapter 3 Sec 3.1 &3.2 With Question/Answer Animations.
CompSci 102 Discrete Math for Computer Science
CSE115/ENGR160 Discrete Mathematics 02/28/12
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
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
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.
Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices
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.
Algorithms Section 3.1. Problems and Algorithms In many domains there are key general problems that ask for output with specific properties when given.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.
22C:19 Discrete Structures Algorithms and Complexity Fall 2014 Sukumar Ghosh.
Fall 2002CMSC Discrete Structures1 Enough Mathematical Appetizers! Let us look at something more interesting: Algorithms.
MCA-2012Data Structure1 Algorithms Rizwan Rehman CCS, DU.
The Fundamentals: Algorithms, the Integers & Matrices.
CompSci 102 Discrete Math for Computer Science
1 Algorithms CS/APMA 202 Rosen section 2.1 Aaron Bloomfield.
Section 3.1. Section Summary Properties of Algorithms Algorithms for Searching and Sorting Greedy Algorithms Halting Problem.
Example { 1 – –1} Use Bubble Sort (sort in increasing order} After first pass { –1 50} After Second Pass { } After.
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.
CS 103 Discrete Structures Lecture 12
The Fundamentals. Algorithms What is an algorithm? An algorithm is “a finite set of precise instructions for performing a computation or for solving.
ALGORITHMS.
22C:19 Discrete Math Algorithms and Integers Fall 2010 Sukumar Ghosh.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
Chapter 3 1 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki,
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Chapter 3. Chapter Summary Algorithms Example Algorithms Growth of Functions Big-O and other Notation Complexity of Algorithms.
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithms Example Algorithms Algorithmic Paradigms Growth of Functions Big-O and other Notation.
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.
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithm and Growth of Function (This slide) Algorithms - Sec 3.1 – Lecture 13 Example Algorithms.
Discrete Mathematics Chapter 2 The Fundamentals : Algorithms, the Integers, and Matrices. 大葉大學 資訊工程系 黃鈴玲.
Chapter 3 Sec 3.1 &3.2 With Question/Answer Animations 1.
Chapter 3 1 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki,
Algorithms (Section 3.1) The Growth of Functions (Section 3.2)
Algorithms Chapter 3.
CSE15 Discrete Mathematics 03/06/17
Growth of Functions & Algorithms
Applied Discrete Mathematics Week 2: Functions and Sequences
CSE15 Discrete Mathematics 03/13/17
Enough Mathematical Appetizers!
Computation.
CS 2210 Discrete Structures Algorithms and Complexity
Algorithms Chapter 3 With Question/Answer Animations
Analysis Algorithms.
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
CS 2210 Discrete Structures Algorithms and Complexity
Applied Discrete Mathematics Week 6: Computation
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
CMSC 203, Section 0401 Discrete Structures Fall 2004 Matt Gaston
Enough Mathematical Appetizers!
CSCE 222 Discrete Structures for Computing
Discrete Mathematics and its Applications
Enough Mathematical Appetizers!
Algorithms.
Discrete Mathematics CS 2610
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

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 3.6 Integers and Algorithms 3.7 Applications of Number Theory 3.8 Matrices 1

Chapter Algorithms –Searching Algorithms –Greedy Algorithms –The Halting Problem 2

Algorithm Definition 1: An algorithm is a finite set of precise instructions for performing a computation or for solving a problem. Example 1: Describe an algorithm for finding the maximum (largest) value in a finite sequence of integers. 3

We perform the following steps 1.Set the temporary maximum equal to the first integer in the sequence. (the temporary maximum will be the largest integer examined at any stage of the procedure.) 2.Compare the next integer in the sequence to the temporary maximum, and if it is larger than the temporary maximum, set the temporary maximum equal to this integer. 3.Repeat the previous step if there are more integers in the sequence. 4.Stop when there are no integers left in the sequence. The temporary maximum at this point is the largest integer in the sequence. 4

Pseudocode Pseudocode provides an intermediate step between an English language description of an algorithm and an implementation of this algorithm in a programming language. Algorithm 1: Finding the maximum element in a finite sequence. procedure max(a 1, a 2,...,a n : integers) max := a 1 for i: =2 to n if max < a i then max := a i {max is the largest element} 5

Property of Algorithm Input. Output. Definiteness. The steps of an algorithm must be defined precisely. Correctness. Finiteness. Effectiveness. Generality. The procedure should be applicable for all problems of the desired form, not just for a particular set of input values. 6

Searching Algorithms Search Problem: Locating an element in an (ordered) list. Linear search Binary search (ordered list) 7

The linear search Algorithm 2 : the linear search algorithm procedure linear search (x: integer, a 1, a 2, …,a n : distinct integers) i :=1; while ( i ≤n and x ≠ a i ) i := i + 1 If i ≤ n then location := i Else location := 0 {location is the subscript of the term that equals x, or is 0 if x is not found} 8

The binary search Algorithm 3: the binary search algorithm Procedure binary search (x: integer, a 1, a 2, …,a n : increasing integers) i :=1 { i is left endpoint of search interval} j :=n { j is right endpoint of search interval} While i < j begin m :=  (i+j)/2  if x > a m then i := m+1 else j := m end If x = a i then location := i else location :=0 {location is the subscript of the term equal to x, or 0 if x is not found} Example 3: to search for 19 in the list Example 3: to search for 19 in the list

Sorting Sort: –Sorting is putting elements into a list in which the elements are in increasing order. E.g. 1)7,2,1,4,5,9 -> 1,2,4,5,7,9 2)d,h,c,a,f -> a,c,d,f,h. Bubble sort Insertion sort 10

Bubble Sort ALGORITHM 4: The Bubble Sort procedure bubble sort (a 1, a 2, …,a n : real numbers with n ≥2) for i := 1 to n-1 for j := 1 to n- i if a j > a j+1 then interchange a j and a j+1 {a 1, a 2, …,a n is in increasing order} Example 4: Use the sort to put 3, 2, 4, 1, 5 into increasing order. 11

Bubble Sort

Insertion Sort Algorithm 5: The Insertion Sort procedure insertion sort (a 1, a 2, …,a n : real numbers with n ≥2) for j := 2 to n begin i := 1 while a j > a i i := i + 1 m := a j for k :=0 to j-i-1 a j-k := a j-k-1 a i := m end {a 1, a 2, …,a n are sorted} Example 5: Use the insertion sort to put the elements of the list 3, 2, 4, 1, 5 into increasing order. Example 5: Use the insertion sort to put the elements of the list 3, 2, 4, 1, 5 into increasing order. 13

Greedy Algorithm Optimization Problem: find the best solution. Algorithms that make what seems to be the best choice at each step are called greedy algorithms. 14

Example 6: Consider the problem of making n cents change with quarters, dimes, nickels, and pennies, and using the least total number of coins. Algorithm 6: Greedy Change-Marking Algorithm procedure change (c 1, c 2, …, c r : values of denominations of coins, where c 1 > c 2 > … > c r ; n: a positive integer) for i := 1 to r while n ≥ c i begin add a coin with value c i to the change n := n – c i end 15

The Halting Problem There is a problem that cannot be solved using any procedure. That is, there are unsolvable problems. Halting Problem FIGURE 2 Showing that the Halting Problem is Unsolvable. 16