RadarURL

논문
2012.09.09 08:47

Algorithms & Pseudo-Code

조회 수 5044 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Definition of Algorithm (after Al Kho-war-iz-mi a 9th century Persian mathematician) - an ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time 

Let's examine the four parts of this definition more closely

  1. an ordered sequence means that you can number the steps (it's socks then shoes!)
  2. unambiguous and well-defined instructions means that each instruction is clear, do-able, and can be done without difficulty
  3. performs some task
  4. halts in finite time (algorithms terminate!)

Algorithms can be executed by a computing agent which is not necessarily a computer.


Three Catagories of Algorithmic Operations

Algorithmic operations are ordered in that there is a first instruction, a second instruction etc. However, this is not enough. An algorithm must have the ability to alter the order of its instructions. An instruction that alters the order of an algorithm is called a control structure

Three Categories of Algorithmic Operations:

  1. sequential operations - instructions are executed in order
  2. conditional  ("question asking") operations - a control structure that asks a true/false question and then selects the next instruction based on the answer
  3. iterative operations (loops) - a control structure that repeats the execution of a block of instructions

Unfortunately not every problem or task has a "good" algorithmic solution. There are 

  1. unsolvable problems - no algorithm can exist to solve the problem (Halting Problem)
  2. "hard" (intractable) problems - algorithm takes too long to solve the problem (Traveling Salesman Problem)
  3. problems with no known algorithmic solution

How to represent algorithms?

  1. Use natural languages
    • too verbose
    • too "context-sensitive"- relies on experience of reader
  2. Use formal programming languages
    • too low level
    • requires us to deal with complicated syntax of programming language
  3. Pseudo-Code - natural language constructs modeled to look like statements available in many programming languages

Pseudo-Code is simply a numbered list of instructions to perform some task. In this course we will enforce three standards for good pseudo code

  1. Number each instruction. This is to enforce the notion of an ordered sequence of ... operations. Furthermore we introduce a dot notation (e.g. 3.1 come after 3 but before 4) to number subordinate operations for conditional and iterative operations
  2. Each instruction should be unambiguous (that is the computing agent, in this case the reader, is capable of carrying out the instruction) and effectively computable (do-able).
  3. Completeness. Nothing is left out.

Pseudo-code is best understood by looking at examples. Each example below demonstrates one of the control structures used in algorithms : sequential operations,  conditional operations, and iterative operations. We also list all variables used at the end of the pseudo-code.


Example #1 - Computing Sales Tax : Pseudo-code the task of computing the final price of an item after figuring in sales tax. Note the three types of instructions: input (get), process/calculate (=) and output (display)

1.         get price of item

2.         get sales tax rate

3.         sales tax = price of time times sales tax rate

4          final prince = price of item plus sales tax

5.         display final price

6.         halt

 

Variables: price of item, sales tax rate, sales tax, final price

Note that the operations are numbered and each operation is unambiguous and effectively computable. We also extract and list all variables used in our pseudo-code. This will be useful when translating pseudo-code into a programming language


Example #2 - Computing Weekly Wages: Gross pay depends on the pay rate and the number of hours worked per week. However, if you work more than 40 hours, you get paid time-and-a-half for all hours worked over 40. Pseudo-code the task of computing gross pay given pay rate and hours worked.

1.         get hours worked

2.         get pay rate

3.         if hours worked ≤ 40 then

3.1       gross pay = pay rate times hours worked

4.         else

            4.1       gross pay = pay rate times 40 plus 1.5 times pay rate times (hours worked minus 40)

5.         display gross pay

6.         halt

 

            variables:  hours worked, ray rate, gross pay

This example introduces the conditional control structure. On the basis of the true/false question asked in line 3, we execute line 3.1 if the answer is True; otherwise if the answer is False we execute the lines subordinate to line 4 (i.e. line 4.1). In both cases we resume the pseudo-code at line 5.


Example #3 - Computing a Quiz Average:  Pseudo-code a routine to calculate your quiz average.

1.         get number of quizzes

2.         sum = 0

3.         count = 0

4.         while count < number of quizzes

            4.1       get quiz grade

            4.2       sum = sum + quiz grade

            4.3       count = count + 1

5.         average = sum / number of quizzes

6.         display average

7.         halt

 

            variables: number of quizzes, sum ,count, quiz grade, average

This example introduces an iterative control statement. As long as the condition in line 4 is True, we execute the subordinate  operations 4.1 - 4.3. When the condition becomes False, we resume the pseudo-code at line 5.

This is an example of a top-test or while do iterative control structure. There is also a bottom-test or repeat until iterative control structure which executes a block of statements until the condition tested at the end of the block is False.


Pseudo-code is one important step in the process of writing a program.


Pseudo-code Language Constructions : A Summary

Computation/Assignment 

        set the value of "variable" to :"arithmetic expression" or
        "variable" equals "expression" or
        "variable" = "expression"

Input/Output

        get "variable", "variable", ...
        display "variable", "variable", ...

Conditional (dot notation used for numbering subordinate statements)

        6.    if  "condition"
                    6.1    (subordinate) statement 1 
                    6.2     etc ...
        7.    else
                    7.1    (subordinate) statement 2
                    7.2    etc ...

Iterative (dot notation used for numbering subordinate statements)

        9.    while "condition" 
                    9.1    (subordinate) statement 1
                    9.2    etc ...



Return to Comp 150 Home Page

 

출처 : http://userpages.wittenberg.edu/bshelburne/Comp150/Algorithms.htm

?

공부 게시판

공부에 도움되는 글을 올려주세요.

  1. [공지] 공부 게시판 입니다.

    Date2003.08.18 By처누 Views931227
    read more
  2. 전수데이터를 생성하는 빠른 콤비나토리얼 프로그램 (Fast Combinatorial Programs Generating Total Data)

    Date2015.07.15 Category논문 ByJaeSoo Views672
    Read More
  3. 스코퍼스(Scopus) 지수

    Date2014.10.21 Category논문 ByJaeSoo Views886
    Read More
  4. [논문] Ubiquitous-City Integrated Authentication System (UCIAS) - Jae-Soo Jang, Hyung-Min Lim, Journal of Intelligent Manufacturing(JIM), February 2014, 장재수

    Date2014.02.21 Category논문 ByJaeSoo Views2061
    Read More
  5. [논문] 다중링크를 이용한 다양한 크기의 데이터 전송 (Data transmission of various size that use multiplex link) - 장재수,학위논문(석사), 숭실대학교 대학원 : 컴퓨터학과(일원) 컴퓨터통신 2003. 12

    Date2014.01.25 Category논문 ByJaeSoo Views2877
    Read More
  6. [논문] 조합과 순열 생성 알고리즘의 개선(Enhancement of Combination and Permutation Generation Algorithms) - 장재수,학위논문(박사), 숭실대학교 대학원 : 컴퓨터학과(일원) 컴퓨터통신 2013. 8

    Date2014.01.25 Category논문 ByJaeSoo Views2621
    Read More
  7. 제 논문에 실린 감사의 글입니다

    Date2013.06.12 Category논문 ByJaeSoo Views7217
    Read More
  8. 박사학위논문을 끝내고 감사하는 마음의 글

    Date2013.06.12 Category논문 ByJaeSoo Views5939
    Read More
  9. 로그(Log)에 대하여..

    Date2013.06.10 Category논문 ByJaeSoo Views3668
    Read More
  10. Excel 엑셀, 상용 로그, 자연 로그(LOG) 구하기 계산 함수; Common, Natural Logarithm

    Date2013.06.10 Category논문 ByJaeSoo Views6940
    Read More
  11. 논문 투고 과정

    Date2013.06.07 Category논문 ByJaeSoo Views4836
    Read More
  12. 수리과학 영어논문 작성법

    Date2013.06.07 Category논문 ByJaeSoo Views5237
    Read More
  13. 논문 작성과 형식 - 1.10 퇴고와 기타사항

    Date2013.05.19 Category논문 ByJaeSoo Views4847
    Read More
  14. 논문 작성과 형식 - 1.8 표와 그림

    Date2013.05.19 Category논문 ByJaeSoo Views5759
    Read More
  15. 논문 작성과 형식 - 1.9 주와 참고문헌의 처리

    Date2013.05.19 Category논문 ByJaeSoo Views4410
    Read More
  16. 논문 작성과 형식 - 1.7 인용과 인증

    Date2013.05.19 Category논문 ByJaeSoo Views4678
    Read More
  17. 논문 작성과 형식 - 1.6 논문 작성시 문장의 형식

    Date2013.05.19 Category논문 ByJaeSoo Views6252
    Read More
  18. 논문 작성과 형식 - 1.5 논문의 내용 전개

    Date2013.05.19 Category논문 ByJaeSoo Views4922
    Read More
  19. 논문 작성과 형식 - 1.4 논문의 내용구성

    Date2013.05.19 Category논문 ByJaeSoo Views5171
    Read More
  20. 논문 작성과 형식 - 1.3 논문의 작성의 개요

    Date2013.05.19 Category논문 ByJaeSoo Views5210
    Read More
  21. 논문 작성과 형식 - 1.2 학술논문의 형식

    Date2013.05.19 Category논문 ByJaeSoo Views6558
    Read More
Board Pagination Prev 1 2 3 4 Next
/ 4


즐겨찾기 (가족)

JAESOO's HOMEPAGE


YOUNGAE's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

숭실대 컴퓨터 통신연구실 (서창진)

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

아스가르드 좋은사람/나쁜사람

JServer.kr

제이서버 메타블로그

재수 티스토리


즐겨찾기 (강의, 커뮤니티)

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너