Discrete Mathematics

Similar documents
Microsoft PowerPoint - 26.pptx

Microsoft PowerPoint Relations.pptx

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

Microsoft PowerPoint - 27.pptx

본문01

step 1-1

Microsoft PowerPoint Predicates and Quantifiers.ppt

Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

Microsoft PowerPoint 일변수 방정식과 함수(1).ppt

2002년 2학기 자료구조

Microsoft PowerPoint - ch03ysk2012.ppt [호환 모드]

하나님의 선한 손의 도우심 이세상에서 가장 큰 축복은 하나님이 나와 함께 하시는 것입니다. 그 이 유는 하나님이 모든 축복의 근원이시기 때문입니다. 에스라서에 보면 하나님의 선한 손의 도우심이 함께 했던 사람의 이야기 가 나와 있는데 에스라 7장은 거듭해서 그 비결을

Stage 2 First Phonics

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

<B3EDB9AEC1FD5F3235C1FD2E687770>

강의10

<32B1B3BDC32E687770>

chap 5: Trees

<31342D3034C0E5C7FDBFB52E687770>

大学4年生の正社員内定要因に関する実証分析

2 min 응용 말하기 01 I set my alarm for It goes off. 03 It doesn t go off. 04 I sleep in. 05 I make my bed. 06 I brush my teeth. 07 I take a shower.

Output file

Microsoft PowerPoint - PL_03-04.pptx

Line (A) å j a k= i k #define max(a, b) (((a) >= (b))? (a) : (b)) long MaxSubseqSum0(int A[], unsigned Left, unsigned Right) { int Center, i; long Max

<C1DF3320BCF6BEF7B0E8C8B9BCAD2E687770>

untitled

11¹Ú´ö±Ô

4 CD Construct Special Model VI 2 nd Order Model VI 2 Note: Hands-on 1, 2 RC 1 RLC mass-spring-damper 2 2 ζ ω n (rad/sec) 2 ( ζ < 1), 1 (ζ = 1), ( ) 1


0125_ 워크샵 발표자료_완성.key

#중등독해1-1단원(8~35)학

아니라 일본 지리지, 수로지 5, 지도 6 등을 함께 검토해야 하지만 여기서는 근대기 일본이 편찬한 조선 지리지와 부속지도만으로 연구대상을 한정하 기로 한다. Ⅱ. 1876~1905년 울릉도 독도 서술의 추이 1. 울릉도 독도 호칭의 혼란과 지도상의 불일치 일본이 조선

public key private key Encryption Algorithm Decryption Algorithm 1

10주차.key

Microsoft PowerPoint - AC3.pptx

- 2 -

퇴좈저널36호-4차-T.ps, page Preflight (2)

PowerPoint 프레젠테이션


예제 1.1 ( 관계연산자 ) >> A=1:9, B=9-A A = B = >> tf = A>4 % 4 보다큰 A 의원소들을찾을경우 tf = >> tf = (A==B) % A

<B1E2C8B9BEC828BFCFBCBAC1F7C0FC29322E687770>

<32382DC3BBB0A2C0E5BED6C0DA2E687770>

Vol.259 C O N T E N T S M O N T H L Y P U B L I C F I N A N C E F O R U M

Let G = (V, E) be a connected, undirected graph with a real-valued weight function w defined on E. Let A be a set of E, possibly empty, that is includ

300 구보학보 12집. 1),,.,,, TV,,.,,,,,,..,...,....,... (recall). 2) 1) 양웅, 김충현, 김태원, 광고표현 수사법에 따른 이해와 선호 효과: 브랜드 인지도와 의미고정의 영향을 중심으로, 광고학연구 18권 2호, 2007 여름

chap01_time_complexity.key

DIY 챗봇 - LangCon

6자료집최종(6.8))

영남학17합본.hwp

#Ȳ¿ë¼®

Journal of Educational Innovation Research 2019, Vol. 29, No. 1, pp DOI: (LiD) - - * Way to

01_60p_서천민속지_1장_최종_출력ff.indd

<30322D28C6AF29C0CCB1E2B4EB35362D312E687770>

PowerPoint 프레젠테이션

