Skip to content · ⁨ข้ามไปยังเนื้อหา⁩

Algorithm Design and Problem-solving · ⁨การออกแบบอัลกอริทึมและการแก้ปัญหา⁩

A-Level Computer Science · ⁨Computer Science A-Level⁩ · Topic 9 · ⁨หัวข้อ 9⁩

Video lesson for this topic · ⁨บทเรียนวิดีโอสำหรับหัวข้อนี้⁩ Open the video page · ⁨เปิดหน้าวิดีโอ⁩
14:52

การคิดเชิงคำนวณ

นี่คืองาน: สร้างระบบเพื่อจัดการสต็อกของร้านทั้งหมด — สินค้าทุกชิ้น การขายทุกครั้ง การจัดส่งทุกครั้ง รายงานทุกฉบับ ในฐานะปัญหาใหญ่เดียว มัน…**

English narration · English + 中文 subtitles burned in · ⁨การบรรยายภาษาอังกฤษ · คำบรรยายภาษาอังกฤษ + 中文 ลอยตัวบนภาพ⁩

9.1

Computational thinking

Syllabus · ⁨หลักสูตร⁩
English
Candidates should be able to: Notes and guidance
Show an understanding of abstraction Need for and benefits of using abstraction Describe the purpose of abstraction Produce an abstract model of a system by only including essential details
Describe and use decomposition Break down problems into sub-problems leading to the concept of a program module (procedure / function)
ไทย
ผู้เข้าสอบควรสามารถ: หมายเหตุและคำแนะนำ
แสดงความเข้าใจเรื่อง abstraction ความจำเป็นและประโยชน์ของการใช้ abstraction อธิบายวัตถุประสงค์ของ abstraction สร้างโมเดล抽象ของระบบโดยรวมเฉพาะรายละเอียดที่สำคัญเท่านั้น
อธิบายและใช้ decomposition แยกปัญหาออกเป็นปัญหาย่อย นำไปสู่แนวคิดของโมดูลโปรแกรม (procedure / function)

Source: Cambridge International syllabus · ⁨แหล่งที่มา: หลักสูตร Cambridge International⁩

English

Computational thinking 计算思维 is the set of mental tools for analysing a problem and designing a solution a computer can run. Two key ones are abstraction and decomposition.

Abstraction

Abstraction 抽象 means keeping the essential features of a problem and ignoring the irrelevant detail, giving a simpler model.

Examples:

  • a train-network map keeps the stations and lines but drops the geography.
  • a class in object-oriented programming keeps only the attributes and methods the system needs.
  • a function hides a piece of work behind a name.

A full model of any real problem would be too big to reason about, so abstraction is essential.

The examiner asks for the purpose of abstraction and for its benefits. Purpose: to produce a simpler model of a problem that contains only the details needed to solve it. Benefits: the problem is easier to understand and to program; the program is smaller and faster to write and test; the same model can be reused for similar problems. When you are asked to produce an abstract model of a system, list only the data and actions the task needs. For a school timetable that means the classes, rooms, teachers and periods; it does not mean the colour of the rooms or the age of the teachers.

Decomposition

Decomposition 分解 means breaking a large problem into smaller sub-problems, each easier to solve and tackled one at a time.

  1. find the main parts of the task.
  2. break each into smaller sub-tasks.
  3. continue until each is small enough to design directly.
  4. solve the small tasks and combine them.

For stock control: "manage stock" → "record sales", "record deliveries", "produce reports" → ("record sales") "look up product", "decrease stock count", "save the transaction". Decomposition makes big problems manageable, lets a team divide the work, and gives modular code — each module becomes a procedure 过程 or function.

"Explain why decomposition is used" is a three-mark question with a fixed shape. Give three separate benefits: each sub-problem 子问题 is small enough to design, code and test on its own; different programmers can work on different modules 模块 at the same time; a module that already exists (or a library routine) can be reused, and a fault is easier to find because it lies inside one module. A structure chart (topic 12) is the diagram of a decomposition: the program at the top, its modules beneath, and the data passed between them.

ไทย

Computational thinking คือชุดเครื่องมือทางความคิดสำหรับ วิเคราะห์ปัญหาและออกแบบโซลูชันที่คอมพิวเตอร์สามารถรันได้ สองอย่างที่สำคัญคือ abstraction และ decomposition

A part-finished jigsaw puzzle
Computational thinking แตกปัญหาใหญ่ออกเป็นส่วนย่อยๆ ที่ง่ายขึ้น — เหมือนการต่อจิ๊กซอว์

Abstraction

Abstraction หมายถึง รักษาคุณสมบัติที่สำคัญ ของปัญหาและ ละเว้นรายละเอียดที่ไม่เกี่ยวข้อง เพื่อสร้างโมเดลที่เรียบง่ายกว่า

ตัวอย่าง:

  • แผนที่ระบบรถไฟ เก็บสถานีและเส้นทางแต่ทิ้งภูมิศาสตร์
  • class ในการเขียนโปรแกรมแบบ object-oriented เก็บเฉพาะ attributes และ methods ที่ระบบต้องการ
  • function ซ่อนงานบางส่วนไว้หลังชื่อ

โมเดลเต็มรูปแบบของปัญหาจริงจะใหญ่เกินไปที่จะพิจารณาได้ ดังนั้น abstraction จึงจำเป็น

ผู้ประเมินถามถึง วัตถุประสงค์ ของการ abstraction และถึง ประโยชน์ ที่ได้รับ วัตถุประสงค์: เพื่อสร้างโมเดลที่เรียบง่ายขึ้นของปัญหา โดยรวมเฉพาะรายละเอียดที่จำเป็นในการแก้ปัญหานั้นเท่านั้น ประโยชน์: ปัญหามีความเข้าใจง่ายและเขียนโปรแกรมได้ง่ายขึ้น; โปรแกรมมีขนาดเล็กกว่าและเขียนหรือทดสอบได้เร็วขึ้น; โมเดลเดียวกันนี้สามารถนำไปใช้ซ้ำกับปัญหาที่มีลักษณะคล้ายกันได้ เมื่อถูกให้ สร้างโมเดลแบบ abstract ของระบบ ให้ระบุเพียงข้อมูลและการกระทำที่งานนั้นต้องการ สำหรับตารางเวลาเรียนของโรงเรียน หมายความว่าชั้นเรียน ห้องเรียน ครู และช่วงเวลา; ไม่รวมถึงสีของห้องหรืออายุของครู

Abstraction เปลี่ยนภูมิศาสตร์จริงที่รกชักรว (เส้นทางคดเคี้ยวพร้อมอาคารกระจายตัว) ให้เป็นแผนที่รถไฟฟ้าที่สะอาดตา — จุดวงกลมสถานีวางเว้นระยะเท่ากันบนเส้นตรง รักษาตำแหน่งสถานีและเส้นทางไว้แต่ทิ้งภูมิศาสตร์ไป
Abstraction รักษาสินค้าหลัก (สถานีและเส้นทาง) ทิ้งรายละเอียดที่ไม่เกี่ยวข้อง (ภูมิศาสตร์)

