1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

College of Information Technology & Design
The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.
MATH 224 – Discrete Mathematics
CompSci 102 Discrete Math for Computer Science
Chapter 11 Sorting and Searching. Topics Searching –Linear –Binary Sorting –Selection Sort –Bubble Sort.
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.
CHAPTER 11 Sorting.
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.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Chapter Complexity of Algorithms –Time Complexity –Understanding the complexity of Algorithms 1.
Chapter 3: The Fundamentals: Algorithms, the Integers, and Matrices
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.
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.
Algorithms Section 3.1. Problems and Algorithms In many domains there are key general problems that ask for output with specific properties when given.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Chapter 3 Sec 3.3 With Question/Answer Animations 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 12 Binary Search and QuickSort Fundamentals of Java.
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.
Section 3.1. Section Summary Properties of Algorithms Algorithms for Searching and Sorting Greedy Algorithms Halting Problem.
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
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
ALGORITHMS.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
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.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
Kruse/Ryba Ch071 Object Oriented Data Structures Searching STL Vector Sequential Search Binary Search Comparison Trees.
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. 大葉大學 資訊工程系 黃鈴玲.
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
Discrete Structures – CNS2300
CSE15 Discrete Mathematics 03/13/17
Enough Mathematical Appetizers!
Computation.
Algorithms Chapter 3 With Question/Answer Animations
CSc 110, Spring 2017 Lecture 39: searching.
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
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
Presentation transcript:

1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms, the Integers, and Matrices

2 Section 2.1 Algorithms An algorithm is a definite procedure for solving a problem using a finite number of steps.

3 Properties of Algorithms Input - An algorithm has input values from a specified set. Output - From each set of input values an algorithm produces output values from a specified set. The output values are the solution to the problem. Definiteness - The steps of an algorithm must be defined precisely.

4 Properties of Algorithms Finiteness - An algorithm should produce the desired output after a finite (but perhaps large) number of steps for any input in the set. Effectiveness - It must be possible to perform each step of an algorithm exactly and in a finite amount of time.

5 Properties of Algorithms Generality - The procedure should be applicable for all problems of the desired form, not just for a particular set of input values

6 Maximum Element in a Finite Set 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}

7 Searching Algorithm procedure linear search(x:integer, a 1, a 2, …, a n : distinct integers) i := 1 while (i ai) i := i + 1 if i <= n then location :=i else location := 0 { location is the subscript of the term that equal x, or is 0 if x is not found}

Binary Search For this algorithm to work, the data must be sorted in the array.

Binary Search Suppose the item of interest has value 62! The algorithm finds the midpoint of the array (0+11)/2 = 5 and looks in that position. If the item is found, the search is over

Binary Search In this case, the item wasn’t found. However, since the array is sorted and 62 > 45, we know it should be below the midpoint, if it exists. We now look at the midpoint of what is left by calculating the index (6+11)/2 = 8, and look there.

Binary Search If the item is found, the search is over. In this case, the search goes on.

Binary Search We know 62 < 67 so we should restrict our search to the portion above that has not been searched. If we recalculate the search index (6+7)/2=6 we see that we are narrowing down on the location.

Binary Search But, we are still not there. There is really only one place left to look but the algorithm doesn’t know this. It only knows that 62>55 so it should look below the current location.

Binary Search One final calculation of the index (7+7)/2 = 7 leads us to the location we have been looking for. Note that we only repeated the process and comparison four times (looking in 5, 8, 6, 7) and that is pretty good when there are actually 11 cells.

15 Sorting Algorithms Bubble Sort Insertion Sort Selection Sort Quick Sort Heap Sort Radix Sort Shell Sort

16 Greedy Algorithms Algorithms that make what seems to be the “best” choice at each step

17 finished