IKC43_06.hwp

975_983 특집-한규철, 정원호

Microsoft PowerPoint - Freebairn, John_ppt


5/12¼Ò½ÄÁö

탄도미사일 방어무기체계 배치모형 연구 (Optimal Allocation Model for Ballistic Missile Defense System by Simulated Annealing Algorithm)

철학탐구 1. 들어가는말,. (pathos),,..,.,.,,. (ethos), (logos) (enthymema). 1).... 1,,... (pistis). 2) 1) G. A. Kennedy, Aristotle on Rhetoric, 1356a(New York :

_KF_Bulletin webcopy

272 石 堂 論 叢 49집 기꾼이 많이 확인된 결과라 할 수 있다. 그리고 이야기의 유형이 가족 담, 도깨비담, 동물담, 지명유래담 등으로 한정되어 있음도 확인하였 다. 전국적인 광포성을 보이는 이인담이나 저승담, 지혜담 등이 많이 조사되지 않은 점도 특징이다. 아울

2 KHU 글로벌 기업법무 리뷰 제2권 제1호 또 내용적으로 중대한 위기를 맞이하게 되었고, 개인은 흡사 어항 속의 금붕어 와 같은 신세로 전락할 운명에 처해있다. 현대정보화 사회에서 개인의 사적 영역이 얼마나 침해되고 있는지 는 양 비디오 사건 과 같은 연예인들의 사

Journal of Educational Innovation Research 2017, Vol. 27, No. 2, pp DOI: : Researc

민속지_이건욱T 최종

Hi-MO 애프터케어 시스템 편 5. 오비맥주 카스 카스 후레쉬 테이블 맥주는 천연식품이다 편 처음 스타일 그대로, 부탁 케어~ Hi-MO 애프터케어 시스템 지속적인 모발 관리로 끝까지 스타일이 유지되도록 독보적이다! 근데 그거 아세요? 맥주도 인공첨가물이

Microsoft PowerPoint - 알고리즘_5주차_1차시.pptx

<B3EDB9AEC1FD5F3235C1FD2E687770>

09김정식.PDF

歯M PDF

<30362E20C6EDC1FD2DB0EDBFB5B4EBB4D420BCF6C1A42E687770>

274 한국문화 73

¹Ìµå¹Ì3Â÷Àμâ

歯처리.PDF

11.8.HUHkoreanrock.hwp

I&IRC5 TG_08권

김기남_ATDC2016_160620_[키노트].key

<C0C7B7CAC0C720BBE7C8B8C0FB20B1E2B4C9B0FA20BAAFC8AD5FC0CCC7F6BCDB2E687770>

Journal of Educational Innovation Research 2018, Vol. 28, No. 4, pp DOI: * A Research Trend

example code are examined in this stage The low pressure pressurizer reactor trip module of the Plant Protection System was programmed as subject for

<31325FB1E8B0E6BCBA2E687770>

chap x: G입력


歯1.PDF

휠세미나3 ver0.4



Modern Javascript

장양수

04-다시_고속철도61~80p

2 / 26

PL10

Columns 8 through while expression {commands} 예제 1.2 (While 반복문의이용 ) >> num=0

Week5

지능정보연구제 16 권제 1 호 2010 년 3 월 (pp.71~92),.,.,., Support Vector Machines,,., KOSPI200.,. * 지능정보연구제 16 권제 1 호 2010 년 3 월

[ 영어영문학 ] 제 55 권 4 호 (2010) ( ) ( ) ( ) 1) Kyuchul Yoon, Ji-Yeon Oh & Sang-Cheol Ahn. Teaching English prosody through English poems with clon


1_2•• pdf(••••).pdf

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

Transcription:

이산수학 () 알고리즘 (Algorithms) 0 년봄학기 강원대학교컴퓨터과학전공문양세

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. ( 컴퓨터프로그램이란정의된알고리즘을컴퓨터가이해할수있는언어로정확하게기술한것에불과하다.) We say that a program implements (or is an implementation of ) its algorithm. ( 프로그램은알고리즘을 구현한것이다 라고이야기한다.) Page