การแยกส่วน (Decomposition)

การแยกส่วน (Decomposition) หมายถึง การแบ่งปัญหาใหญ่ออกเป็นปัญหาย่อยๆ ที่มีขนาดเล็กลง ซึ่งแต่ละส่วนจะแก้ได้ง่ายกว่าและดำเนินการทีละส่วน

  1. หาองค์ประกอบหลักของงาน
  2. แบ่งแต่ละส่วนออกเป็นงานย่อยที่มีขนาดเล็กกว่า
  3. ทำต่อไปจนกว่าแต่ละส่วนจะมีขนาดเล็กพอที่จะออกแบบได้โดยตรง
  4. แก้ไขงานย่อยแล้วนำมารวมกัน

สำหรับการควบคุมสต็อก: "จัดการสต็อก" → "บันทึกการขาย", "รับสินค้าเข้า", "ทำรายงาน" → ("บันทึกการขาย") "ค้นหาผลิตภัณฑ์", "ลดจำนวนสต็อก", "บันทึกธุรกรรม" การแยกส่วนทำให้ปัญหาใหญ่จัดการได้ ทำให้ทีมแบ่งงานออกได้ และให้โค้ดที่เป็นโมดูลาร์ — แต่ละโมดูลกลายเป็น procedure หรือฟังก์ชัน

"อธิบายเหตุผลของการใช้ Decomposition" เป็นคำถามคะแนน 3 คะแนนที่มีรูปแบบตายตัว ให้ระบุประโยชน์ 3 อย่างแยกจากกัน: แต่ละ ปัญหาย่อย มีขนาดเล็กพอที่จะออกแบบ เขียนโค้ด และทดสอบได้ด้วยตนเอง; นักเขียนโปรแกรม不同的人 สามารถทำงานใน โมดูล ที่แตกต่างกันได้พร้อมกัน; โมดูลที่มีอยู่เดิม (หรือdirname ในไลบรารี) สามารถนำมาใช้ซ้ำได้ และการหาข้อผิดพลาดก็ง่ายขึ้นเพราะมันอยู่ภายในโมดูลเดียว Only Structure chart (topic 12) คือแผนภาพของการแยกส่วน: โปรแกรมอยู่ที่ด้านบน โมดูลอยู่ด้านล่าง และมีข้อมูลที่ถูกส่งผ่านระหว่างกัน

ต้นไม้ที่มี "จัดการสต็อก" ด้านบน แยกย่อยเป็นโมดูล "บันทึกการขาย", "รับสินค้า", "สร้างรายงาน" และ "บันทึกการขาย" แยกย่อยเป็นงานย่อย "ค้นหาสินค้า", "ลดจำนวนสต็อก" และ "บันทึกธุรกรรม"
การแยกย่อยโปรแกรมออกเป็นโมดูลและ submodule
Explore · ⁨สำรวจ⁩

Solving a problem the computational way · ⁨แก้ปัญหาด้วยวิธีการทางคอมพิวเตอร์⁩

Step through the four cornerstones in the order you'd use them — break the problem down, spot what repeats, strip it to essentials, then write the steps. · ⁨ผ่านขั้นตอน基石ทั้งสี่ตามลำดับที่คุณจะใช้ — แยกปัญหาออก, หาสิ่งที่ซ้ำกัน, ตัดส่วนที่ไม่จำเป็นออก, แล้วเขียนขั้นตอน⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
computational thinking/ˌkɒmpjuːˈteɪʃənl ˈθɪŋkɪŋ/ การคิดเชิงคำนวณ
abstraction/əbˈstrækʃn/ การห่อหุ้ม (abstraction)
decomposition/ˌdiːkɒmpəˈzɪʃn/ การสลายตัว
sub-problem/sʌb ˈprɒbləm/ ปัญหาย่อย
procedure/prəˈsiːdʒə/ ขั้นตอนวิธี
modules/ˈmɒdjuːlz/ โมดูล
9.2

Algorithms · ⁨อัลกอริทึม⁩

Syllabus · ⁨หลักสูตร⁩
English
Candidates should be able to: Notes and guidance
Show understanding that an algorithm is a solution to a problem expressed as a sequence of defined steps
Use suitable identifier names for the representation of data used by a problem and represent these using an identifier table
Write pseudocode that contains input, process and output
Write pseudocode using the three basic constructs of sequence, selection and iteration (repetition)
Document a simple algorithm using a structured English description, a flowchart or pseudocode
Write pseudocode from: • a structured English description • a flowchart
Draw a flowchart from: • a structured English description • pseudocode
Describe and use the process of stepwise refinement to express an algorithm to a level of detail from which the task may be programmed
Use logic statements to define parts of an algorithm solution
ไทย
ผู้เข้าสอบควรสามารถ: หมายเหตุและคำแนะนำ
แสดงความเข้าใจว่า algorithm คือวิธีแก้ปัญหาที่แสดงออกในรูปแบบลำดับขั้นตอนที่กำหนดไว้
ใช้ชื่อตัวแปรที่เหมาะสมสำหรับการแทนค่าข้อมูลที่ใช้ในปัญหาและแสดงผลลัพธ์โดยใช้ identifier table
เขียน pseudocode ที่มีการป้อนข้อมูล ประมวลผล และแสดงผล
เขียน pseudocode โดยใช้โครงสร้างพื้นฐานสามอย่างคือ sequence, selection และ iteration (repetition)
บันทึก algorithm แบบง่าย bằngการบรรยาย structured English, flowchart หรือ pseudocode
เขียน pseudocode จาก: • การบรรยาย structured English • flowchart
วาด flowchart จาก: • การบรรยาย structured English • pseudocode
อธิบายและใช้กระบวนการ stepwise refinement เพื่อแสดงอัลกอริทึมในระดับรายละเอียดเพียงพอสำหรับการเขียนโปรแกรมงานนั้น
ใช้ประโยคตรรกะเพื่อกำหนดส่วนหนึ่งของวิธีแก้ algorithm

Source: Cambridge International syllabus · ⁨แหล่งที่มา: หลักสูตร Cambridge International⁩

English
Bubble sort, pass by pass

An algorithm 算法 is a solution expressed as a sequence of defined steps. Each step is unambiguous 无歧义 (one meaning), deterministic 确定性 (same input → same output), finite (the steps end), and effective (each can be done). An algorithm says what to do, independent of the programming language used to implement it.

ไทย
Bubble sort, pas-by-pass

