Newest Viewed Downloaded

Example of Selection Sort78 45 23 32 56 78 8 排序 23 23 未排序

Foundations of Computer Science (計算機概論) Chapter 8 Algorithms (演算法)

Outline

8.1 Concept (概念) 8.2 Three constructs (三種結構) 8.3 Algorithm representation (演算法的表示法) 8.4 More formal definition (較正式的定義)

Outline

8.5 Subalgorithms (子演算法) 8.6 Basic algorithms (基本的演算法) 8.7 Recursion (遞迴)

8.1 Concept (概念)

Informal Definition (非正式定義)

An algorithm is a step-by-step method for solving a problem or doing a task 演算法是一步接者一步地解一個問題或完成某項工作的方法 An algorithm accepts a list of input data and creates a list of output data 演算法會接受輸入資料串列並產生適當的輸出資料

Informal Definition (非正式定義)

A step-by-step method for solving a problem or doing a task (一步接者一步地解一個問題或 完成某項工作的方法) Input List (輸入串列) Output List (輸出串列) Algorithm (演算法)

Example (範例)

The algorithm uses the following five steps to find the largest integer 由五個整數最大的整數的演算法 12, 8, 13, 9, 11

Example (範例)

Defining Actions in FindLarget Algorithm

FindLargest 演算法的動作定義

步驟1 將第一個數字設定給Largest 步驟2 若第二個數字大於Largest內的值,將第二個數字設定給Largest 步驟3 若第三個數字大於Largest內的值,將第三個數字設定給Largest 步驟4 若第四個數字大於Largest內的值,將第四個數字設定給Largest 步驟5 若第五個數字大於Largest內的值,將第五個數字設定給Largest

FindLargest Refined

重新定義FindLargest演算法

步驟0 將Largest設定0 步驟1 若目前的數字大於Largest內的值,將目前的數字設定給Largest 步驟2 若目前的數字大於Largest內的值,將目前的數字設定給Largest 步驟3 若目前的數字大於Largest內的值,將目前的數字設定給Largest 步驟4 若目前的數字大於Largest內的值,將目前的數字設定給Largest 步驟5 若目前的數字大於Largest內的值,將目前的數字設定給Largest

Generalization of FindLargest

FindLargest演算法的一般化

Input List (輸入串列) Output List (輸出串列) FindLargest Set Largest to 0 (將Largest設為0) Repeat the following step N times: (重複下列步驟N次:) If the current number is greater than Largest, set Largest to the current number. (若目前的數字大於Largest內的值, 將目前的數字設定給Largest)

8.2 Three Constructs (三種結構)

Three Constructs (三種結構)

Computer scientists have defined three constructs for a structured program or algorithm 電腦科學家為結構化程式與演算法定義了三種結構 Sequence (循序) Decision (selection) (決定、選擇) Repetition (重複)

Sequence (循序)

do action 1 do action 2 … … … … … … … … … … do action n 執行動作 1 執行動作 2 … … … … … … … … … … 執行動作 n

Decision (Selection) (決定、選擇)

if a condition is true, then else do a series of actions do another series of actions if 條件為真, then else 執行一串動作 執行另一串動作

Repetition (重複)

while a condition is true, do action 1 do action 2 … … … … … … … do action n while 條件為真, 執行動作 1 執行動作 2 … … … … … … … 執行動作 n

8.3 Algorithm Representation (演算法的表示)

Showing 1 - 20 of 93 items Details

Name: 
ch08
Author: 
Shou-Li Hsu
Company: 
N/A
Description: 
Example of Selection Sort78 45 23 32 56 78 8 排序 23 23 未排序
Tags: 
example | sort | action | end | algorithm | 未排序 | while | search
Created: 
9/15/2005 6:07:57 PM
Slides: 
93
Views: 
1
Downloads: 
0
Rating: 
0


> Comment



Share this presentation
|

Comments

Share this presentation:

|
Sitemap