Programming Languages Some common programming languages: Newer: Java, C, C++, Visual Basic, JavaScript, Perl, Tcl, Pascal Older: Fortran, Cobol, Lisp, Basic Assembly languages, for low-level coding. In this class we will use an informal, Pascal-like pseudocode language. You should know at least real language! Page

Algorithm Example (in English) Task: Given a sequence {a i }=a,,a n, a i N, say what its largest element is. ( 주어진 sequence 에서가장큰수는?) Algorithm in English Set the value of a temporary variable v to a s value. Look at the next element a i in the sequence. If a i >v, then re-assign v to the number a i. Repeat previous steps until there are no more elements in the sequence, & return v. Page

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! ( 차대전이전에, 컴퓨터는알고리즘을수행하는사람을의미했다!) Page

Execute the Max Algorithm Let {a i }=7,,,,8. Find its maximum by hand. Set v = a = 7. Look at next element: a =. Is a >v? Yes, so change v to. Look at next element: a =. Is >? No, leave v alone. Is >? Yes, v= Page 6

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. Page 7

Algorithm Characteristics ( 알고리즘의특성 ) (/) Some important features of algorithms ( 계속 ): Effectiveness( 효율성 ): Individual steps are all do-able. ( 각단계는유한한양의시간에수행되어야한다.) Generality( 일반성 ): Works for many possible inputs. ( 특정한입력이아닌모든가능한입력에대해서동작하여야한다.) Page 8

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 Page 9

procedure procname(arg: type) Declares that the following text defines a procedure named procname that takes inputs (arguments) named arg which are data objects of the type type. Example: procedure maximum(l: list of integers) [statements defining maximum ] Page 0

variable := expression An assignment statement evaluates the expression, then reassigns the variable to the value that results. Example: v := x+7 (If x is, changes v to.) In pseudocode, the expression might be informal: x := the largest integer in the list L Page

Informal Statement Sometimes we may write an informal statement, if the meaning is still clear and precise: swap x and y. Keep in mind that real programming languages never allow this. ( 궁극적으로는알고리즘을쓰고이를구현해야한다.) When we ask for an algorithm to do so-and-so, writing Do so-and-so isn t enough! ( x 를찾는알고리즘을기술하라 했는데, find x 라하는것은충분치않다!) Break down algorithm into detailed steps. Page

begin statements end Groups a sequence of statements together: begin statement statement statement n end Allows sequence to be used like a single statement. Might be used: After a procedure declaration. In an if statement after then or else. In the body of a for or while loop. Page

{ comment } Not executed (does nothing). Natural-language text explaining some aspect of the procedure to human readers. (Reader 의이해도모 ) Also called a remark in some real programming languages. Example: {Note that v is the largest integer seen so far.} Page

If condition then statement Evaluate the propositional expression condition. If the resulting truth value is true, then execute the statement; otherwise, just skip on ahead to the next statement. ( 조건이 true 일때만문장을수행한다.) Variant: if cond then stmt else stmt Like before, but iff truth value is false, executes stmt. Page

while condition statement (/) Evaluate the propositional expression condition. If the resulting value is true, then execute statement. Continue repeating the above two actions over and over until finally the condition evaluates to false; then go on to the next statement. ( 조건이 true 인한문장을반복하여수행한다.) Page 6

while comment statement (/) Also equivalent to infinite nested ifs, like so: (if 를무한히써서구현할수도있다. 설마 ~) if condition begin statement if condition begin statement (continue infinite nested if s) end end Page 7

for var := initial to final stmt Initial is an integer expression. Final is another integer expression. Repeatedly execute stmt, first with variable var := initial, then with var := initial+, then with var := initial+, etc., then finally with var := final. What happens if stmt changes the value that initial or final evaluates to? For can be exactly defined in terms of while, like so: begin var := initial while var final begin stmt var := var + end end Page 8

procedure(argument) A procedure call statement invokes the named procedure, giving it as its input the value of the argument expression. Various real programming languages refer to procedures as functions (since the procedure call notation works similarly to function application f(x)), or as subroutines, subprograms, or methods. Page 9