อัลกอริทึม (Algorithm) คือ วิธีแก้ปัญหาที่แสดงออกมาเป็นลำดับขั้นตอนที่กำหนดไว้อย่างชัดเจน ขั้นตอนแต่ละขั้นต้อง ไม่มีความกำกวม (Unambiguous) (มีความหมายเดียว), เป็นแบบกำหนดเอง (Deterministic) (อินพุตเท่าเดิม → เอาต์พุตเท่าเดิม), มีขอบเขตจำกัด (Finite) (ขั้นตอนจบลง), และ มีประสิทธิภาพ (Effective) (แต่ละขั้นทำได้จริง) อัลกอริทึมบอก สิ่งที่ต้องทำ โดยไม่ขึ้นอยู่กับภาษาโปรแกรมมิ่งที่ใช้ในการนำไปปฏิบัติ

Explore · ⁨สำรวจ⁩

Selection: follow the IF / ELSE branches · ⁨การเลือก: ตามเส้นทาง IF / ELSE⁩

Drag the score and watch which branch runs. Selection tests each condition in turn and takes the FIRST one that is true — that is how IF … ELSE IF … ELSE works. · ⁨ลากคะแนนและดูว่าเส้นทางไหนทำงาน การเลือกจะทดสอบเงื่อนไขทีละข้อและเลือกเส้นทางที่ TRUE เป็นข้อแรก — นั่นคือวิธีการทำงานของ IF … ELSE IF … ELSE⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
algorithm/ˈælɡərɪθəm/ อัลกอริทึม
unambiguous/ʌnæmˈbɪɡjuːəs/ ไม่มีข้อกำกวม
Watch lesson · ⁨ดูบทเรียน⁩
9.2

Identifier table · ⁨ตารางตัวชี้จำ (Identifier table)⁩

English

When you start an algorithm, list every piece of data in an identifier table 标识符表 — its identifier 标识符 (the variable 变量 name), data type 数据类型, and description. The exam's table has exactly these three columns:

Identifier Data type Description
Category STRING the product category
SaleDate DATE when the item was sold
ItemCost REAL cost of the item
InStock BOOLEAN TRUE if in stock
Sales ARRAY[1:30] OF REAL the last 30 daily sales totals

Use descriptive names (ItemCost, not x): an identifier starts with a letter, contains no spaces, and is written the same way every time it appears. Common types are INTEGER, REAL, STRING, CHAR, BOOLEAN, DATE, plus arrays. The table forces you to name every piece of data before writing code, and a "complete the identifier table" question gives one mark for each correct data type or description, so write the type exactly as the pseudocode guide does.

ไทย

เมื่อเริ่มอัลกอริทึม ให้ระบุงานข้อมูลทั้งหมดไว้ใน ตารางตัวชี้จำ — ชื่อตัวชี้จำ (variable name), ชนิดของข้อมูล, และคำอธิบาย ตารางสอบจะมีสามคอลัมน์เหล่านี้เท่านั้น:

ตัวชี้จำ ชนิดของข้อมูล คำอธิบาย
Category STRING ประเภทสินค้า
SaleDate DATE เวลาที่สินค้าถูกขาย
ItemCost REAL ราคาต้นทุนของสินค้า
InStock BOOLEAN TRUE หากมีสินค้าคงเหลือ
Sales ARRAY[1:30] OF REAL ยอดรวมยอดขายรายวัน 30 วันล่าสุด

ใช้ ชื่อที่สื่อความหมาย (ItemCost, ไม่ใช่ x): ตัวชี้จำเริ่มต้นด้วยตัวอักษร, ไม่มีช่องว่าง, และสะกดเหมือนกันทุกครั้งเมื่อปรากฏ Types ที่พบบ่อยคือ INTEGER, REAL, STRING, CHAR, BOOLEAN, DATE,连同 Arrays ตารางนี้บังคับให้คุณตั้งชื่อนำข้อมูลทุกชิ้นก่อนเขียนโค้ด, และคำถาม "เติมตารางตัวชี้จำ" จะให้คะแนน 1 คะแนนสำหรับชนิดของข้อมูลหรือคำอธิบายที่ถูกต้องต่อหนึ่งจุด, ดังนั้นจงเขียนชนิดของข้อมูลให้ตรงกับคู่มือ Pseudocode พอดี

ตารางระบุชื่อแสดงตัวแปรแต่ละตัวพร้อมชื่อ ประเภทข้อมูล และคำอธิบาย ตัวอย่างเช่น ItemCost เป็น REAL สำหรับราคาสินค้า
ตารางตัวแปรระบุชื่อข้อมูลทุกชิ้นก่อนเริ่มเขียนโค้ด
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
identifier table/aɪˈdentɪfaɪə ˈteɪbl/ ตารางตัวระบุ
identifier/aɪˈdentɪfaɪə/ ตัวระบุ
variable/ˈveərɪəbl/ ตัวแปร
data type/ˈdeɪtə taɪp/ ชนิดของข้อมูล
Boolean/ˈbuːlɪən/ Boolean
pseudocode/ˈsuːdəʊkəʊd/ โค้ดเทียม (pseudocode)
9.2

Pseudocode — the three basic constructs · ⁨Pseudocode — โครงสร้างพื้นฐานทั้งสาม⁩

English

Pseudocode 伪代码 is a structured, language-neutral way to describe algorithms.

1. Sequence

Steps run one after another (sequence 顺序):

2. Selection

A choice of which steps run, based on a condition (selection 选择):

For more options, use CASE OF ... ENDCASE.

3. Iteration

Repeating a block (iteration 迭代, a loop 循环):

A WHILE loop tests the condition before each pass (may run zero times); a REPEAT...UNTIL loop tests after each pass (always runs at least once).

Choosing the loop is itself a mark: FOR when you know how many times (a count-controlled loop 计数循环); WHILE when the loop might not run at all (a pre-condition loop 前测循环); REPEAT ... UNTIL when it must run at least once, as in validating an input (a post-condition loop 后测循环). A "describe the iteration construct" answer names the construct, says where the condition is tested, and gives the consequence (zero times or at least once).

Common operations

  • assignment 赋值: x ← 5 (an arrow; = is for comparison).
  • input/output: INPUT variable, OUTPUT expression.
  • comparisons =, <>, <, >, <=, >=; logic AND, OR, NOT.
  • arithmetic + - * /, plus DIV (integer division) and MOD (remainder).
  • strings: LENGTH, LEFT, RIGHT, MID, and & for concatenation 拼接 (joining).

The pseudocode the exam expects

Every pseudocode answer is marked against Cambridge's published pseudocode guide. Write these forms exactly:

Construct Pseudocode
Variable DECLARE Total : INTEGER
Array DECLARE Marks : ARRAY[1:30] OF REAL
Constant CONSTANT MaxTries = 3
Assignment Total ← Total + Value
Input / output INPUT Name
OUTPUT "Hello ", Name
Selection CASE OF Choice
1 : OUTPUT "Add"
OTHERWISE OUTPUT "Error"
ENDCASE
FOR loop FOR i ← 1 TO 10 STEP 2 ... NEXT i
WHILE loop WHILE Total < 100 DO ... ENDWHILE
REPEAT loop REPEAT ... UNTIL Mark >= 0
Integer arithmetic 17 DIV 5 = 3
17 MOD 5 = 2
Strings LENGTH(S), LEFT(S, 3), RIGHT(S, 2)
MID(S, 2, 4), UCASE(S), LCASE(S)
Conversions INT(3.7) = 3, NUM_TO_STR(12)
STR_TO_NUM("4.5"), ASC('A') = 65, CHR(66) = 'B'
Random RAND(100)
INT(RAND(100)) + 1

