College of Information Technology & Design

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

MATH 224 – Discrete Mathematics
Analysis of Algorithms CS Data Structures Section 2.6.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Chapter 9: Searching, Sorting, and Algorithm Analysis
CompSci 102 Discrete Math for Computer Science
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
CSE115/ENGR160 Discrete Mathematics 02/24/11 Ming-Hsuan Yang UC Merced 1.
Efficiency of Algorithms
Lecture 2: Fundamental Concepts
1 Module 2: Fundamental Concepts Problems Programs –Programming languages.
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
The Design and Analysis of Algorithms
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 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.
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.
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.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
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.
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
Counting Discrete Mathematics. Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter passwords are there?”
UNIT-I INTRODUCTION ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 1:
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
ALGORITHMS.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
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. 大葉大學 資訊工程系 黃鈴玲.
CSE15 Discrete Mathematics 03/06/17
Growth of Functions & Algorithms
Applied Discrete Mathematics Week 2: Functions and Sequences
COP 3503 FALL 2012 Shayan Javed Lecture 15
Data Structures and Algorithms
CSE322 Recursive and Recursively enumerable sets
Enough Mathematical Appetizers!
Lecture 2: Introduction to Algorithms
Computation.
COMS W1004 Introduction to Computer Science and Programming in Java
Algorithms Chapter 3 With Question/Answer Animations
Analysis Algorithms.
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Applied Discrete Mathematics Week 6: Computation
CSE 373 Data Structures and Algorithms
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Enough Mathematical Appetizers!
CSCE 222 Discrete Structures for Computing
Revision of C++.
Discrete Mathematics and its Applications
Enough Mathematical Appetizers!
Algorithms.
Discrete Mathematics CS 2610
Presentation transcript:

College of Information Technology & Design Discrete Mathematics Algorithms University of Jazeera College of Information Technology & Design Khulood Ghazal

Algorithms An algorithm : is a finite set of precise instructions for performing a computation or for solving a problem. OR it is a sequence of steps leads to the desire answer. How can we describe an algorithm ? 1. English language. 2.Pseudocode. 3.Computer language.

Algorithms Example 1: Describe an algorithm for finding the maximum (largest) value in a finite sequence of integers. Solution :( using English language ) . 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.) 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. Repeat the previous step if there are more integers in the sequence. Stop when there are no integers left in the sequence. The temporary maximum at this point is the largest integer in the sequence.

Algorithms n is the number of integers in the list. The pseudocode for Finding the Maximum Element in a Finite Sequence. n is the number of integers in the list. procedure max ( a1,a2,…,an : integers ) max := a1 for i := 2 to n if ai > max then max := ai return max { max is the largest element } Example : list a= {6 4 10 } max=6 n = 3 i=2 4>6 (F) i=3 10>6 (T) then max=10 i=4 return 10 if ai > max =F And i<=n

Properties of Algorithms Properties that all algorithms generally share are: 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 the algorithm must be defined precisely. Correctness: An algorithm should produce the correct output values for each set of input values. 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. Generality: The function should be applicable for all problems of the desired form, not just for a particular set of input values.

Searching Algorithms 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.

Search algorithm #1: Linear Search Searching Algorithms Search algorithm #1: Linear Search Basic idea : The algorithm begins by comparing x and a1 .when x = a1 the solution is the location of a1 (namely 1). when x  a1 ,compare x with a2 ,if x= a2 ,the solution is the location of a2 (namely 2 ) . When xa2 ,compare x with a3 . continue this process, comparing x successively with each term of the list until a match is found ,where the solution is the location of that term, unless no match occurs, the solution is 0.

Linear Search The pseudocode for the linear search algorithm n is the number of integers in the list. procedure linear search (x: integer, a1, a2, …, an: distinct integers) i := 1 while (i  n  x  ai ) i := i + 1 End if i  n then location := i else location := 0 return location {index or 0 if not found} Example : list a={ 3 6 7 8} x=7 n=4 i=1 1  4  7 3 (T ^ T=T) i=2 2  4  76 (T ^ T=T) i=3 3  4  77 (T ^ F=F) 3 4 then location:=3 return 3 (index of 7)

Search algorithm #2: Binary Search Discrete Mathematics and its Applications 2017-04-06 Search algorithm #2: Binary Search Basic idea: On each step, look at the middle element of the remaining list to eliminate half of it. <x <x <x >x (c)2001-2002, Michael P. Frank

Search algorithm #2: Binary Search Discrete Mathematics and its Applications 2017-04-06 Search algorithm #2: Binary Search Example : To search for 19 in the list. 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22 . First split this list, which has 16 terms into two smaller list with eight term each; namely : 1 2 3 5 6 7 8 10 12 13 15 16 18 19 20 22 Then compare 19 and the largest term in the first list , since 10<19 ,the search for 19 can be restricted to the list containing the numbers(12 13…….22 -9th to 16th terms ) next split this list into two smaller lists of four terms each ,namely : 12 13 15 16 18 19 20 22 Since 16<19 the search restricted to the second of these lists(13th to 16th terms). The list 18 19 20 22 is split into two lists, namely : 18 19 20 22 Since 19 not <19 the search restricted to the first list (18 19_13th and 14th terms ) Next this list is split into two lists of one term each: 18 19 Since 18<19 the search restricted to the second list ,the list containing 19 (14th term of the list) and 19 is located as 14th term of the original list . (c)2001-2002, Michael P. Frank

Search algorithm #2: Binary Search The pseudocode for the binary search algorithm n is the number of integers in the list. procedure binary search(x:integer, a1, a2, …, an: distinct integers) i := 1 {left endpoint of search interval} j := n {right endpoint of search interval} while i < j begin {while interval has >1 item} m := (i + j ) /2 {midpoint} if x > am then i := m+1 else j := m end if x = ai then location := i else location := 0 return location