Max Procedure in Pseudocode Rewrite finding maximum number in pseudocode. procedure max(a, a,, a n : integers) v := a {largest element so far} for i := to n {go thru rest of elems} if a i > v then v := a i {found bigger?} {at this point v s value is the same as the largest integer in the list} return v Page 0

Inventing an Algorithm Requires a lot of creativity and intuition. Like writing proofs. We can t give you an algorithm for inventing algorithms. Just look at lots of examples [ 많은예를보세요 ] And practice (preferably, on a computer) [ 연습을많이하세요 ] And look at more examples [ 좀더많은예를보세요 ] And practice some more etc., etc. [ 좀더많은연습을하세요 ] Page

Searching Algorithm ( 탐색알고리즘 ) 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. Problem occurs often in many contexts. ( 여러분이 Programming 을하는한수십번이상마주치는문제임!) Let s find an efficient algorithm! Page

Linear Search ( 선형탐색 ) 리스트의첫번째원소부터차례대로검색하는방법 예 : Find in {, 6, 9,,, 8,, } procedure linear search (x: integer, a, a,, a n : distinct integers) i := while (i n x a i ) i := i + if i n then location := i else location := 0 return location {index or 0 if not found} Linear search 는 ordered list( 정렬된상태 ) 뿐아니라 unordered list( 정렬되지않은상태 ) 에서도바르게동작한다. Page

Binary Search ( 이진탐색 ) (/) Basic idea: On each step, look at the middle element of the remaining list to eliminate half of it. ( 리스트의중간에위치한값과비교하여, 작은값들을가지는리스트혹은큰값 들을가지는리스트중에서한쪽부분에대해서만검사를진행한다.) 예 : Find 8 in {, 6, 9,,, 8,, } <x <x <x >x Page

Binary Search ( 이진탐색 ) (/) procedure binary search (x:integer, a, a,, a n : distinct integers) i := {left endpoint of search interval} j := n {right endpoint of search interval} while i<j begin {while interval has > item} m := (i+j)/ {midpoint} if x>a m then i := m+ else j := m end if x = a i then location := i else location := 0 return location Binary search 는 ordered list( 정렬된상태 ) 에서만바르게동작할뿐 unordered list( 정렬되지않은상태 ) 에서는바르게동작하지않는다. Page

Sorting Algorithm ( 정렬알고리즘 ) Sorting is a common operation in many applications. (Programming 을하는한 Search 다음으로많이마주치는문제임!) E.g. spreadsheets and databases It is also widely used as a subroutine in other dataprocessing algorithms. Two sorting algorithms shown in textbook: Bubble sort Insertion sort However, these are not very efficient, and you should not use them on large data sets! There are more than different sorting algorithms! ( The Art of Computer Programming by Donald Knuth.) Page 6

Page 7 Bubble Sort Example Sort L = {,,,, } nd pass st pass rd pass th pass

Bubble Sort Algorithm procedure bubble sort(a, a,, a n : real numbers with n ) for i := to n - for j := to n - i if a j > a j+ then interchange a j and a j+ {a, a,, a n is in increasing order.} Page 8

Insertion Sort procedure insertion sort(a, a,, a n : real numbers with n ) for j := to n i := while a j > a i {find a proper position of a j } i := i + m := a j for k := 0 to j i {insert a j into the proper position} a j-k := a j-k- a i := m {a, a,, a n is in increasing order.} Page 9

Greedy Algorithm 최적의알고리즘 (optimal algorithm) 을찾기가어렵다? 알고리즘의각단계에서최선을선택을수행하는 Greedy algorithm 을사용할수있다. Greedy algorithm 은최적일수도있다. 최적임을보이기위해서는증명이필요하고, 최적이아님을보이기위해서는반례 (counterexample) 를든다. 예제, 0,, 센트의동전이있을때, 동전의수를최소화하면서 67 센트의거스름돈을만들어라. 센트동전을선택한다. ( 센트남음 ) 센트동전을선택한다. (7 센트남음 ) 0 센트동전을선택한다. (7 센트남음 ) 센트동전을선택한다. ( 센트남음 ) 센트동전을선택한다. ( 센트남음 ) 센트동전을선택한다. ( 센트남음 ) Page 0