RAND(100) gives a real number from 0 up to (but not including) 100. INT(RAND(100)) + 1 gives an integer from 1 to 100.

Two habits earn marks on every question: declare every variable you use, with the type from your identifier table, and initialise 初始化 every counter 计数器 and total (Count ← 0, Total ← 0) before the loop that changes it.

Input → Process → Output

Every program follows this shape:

Listing the inputs and outputs first makes the algorithm cleaner.

Worked example. Write pseudocode that inputs 100 integers and outputs how many of them, and the total of those, that lie between 10 and 20 inclusive.

Identifier table: Count : INTEGER (loop counter), Value : INTEGER (the integer just input), InRange : INTEGER (how many were in range), Total : INTEGER (their sum).

If the question then asks you to "identify two constructs and state how each is used", answer in the same shape: iteration, the FOR loop, repeats the input 100 times; selection, the IF statement, adds a value only when it is in range.

Worked example. A program picks a secret integer from 1 to 100. The user guesses until they are right; after each wrong guess the program says "Too low" or "Too high", and at the end it outputs how many guesses were made.

Identifier table: Secret : INTEGER (the number to guess), Guess : INTEGER (the user's input), Tries : INTEGER (how many guesses so far).

A REPEAT ... UNTIL loop is the right choice because the user must guess at least once. The marks are for: the random number in the right range, a loop that ends on a correct guess, the counter that starts at zero and increases inside the loop, the two messages under the right conditions, and the final output.

Worked example. Output two different random integers, each between $-10$ and $10$ inclusive.

There are 21 possible values, so INT(RAND(21)) gives 0 to 20 and subtracting 10 shifts it to the range $-10$ to $10$. The second number must be generated again until it differs from the first:

ไทย

Pseudocode คือวิธีการอธิบายอัลกอริทึมที่มีโครงสร้างและเป็นกลางต่อภาษา

โครงสร้างพื้นฐานสามแบบในรูปแบบแผนผังขนาดเล็ก: ลำดับขั้นตอนทำงานขั้นตอน A แล้ว B แล้ว C; การเลือกทดสอบเงื่อนไขและทำ X หรือ Y; การวนซ้ำทำซ้ำเนื้อหาเมื่อเงื่อนไขเป็นจริง โดยวนกลับ
Block สร้างสร้างของอัลกอริทึมทั้งสาม: Sequence, Selection และ Iteration

1. ลำดับ (Sequence)

ขั้นตอนทำงานตามลำดับ (sequence):

INPUT Name
INPUT Age
OUTPUT "Hello", Name

2. การเลือก (Selection)

การตัดสินใจว่าขั้นตอนไหนจะทำงาน โดยอ้างอิงจากเงื่อนไข (selection):

IF Age >= 18 THEN
    OUTPUT "Adult"
ELSE
    OUTPUT "Minor"
ENDIF

สำหรับตัวเลือกเพิ่มเติม ให้ใช้ CASE OF ... ENDCASE.

3. การวนซ้ำ (Iteration)

การทำซ้ำบล็อก (iteration, loop):

FOR i ← 1 TO 10
    OUTPUT i
NEXT i

ลูป WHILE ตรวจสอบเงื่อนไข ก่อน การวนแต่ละรอบ (อาจไม่ทำงานเลย); ลูป REPEAT...UNTIL ตรวจสอบ หลัง การวนแต่ละรอบ (ทำงานอย่างน้อยครั้งเสมอ)

WHILE Total < 100 DO
    INPUT Value
    Total ← Total + Value
ENDWHILE

REPEAT
    INPUT Mark
UNTIL Mark >= 0 AND Mark <= 100
แผนผังสองแผนวางข้างกัน WHILE ตรวจสอบเงื่อนไขก่อน ดังนั้นเนื้อหาอาจไม่เคยทำงาน:形อยู่เหนือเนื้อหาและสาขา No ออกจากลูป REPEAT UNTIL ทำงานเนื้อหาก่อนแล้วตรวจสอบหลังจากนั้น ดังนั้นเนื้อหาจึงทำงานอย่างน้อยครั้งเสมอ: เนื้อหาอยู่เหนือ形และสาขา No กลับไปที่เนื้อหา
ลูป WHILE ตรวจสอบก่อนเนื้อหาทำงาน; ลูป REPEAT ... UNTIL ตรวจสอบหลังจากนั้น ดังนั้นเนื้อหาจึงทำงานอย่างน้อยครั้งเสมอ

การเลือกชนิดลูปก็เป็นคะแนนเอง: FOR เมื่อทราบจำนวนรอบ (ลูปควบคุมโดยนับ); WHILE เมื่อลูปอาจไม่ทำงานเลย (ลูปก่อนเงื่อนไข); REPEAT ... UNTIL เมื่อต้องทำงานอย่างน้อยครั้งเดียว เช่น ในการตรวจสอบอินพุต (ลูปหลังเงื่อนไข) คำตอบ "อธิบายโครงสร้างการวนซ้ำ" ต้องระบุชื่อโครงสร้าง บอกว่าเงื่อนไขถูกทดสอบที่ไหน และบอกผลกระทบ (ศูนย์ครั้งหรืออย่างน้อยครั้งเดียว)

การดำเนินการทั่วไป

  • การกำหนดค่า: x ← 5 (ลูกศร; = ใช้สำหรับการเปรียบเทียบ)
  • อินพุต/เอาต์พุต: INPUT variable, OUTPUT expression.
  • การเปรียบเทียบ =, <>, <, >, <=, >=; Logic AND, OR, NOT.
  • การคำนวณ + - * /, บวก DIV (การหารจำนวนเต็ม) และ MOD (เศษเหลือ).
  • สตรีง: LENGTH, LEFT, RIGHT, MID, และ & สำหรับ การต่อ (joining).

ปсевโดโค้ดที่ข้อสอบต้องการ

คำตอบทุกข้อจะถูกตรวจตามคู่มือปсевโดโค้ดของ Cambridge ที่เผยแพร่ไว้ เขียนรูปแบบเหล่านี้ให้ตรงตามนี้:

โครงสร้าง ปсевโดโค้ด
ตัวแปร DECLARE Total : INTEGER
อาร์เรย์ DECLARE Marks : ARRAY[1:30] OF REAL
ค่าคงที่ CONSTANT MaxTries = 3
การกำหนดค่า Total ← Total + Value
การรับ/ส่งข้อมูล INPUT Name
OUTPUT "Hello ", Name
การเลือกเงื่อนไข CASE OF Choice
1 : OUTPUT "Add"
OTHERWISE OUTPUT "Error"
ENDCASE
ลูป FOR FOR i ← 1 TO 10 STEP 2 ... NEXT i
ลูป WHILE WHILE Total < 100 DO ... ENDWHILE
ลูป REPEAT REPEAT ... UNTIL Mark >= 0
การคำนวณจำนวนเต็ม 17 DIV 5 = 3
17 MOD 5 = 2
สตรีง LENGTH(S), LEFT(S, 3), RIGHT(S, 2)
MID(S, 2, 4), UCASE(S), LCASE(S)
การแปลงชนิดข้อมูล INT(3.7) = 3, NUM_TO_STR(12)
STR_TO_NUM("4.5"), ASC('A') = 65, CHR(66) = 'B'
สุ่ม RAND(100)
INT(RAND(100)) + 1

RAND(100) ให้ค่าจริงตั้งแต่ 0 ขึ้นไปจนถึง (แต่ไม่รวม) 100. INT(RAND(100)) + 1 ให้ค่าจำนวนเต็มตั้งแต่ 1 ถึง 100.

สองนิสัยที่ทำให้ได้คะแนนในทุกข้อคือ: ประกาศตัวแปรทุกตัวที่คุณใช้ พร้อมระบุชนิดจากตารางไถ่ชื่อ, และ เริ่มต้นค่าตัวนับและผลรวมทั้งหมด (Count ← 0, Total ← 0) ก่อนลูปที่จะทำการเปลี่ยนแปลงค่าเหล่านั้น.

ข้อมูลเข้า → กระบวนการ → ข้อมูลออก

โปรแกรมทุกตัวมีโครงสร้างดังนี้:

INPUT Length
INPUT Width
Area ← Length * Width
OUTPUT "Area = ", Area

การระบุข้อมูลเข้าและข้อมูลออกก่อนจะช่วยให้อัลกอริทึมเป็นระเบียบมากขึ้น

ตัวอย่างวิธีทำ. เขียน伪代码ที่รับ入了 100 จำนวนเต็มและ outputs ว่ามีกี่ตัว และมีผลรวมเท่าใด ที่อยู่ในช่วงระหว่าง 10 ถึง 20 แบบรวมขอบเขต

ตารางไถ่ชื่อ: Count : INTEGER (ตัวนับรอบลูป), Value : INTEGER (จำนวนเต็มที่เพิ่งรับเข้ามา), InRange : INTEGER (จำนวนที่มีอยู่ในช่วง), Total : INTEGER (ผลรวมของจำนวนเหล่านั้น).

DECLARE Count, Value, InRange, Total : INTEGER
InRange ← 0
Total ← 0
FOR Count ← 1 TO 100
    INPUT Value
    IF Value >= 10 AND Value <= 20 THEN
        InRange ← InRange + 1
        Total ← Total + Value
    ENDIF
NEXT Count
OUTPUT InRange, Total

หากโจทย์ขอให้ "ระบุโครงสร้าง 2 แบบและอธิบายการใช้งานของแต่ละแบบ" ตอบในรูปแบบเดียวกัน: การซ้ำซ้อน, ลูป FOR, ทำการรับข้อมูลซ้ำ 100 ครั้ง; การเลือกเงื่อนไข, คำสั่ง IF, เพิ่มค่าก็ต่อเมื่ออยู่ในช่วงเท่านั้น

ตัวอย่างคำอธิบาย. โปรแกรมสุ่มเลขลับจำนวนเต็มจาก 1 ถึง 100 ผู้ใช้ทายจนถูก; หลังจากรายแต่ละครั้งโปรแกรมจะแสดง "ต่ำเกินไป" หรือ "สูงเกินไป" และท้ายที่สุดจะแสดงว่าทายไปทั้งหมดกี่ครั้ง

ตารางไถ่ชื่อ: Secret : INTEGER (เลขที่ต้องทาย), Guess : INTEGER (สิ่งที่ผู้ใช้พิมพ์), Tries : INTEGER (จำนวนครั้งที่ทายมาจนถึงตอนนี้).

DECLARE Secret, Guess, Tries : INTEGER
Secret ← INT(RAND(100)) + 1
Tries ← 0
REPEAT
    INPUT Guess
    Tries ← Tries + 1
    IF Guess < Secret THEN
        OUTPUT "Too low"
    ELSE
        IF Guess > Secret THEN
            OUTPUT "Too high"
        ENDIF
    ENDIF
UNTIL Guess = Secret
OUTPUT "You took ", Tries, " guesses"

การใช้ REPEAT ... UNTIL loop เป็นทางเลือกที่เหมาะสมเพราะผู้ใช้อาจต้องทายอย่างน้อยหนึ่งครั้ง คะแนนจะอยู่ที่: การสุ่มเลขในช่วงที่ถูกต้อง, ลูปที่จบลงเมื่อทายถูก, ตัวนับที่เริ่มที่ศูนย์และเพิ่มขึ้นภายในลูป, ข้อความสองประเภทภายใต้เงื่อนไขที่ถูกต้อง, และการแสดงผลสุดท้าย

แผนภาพไหลของเกมทายเลข: เริ่มต้น, จากนั้นกำหนด Secret เป็นเลขสุ่มจาก 1 ถึง 100 และ Tries เป็น 0, จากนั้นรับค่าทาย, เพิ่ม 1 เข้ากับ Tries, ตรวจสอบว่าค่าทายเท่ากับ Secret หรือไม่ (Yes นำไปสู่การแสดงผล Tries และหยุด), มิฉะนั้นตรวจสอบว่าค่าทายน้อยกว่า (Yes แสดง Too low, No แสดง Too high), และการแสดงผลทั้งสองวนกลับไปที่การรับค่า
เกมทายเลขเดิมในรูปแผนภาพไหล: สี่เหลี่ยมขนมเปียกปูนตัดสินใจทั้งสองคือคำสั่ง IF ทั้งสอง, และลูกศรย้อนกลับคือลูป REPEAT ... UNTIL

ตัวอย่างคำอธิบาย. แสดงตัวเลขสุ่มจำนวนเต็มที่แตกต่างกันสองตัว แต่ละตัวอยู่ระหว่าง $-10$ ถึง $10$ (รวมขอบเขต)

มีค่าที่เป็นไปได้ 21 ค่า ดังนั้น INT(RAND(21)) จึงให้ค่าตั้งแต่ 0 ถึง 20 และการลบ 10 จะย้ายช่วงให้เป็น $-10$ ถึง $10$. ตัวที่สองต้องถูกสุ่มใหม่จนกว่าจะต่างจากตัวแรก:

DECLARE First, Second : INTEGER
First ← INT(RAND(21)) - 10
REPEAT
    Second ← INT(RAND(21)) - 10
UNTIL Second <> First
OUTPUT First, Second
โปรแกรมทุกตัวมีโครงสร้าง ข้อมูลเข้า, กระบวนการ, ข้อมูลออก, แสดงด้วยตัวอย่างพื้นที่: รับความยาวและความกว้าง, ประมวลผลด้วยการคูณ, แสดงพื้นที่
โปรแกรมทุกตัวมีโครงสร้าง ข้อมูลเข้า, กระบวนการ, ข้อมูลออก
Explore · ⁨สำรวจ⁩

IF … ELSE selection · ⁨IF … ELSE 选择⁩

Change the value and watch which branch runs — how a program makes a decision. · ⁨更改值并观察哪个 branch 运行——程序如何做决定。⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
sequence/ˈsiːkwəns/ ลำดับขั้นตอน (sequence)
flowchart/ˈfləʊtʃɑːt/ แผนภูมิไหล
selection/sɪˈlekʃn/ การคัดเลือก
iteration/ˌɪtəˈreɪʃn/ การวนซ้ำ
loop/luːp/ ลูป
count-controlled loop/kaʊnt kənˈtrəʊld luːp/ ลูปควบคุมด้วยการนับ
pre-condition loop/priː kənˈdɪʃn luːp/ ลูปก่อนเงื่อนไข
post-condition loop/pəʊst kənˈdɪʃn luːp/ ลูปหลังเงื่อนไข
assignment/əˈsaɪnmənt/ การกำหนดค่า (assignment)
concatenation/kənˌkætəˈneɪʃn/ การต่อสตริง (concatenation)
initialise/ɪˈnɪʃəlaɪz/ เริ่มต้น
counter/ˈkaʊntə/ ตัวอย่าง反驳
structured English/ˈstrʌktʃəd ˈɪŋɡlɪʃ/ ภาษาอังกฤษที่มีโครงสร้าง
stepwise refinement/ˈstepwaɪz rɪˈfaɪnmənt/ การละเอียดแบบขั้นบันได
logic statement/ˈlɒdʒɪk ˈsteɪtmənt/ ประโยคตรรกะ
precedence/ˈpresɪdəns/ ลำดับความสำคัญ
De Morgan's law/də ˈmɔːɡənz lɔː/ กฎของเด摩根
9.2

Three notations · ⁨สามรูปแบบการเขียน⁩

English

The same algorithm can be written three ways.

  • structured English 结构化英语 — natural language with indentation and fixed keywords; good for a high-level description.
  • flowchart 流程图 — a diagram with standard shapes:
Shape Meaning
Rounded rectangle Start / Stop
Parallelogram Input / Output
Rectangle Process
Diamond Decision
Arrow Flow of control
  • pseudocode — the keyword notation above; closest to code.

You should be able to convert between any pair: each IF is a decision diamond, each loop is a back-arrow, and a sequence is stacked rectangles.

IF ... THEN ... ELSE ... ENDIF

ไทย

อัลกอริทึมเดียวสามารถเขียนได้ด้วยสามวิธี

  • ภาษาอังกฤษเชิงโครงสร้าง — ภาษาธรรมชาติพร้อมการเยื้องและคำสำคัญที่กำหนด; เหมาะสำหรับการอธิบายระดับสูง
  • แผนภาพไหล — แผนภูมิที่มีรูปร่างมาตรฐาน:
รูปร่าง ความหมาย
สี่เหลี่ยมมุมโค้งมน เริ่มต้น / หยุด
สี่เหลี่ยมขนาน รับ/ส่งข้อมูล
สี่เหลี่ยมผืนผ้า กระบวนการ
สี่เหลี่ยมขนมเปียกเปียก การตัดสินใจ
ลูกศร การไหลของการควบคุม
  • ปсевโดโค้ด — การใช้คำสำคัญตามรูปแบบข้างต้น; ใกล้เคียงกับโค้ดมากที่สุด

คุณควรสามารถแปลงระหว่างคู่ใดๆ ได้: แต่ละ IF คือสี่เหลี่ยมขนมเปียกเปียกการตัดสินใจ, แต่ละลูปคือลูกศรย้อนกลับ, และลำดับคือการซ้อนสี่เหลี่ยม

IF ... THEN ... ELSE ... ENDIF

แผนภาพไหลสำหรับการหาค่าเฉลี่ย: จุดเริ่มต้นและจุดสิ้นสุดสี่เหลี่ยมมุมโค้งมน, สี่เหลี่ยมขนานสำหรับรับ/ส่งข้อมูล, สี่เหลี่ยมผืนผ้าสำหรับกระบวนการ, และสี่เหลี่ยมขนมเปียกเปียก "count < n?" ที่สาขา Yes ย้อนกลับไปอ่านค่าถัดไป
แผนภาพไหลสำหรับการหาค่าเฉลี่ยของรายการตัวเลข โดยใช้รูปร่างมาตรฐาน
9.2

Stepwise refinement · ⁨การปรับปรุงทีละขั้น⁩

English

Stepwise refinement 逐步求精 starts with a high-level outline and expands each step until it is small enough to code. For an average of $n$ numbers:

Level 1:

Level 2:

Each refinement keeps the previous structure and adds detail.

A six-mark "apply stepwise refinement" question gives you a high-level outline and wants each step expanded into the concrete statements a programmer could code. Keep the steps in the same order, name the data each step reads or produces, and stop when every line is a single input, assignment, output, loop or condition. For example, "validate the password" becomes: input the password; check its length is at least 8; check it contains at least one digit; output "accepted" if both checks pass, otherwise output "rejected".

ไทย

การปรับปรุงทีละขั้น เริ่มจากโครงร่างระดับสูงแล้ว ขยายแต่ละขั้นตอน จนมีขนาดเล็กพอที่จะเขียนโค้ดได้. สำหรับการหาค่าเฉลี่ยของ $n$ จำนวน:

ระดับ 1:

Read in the numbers
Compute the average
Output the average

ระดับ 2:

INPUT n
total ← 0
FOR i ← 1 TO n
    INPUT value
    total ← total + value
NEXT i
average ← total / n
OUTPUT average

การปรับปรุงแต่ละขั้นจะรักษาโครงสร้างเดิมไว้และเพิ่มรายละเอียดเข้าไป

คำถาม "ประยุกต์ใช้การปรับปรุงทีละขั้น" คะแนน 6 คะแนน ให้โครงร่างระดับสูงมาและต้องการให้ขยายแต่ละขั้นเป็นคำสั่งเฉพาะที่นักเขียนโปรแกรมสามารถนำไปเขียนโค้ดได้ รักษาลำดับขั้นตอนไว้ตั้งเดิม ระบุข้อมูลที่แต่ละขั้นอ่านหรือสร้าง และหยุดเมื่อทุกบรรทัดเป็นเพียงการรับข้อมูล, การกำหนดค่า, การแสดงผล, ลูป หรือเงื่อนไข ตัวอย่างเช่น, "ตรวจสอบรหัสผ่าน" กลายเป็น: รับรหัสผ่าน; ตรวจสอบความยาวอย่างน้อย 8 หลัก; ตรวจสอบว่ามีตัวเลขอย่างน้อยหนึ่งหลัก; แสดง "ยอมรับ" หากผ่านการตรวจสอบทั้งสองอย่าง否则 แสดง "ปฏิเสธ"

การปรับปรุงทีละขั้น: โครงร่างระดับ 1 (อ่านตัวเลข, คำนวณค่าเฉลี่ย, แสดงค่าเฉลี่ย) ถูกขยายเป็นปсевโดโค้ดละเอียดระดับ 2 พร้อมลูปรับข้อมูลและการหาร
การปรับระดับทีละขั้น: ขยายแต่ละขั้นตอนระดับสูงให้เป็น伪โค้ดที่ละเอียด
Explore · ⁨สำรวจ⁩

Stepwise refinement: outline to code · ⁨การปรับปรุงแบบขั้นตอน: จากแผนภาพไปจนถึงโค้ด⁩

Step down the levels. You start with the whole task in one line and keep expanding each step into smaller ones — until every step is simple enough to code directly. · ⁨ลดระดับลงทีละขั้น คุณเริ่มจากโจทย์ทั้งหมดในบรรทัดเดียว และขยายแต่ละขั้นตอนให้อยู่ในระดับย่อยลงไปเรื่อยๆ — จนกว่าแต่ละขั้นตอนจะเล็กและเรียบง่ายพอที่จะเขียนโค้ดได้โดยตรง⁩

9.2

Logic statements · ⁨คำสั่งตรรกะ⁩

English

A logic statement 逻辑语句 is a Boolean 布尔 condition that controls branching, built from comparisons (x > 10), connectives (AND, OR, NOT) and brackets. Use it as the condition of IF, WHILE or REPEAT...UNTIL:

Precedence 优先级 (highest to lowest): NOT, then AND, then OR. Use brackets when unsure. Common mistakes:

  • a = 1 OR 2 is wrong — write a = 1 OR a = 2.
  • NOT a > 5 means NOT (a > 5), i.e. a <= 5.
  • NOT (A AND B) is the same as (NOT A) OR (NOT B) (De Morgan's law 德摩根定律) — handy for simplifying conditions.

Turning a sentence into a logic statement is a skill the papers test directly. "A ticket is free for anyone under 5 or over 65" becomes Age < 5 OR Age > 65. "A mark is valid if it is a whole number from 0 to 100" becomes Mark >= 0 AND Mark <= 100. "The loop stops when the file is finished or ten records have been read" becomes UNTIL EOF(File) OR Count = 10. Write each comparison in full: Age > 65 and Age < 5, never Age > 65 OR < 5.

Worked example. Write an identifier table and pseudocode to read 10 numbers and output the largest. The identifier table names each variable with its data type and purpose: Count : INTEGER (loop counter), Num : REAL (the number just read), Max : REAL (largest so far).

The design decision carrying the marks is initialising Max: it must start lower than any possible input - or, safer still, be set to the first number read. Initialise it to 0 and the algorithm wrongly returns 0 for a list of negative numbers, a bug your trace only exposes if the test data include a negative.

ไทย

คำสั่งตรรกะ คือ เงื่อนไข布尔 ที่ควบคุมการแยกทาง สร้างจากการเปรียบเทียบ (x > 10), ตัวเชื่อม (AND, OR, NOT) และวงเล็บ ใช้เป็นเงื่อนไขของ IF, WHILE หรือ REPEAT...UNTIL:

WHILE attempts < 3 AND NOT loggedIn DO
    INPUT password
    IF password = correctPassword THEN
        loggedIn ← TRUE
    ELSE
        attempts ← attempts + 1
    ENDIF
ENDWHILE

ลำดับความสำคัญ (จากสูงสุดไปต่ำสุด): NOT, แล้ว AND, แล้ว OR. ใช้วงเล็บเมื่อไม่แน่ใจ ข้อผิดพลาดพบบ่อย:

  • a = 1 OR 2 ผิด — ต้องเขียน a = 1 OR a = 2.
  • NOT a > 5 หมายความว่า NOT (a > 5), นั่นคือ a <= 5.
  • NOT (A AND B) เหมือนกับ (NOT A) OR (NOT B) (กฎเดมอร์แกน) — มีประโยชน์ในการลดทอนเงื่อนไขให้สั้นลง

การแปลงประโยคเป็นคำสั่งตรรกะเป็นทักษะที่ข้อสอบทดสอบโดยตรง "บัตรเข้าฟรีสำหรับทุกคนที่มีอายุต่ำกว่า 5 ปีหรือมากกว่า 65 ปี" จะกลายเป็น Age < 5 OR Age > 65 "คะแนนมีความถูกต้องหากเป็นจำนวนเต็มตั้งแต่ 0 ถึง 100" จะกลายเป็น Mark >= 0 AND Mark <= 100 "ลูปจะหยุดเมื่อไฟล์读完หรืออ่านข้อมูลครบสิบบรรทัด" จะกลายเป็น UNTIL EOF(File) OR Count = 10. เขียนทุกการเปรียบเทียบให้สมบูรณ์: Age > 65 และ Age < 5, ห้ามใช้ Age > 65 OR < 5.

ต้นไม้การวิเคราะห์สำหรับ "attempts < 3 AND NOT loggedIn": NOT作用于loggedInก่อน, แล้วANDรวมผลนั้นเข้ากับattempts < 3
ลำดับความสำคัญ: NOTจับคู่กับloggedInก่อน, แล้วANDรวมทั้งสองฝั่งเข้าด้วยกัน

ตัวอย่างทำแล้ว. เขียนตารางตัวระบุและ伪โค้ดเพื่ออ่านตัวเลข 10 ตัวและแสดงผลใหญ่ที่สุด ตารางตัวระบุ ชื่อบันไดตัวแปรพร้อมชนิดข้อมูลและวัตถุประสงค์: Count : INTEGER (ตัวนับลูป), Num : REAL (ตัวเลขที่เพิ่งอ่าน), Max : REAL (ค่าที่ใหญ่ที่สุดจนถึงตอนนี้).

Max ← -999999
FOR Count ← 1 TO 10
    INPUT Num
    IF Num > Max THEN
        Max ← Num
    ENDIF
NEXT Count
OUTPUT Max

การตัดสินใจในการออกแบบที่สำคัญที่สุดคือการ เริ่มต้นค่า Max: ต้องเริ่มต้น ต่ำกว่าค่าอินพุตที่เป็นไปได้ทั้งหมด - หรือปลอดภัยกว่านั้นคือ ตั้งค่าเป็น ค่าแรก ที่อ่านได้ เริ่มต้น它以 0 แล้วอัลกอริทึมจะส่งผลลัพธ์เป็น 0 สำหรับรายการของเลขลบ ซึ่งเป็นบั๊กที่การติดตามจะเปิดเผยก็ต่อเมื่อข้อมูลทดสอบมีเลขลบเท่านั้น

9.2

Definitions the examiner accepts · ⁨คำนิยามที่ผู้สอบยอมรับ⁩

English

A definition question is marked against fixed wording. Learn these exactly, and give one answer only.

Term Definition
abstraction keeping the essential details of a problem and leaving out the details that are not needed
decomposition breaking a problem down into smaller sub-problems, each of which can be solved separately
algorithm a solution to a problem expressed as a sequence of defined steps
identifier table a table listing each identifier used in an algorithm with its data type and a description of its purpose
pseudocode a structured, language-independent way of writing the steps of an algorithm
flowchart a diagram that shows the steps and decisions of an algorithm using standard symbols joined by arrows
sequence statements executed one after another in the order written
selection choosing which statements to execute according to a condition
iteration repeating a group of statements while, or until, a condition holds
stepwise refinement breaking each step of an outline into smaller steps, repeatedly, until each step can be coded directly
logic statement a condition built from comparisons and the operators AND, OR and NOT that evaluates to TRUE or FALSE
ไทย

คำถามคำนิยามจะให้คะแนนตามข้อความที่กำหนดไว้你必须 exact. เรียนรู้ให้ถูกต้องและตอบเพียงคำตอบเดียวเท่านั้น

พจน์ นิยาม
การลดทอน การรักษารายละเอียดหลักของปัญหาไว้และตัดรายละเอียดที่ไม่จำเป็นออก
การแบ่งย่อย การแตกปัญหาออกเป็นปัญหาย่อยเล็กๆ หลายส่วน โดยแต่ละส่วนสามารถแก้แยกกันได้
อัลกอริทึม วิธีแก้ปัญหาที่แสดงเป็นลำดับขั้นตอนที่กำหนดไว้อย่างชัดเจน
ตารางตัวระบุ ตารางที่ระบุตัวระบุที่ใช้ในอัลกอริทึมพร้อมชนิดข้อมูลและคำอธิบายวัตถุประสงค์
伪โค้ด วิธีการเขียนขั้นตอนของอัลกอริทึมแบบมีโครงสร้างและไม่ขึ้นอยู่กับภาษา
แผนภาพโฟว์ แผนภาพที่แสดงขั้นตอนและการตัดสินใจของอัลกอริทึมโดยใช้สัญลักษณ์มาตรฐานเชื่อมด้วยลูกศร
ลำดับ คำสั่งที่ถูกดำเนินการตามลำดับจากบนลงล่างตามลำดับที่เขียน
การเลือก การเลือกที่จะ wykonาคำสั่งใดตามเงื่อนไขที่กำหนด
การวนซ้ำ การทำซ้ำกลุ่มคำสั่งจนกว่าเงื่อนไขจะเป็นจริงหรือจนกว่าเงื่อนไขจะหมดสภาพ
การปรับระดับทีละขั้น การแตกแต่ละขั้นตอนของโครงร่างออกเป็นขั้นตอนย่อยๆ ซ้ำๆ จนกว่าแต่ละขั้นตอนจะสามารถเขียนโค้ดได้โดยตรง
คำสั่งตรรกะ เงื่อนไขที่สร้างจากการเปรียบเทียบและตัวดำเนินการ AND, OR และ NOT ที่ประเมินค่าได้เป็น TRUE หรือ FALSE
9.2

Exam tips · ⁨ข้อแนะนำสำหรับการสอบ⁩

English
  • Define an algorithm as an unambiguous, finite, deterministic sequence of steps, independent of language.
  • Use the three constructs correctly — sequence, selection, iteration — and keep an identifier table with data types.
  • Break a problem down by decomposition and abstraction, then stepwise refinement.
  • Write pseudocode that would actually run: declare variables and follow the exam's pseudocode style.

Common mistakes

  • Using = to assign a value. Assignment is ←; = is a comparison.
  • Forgetting ENDIF, ENDWHILE, ENDCASE or NEXT. Every construct closes, and the closing word is where the mark for the construct is checked.
  • Not initialising a total or counter before the loop, so the algorithm adds to a value that never existed.
  • Using a FOR loop when the number of repetitions is unknown. Reading until a sentinel value or a correct guess needs WHILE or REPEAT ... UNTIL.
  • Writing Age > 65 OR < 5. Each side of OR and AND must be a complete comparison.
  • Answering "explain why decomposition is used" with one benefit written three ways. Three marks need three different benefits.
ไทย
  • นิยาม อัลกอริทึม ว่าเป็นการลำดับขั้นตอนที่ชัดเจน有限、 deterministic且不依赖语言。
  • ใช้โครงสร้างสามอย่างให้ถูกต้อง — ลำดับ, การเลือก, การวนซ้ำ — และรักษาตารางตัวระบุพร้อมชนิดข้อมูล
  • แตกปัญหาด้วยการ ลดทอนและการแบ่งย่อย จากนั้นจึงปรับระดับทีละขั้น
  • เขียน伪โค้ดที่รันได้จริง: ประกาศตัวแปรและปฏิบัติตามรูปแบบ伪โค้ดของข้อสอบ

ข้อผิดพลาดที่พบบ่อย

  • การใช้ = ในการกำหนดค่า การกำหนดค่าคือ ←; = คือการเปรียบเทียบ
  • ลืม ENDIF, ENDWHILE, ENDCASE หรือ NEXT. ทุกโครงสร้างต้องปิด, และคำปิดคือจุดที่ตรวจสอบคะแนนของโครงสร้างนั้น
  • ไม่ได้เริ่มต้นค่ารวมหรือตัวนับก่อนลูป, ทำให้อัลกอริทึมบวกเข้าไปยังค่าที่ไม่มีอยู่จริง
  • ใช้ FOR ลูปเมื่อจำนวนรอบไม่ทราบ การอ่านจนกว่าจะเจอค่า sentinel หรือทายถูกต้องการ WHILE หรือ REPEAT ... UNTIL
  • เขียน Age > 65 OR < 5. แต่ละฝั่งของ OR และ AND ต้องเป็นการเปรียบเทียบที่สมบูรณ์
  • ตอบ "อธิบายว่าทำไมต้องใช้การแบ่งย่อย" ด้วยประโยชน์หนึ่งเขียนสามวิธี. คะแนนสามข้อต้องการประโยชน์ที่แตกต่างกันสามอย่าง
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
deterministic/dɪˌtɜːmɪˈnɪstɪk/ deterministic

Interactive lessons on this topic · ⁨บทเรียนเชิงโต้ตอบสำหรับหัวข้อนี้⁩

Work through it step by step, with instant-check exercises. · ⁨ทำทีละขั้นตอน พร้อมแบบฝึกหัดตรวจสอบผลทันที⁩

Past Papers · ⁨ข้อสอบย้อนหลัง⁩

More topics in A-Level Computer Science · ⁨Computer Science A-Level⁩ · ⁨หัวข้อเพิ่มเติมใน A-Level Computer Science · ⁨Computer Science A-Level⁩⁩

Log in or create account · ⁨เข้าสู่ระบบหรือสร้างบัญชี⁩

IGCSE, A-Level & AP