Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics and its Applications

Similar presentations


Presentation on theme: "Discrete Mathematics and its Applications"— Presentation transcript:

1 Discrete Mathematics and its Applications
Yonsei Univ. at Wonju Dept. of Mathematics 이산수학 Discrete Mathematics Prof. Gab-Byung Chae Slides for a Course Based on the Text Discrete Mathematics & Its Applications (6th Edition) by Kenneth H. Rosen A word about organization: Since different courses have different lengths of lecture periods, and different instructors go at different paces, rather than dividing the material up into fixed-length lectures, we will divide it up into “modules” which correspond to major topic areas and will generally take 1-3 lectures to cover. Within modules, we have smaller “topics”. Within topics are individual slides. 채갑병 (c) , Michael P. Frank

2 Rosen 6th ed., §2.1 ~31 slides, ~1 lecture
Module #5: Algorithms Rosen 6th ed., §2.1 ~31 slides, ~1 lecture 채갑병

3 §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. 채갑병

4 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. 채갑병

5 Programming Languages
Some common programming languages: Newer: Java, C, C++, Visual Basic, JavaScript, Perl, Tcl, Pascal, Python Older: Fortran, Cobol, Lisp, Basic Assembly languages, for low-level coding. In this class we will use an informal, Pascal-like “pseudo-code” language. 채갑병

6 Algorithm Example (English)
Task: Given a sequence {ai}=a1,…,an, aiN, say what its largest element is. Step 1. Set the value of a temporary variable v (largest element seen so far, 프로그램 진행중 임의의 시점에서 가장 큰 수를 저장 하기 위한 변수.) to a1’s value. Step 2. Look at the next element ai in the sequence. 채갑병

7 Step 3. If ai>v, then re-assign v to the number ai.
Step 4. Repeat previous 2 steps until there are no more elements in the sequence, & return v. 채갑병

8 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! 채갑병

9 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… 채갑병

10 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. 채갑병

11 Our Pseudocode Language
procedure name(argument: type) 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) Not defined in book: return expression 채갑병

12 Max procedure in pseudocode
procedure max(a1, a2, …, an: integers) v := a1 {largest element so far} for i := 2 to n {go thru rest of elems} if ai > v then v := ai {found bigger?} {at this point v’s value is the same as the largest integer in the list} return v 채갑병

13 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. Let’s find an efficient algorithm! 채갑병

14 Search alg. #1: 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 {index or 0 if not found} 채갑병

15 Search alg. #2: Binary Search
Basic idea: 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. <x <x <x >x 채갑병

16 Search alg. #2: Binary Search
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 채갑병


Download ppt "Discrete Mathematics and its Applications"

Similar presentations


Ads by Google