RadarURL

논문
2012.09.09 08:47

Algorithms & Pseudo-Code

조회 수 8055 추천 수 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

?

공부 게시판

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

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
공지 [공지] 공부 게시판 입니다. 처누 2003.08.18 2003309
2615 공지 대전, 인천, 세종 하수구 막힘 문제 해결 방법 new 정열적인코요테90 2026.10.05 1
2614 취미 <문경맥주> 구입 할 수 있는 곳은 새 창 열림 new 타오르는드래곤61 2026.10.05 1
2613 데이터베이스 강남건전지❤️OlO-8655-OO53❤️친절문의환영 #강남건전지 #강남유니콘 #선릉유니콘 #강남건전지위치 #선릉역건전지#대치동유니콘 #강남바커스 #선릉바커스 #선릉역바커스 #강남룸클럽 #선릉룸클럽 #강남베터리 #강남바데리 new 괴랄한재규어89 2026.10.05 1
2612 사무 소프트웨어 용인두피문신 고민? 만족 후기 보려면 new 날카로운꿩11 2026.10.05 1
2611 논문 카­톡 gusim8003 급전/내구제 (24시문의) 폰테크 소액대출 선불폰 가개통 new 타오르는켄타우로스86 2026.10.05 1
2610 윈도우즈 웨딩누브라, 완벽한 드레스 핏을 위한 선택 new 날카로운감시자22 2026.10.05 1
2609 인터넷 성공적인 중고화물차 선택, 현명한 가이드 new 붉은드래곤50 2026.10.05 2
2608 가상화 인천맛집 순위 new 차가운파편97 2026.10.05 2
2607 응용 프로그래밍 완벽한 웨딩드레스 핏의 비밀, 웨딩누브라 new 힘겨운암석76 2026.10.05 1
2606 카메라 파주누수업체, 신속 해결 전문가의 비결 new 차가운에메랄드79 2026.10.05 1
2605 u-E(통합센터) 올해의 핫플 선정 간석동 마블! 010&&8923&&0291 new 교활한감시자99 2026.10.05 1
2604 웹서버,WAS 손목터널증후군 치료, 현명한 선택 기준은? new 괴상한두루미52 2026.10.05 1
2603 u-E(통합센터) 손목터널증후군, 두팔로정형외과에서 해답을 찾다 new 눈부신백마법사86 2026.10.05 1
2602 응용 프로그래밍 골든타워 010 2817 0845 골타문의 편하게 알아보는 셔츠룸 new 속삭이는미노타우르93 2026.10.05 2
2601 u-E(TestBed) 특별한 기념품제작, 판촉물365 new 광기의태풍18 2026.10.05 1
2600 건강 대전누수 문제, 청년연합누수가 답이다 new 몽환적인삵34 2026.10.05 2
2599 u-E(법,정책) 양산싱크대막힘, 뚫자하수구에서 한 번에 해결 new 낙관적인유니콘42 2026.10.05 1
2598 가상화 최근 테헤란로 벤처 밸리의 핵심 리더들 사이에서 ‘클래스가 다른 정통 수질과 프라이빗 무드’로 소문 자자한 '선릉 룸싸롱' 기습 방문, 인공미를 거부하는 무결점 뉴페이스들과 심장을 마비시킨 사심 플러팅에 제대로 저격당하고 온 솔직 후기 new 희미한홍학99 2026.10.05 3
2597 웹서버,WAS 카­톡 gusim8003 급전/내구제 (24시문의) 선불폰 소액결제 일수 급전대출 new 황금빛섬광82 2026.10.05 2
2596 웹광고 해외선물 메타5 거래소와 GFS컴퍼니의 장점과 고려사항 new 울리는이구아나69 2026.10.05 2
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 131 Next
/ 131


즐겨찾기 (가족)

JAESOO's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

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

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

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

JServer.kr

제이서버 메타블로그

재수 티스토리


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

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너