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

Algorithms and Programming · ⁨อัลกอริทึมและการเขียนโปรแกรม⁩

AP Computer Science Principles · Topic 3 · ⁨หัวข้อ 3⁩

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

อัลกอริทึมและการเขียนโปรแกรม

จินตนาการสมุดโทรศัพท์ที่มีชื่อนับล้าน และคุณต้องหาหนึ่งชื่อ. ตรวจสอบทีละชื่อ และคุณสามารถอยู่ตรงนั้นทั้งวัน. มีวิธีหาได้ในเวลาประมาณ…

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

English

Code below uses the AP CSP pseudocode – the exam's language-neutral reference. Assignment is written a ← expression, and list indices start at 1.

ไทย

โค้ดด้านล่างใช้ 伪代码ของ AP CSP – ซึ่งเป็นตัวอ้างอิงที่เป็นกลางต่อภาษาสำหรับการสอบ การกำหนดค่าเขียนด้วย a ← expression, และดัชนีของลิสต์เริ่มที่ 1

3.1

Variables and Assignments · ⁨ตัวแปรและการกำหนดค่า⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-1): To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.

Learning Objective AAP-1.A: Represent a value with a variable. [Skill 3.A]

  • AAP-1.A.1 A variable is an abstraction inside a program that can hold a value. Each variable has associated data storage that represents one value at a time, but that value can be a list or other collection that in turn contains multiple values.
  • AAP-1.A.2 Using meaningful variable names helps with the readability of program code and understanding of what values are represented by the variables.
  • AAP-1.A.3 Some programming languages provide types to represent data, which are referenced using variables. These types include numbers, Booleans, lists, and strings.
  • AAP-1.A.4 Some values are better suited to representation using one type of datum rather than another.

Learning Objective AAP-1.B: Determine the value of a variable as a result of an assignment. [Skill 4.B]

  • AAP-1.B.1 The assignment operator allows a program to change the value represented by a variable.

  • AAP-1.B.2 The exam reference sheet provides the "$\leftarrow$" operator to use for assignment. For example,

    Text:

    a ← expression

    Block:

    a ← expression

    evaluates expression and then assigns a copy of the result to the variable a.

  • AAP-1.B.3 The value stored in a variable will be the most recent value assigned. For example:

    a ← 1 b ← a a ← 2 display(b)

    still displays 1.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-1): เพื่อหาคำตอบเฉพาะสำหรับปัญหาทั่วไป นักเขียนโปรแกรมจะแทนที่และจัดระเบียบข้อมูลในหลายรูปแบบ

วัตถุประสงค์การเรียนรู้ AAP-1.A: แทนค่าด้วยตัวแปร [ทักษะ 3.A]

  • AAP-1.A.1 ตัวแปร (variable) คือการนามธรรมภายในโปรแกรมที่สามารถเก็บค่าได้ ตัวแปรแต่ละตัวมีพื้นที่จัดเก็บข้อมูลที่เกี่ยวข้องซึ่งแทนค่าหนึ่ง ณ เวลาหนึ่ง แต่ค่านั้นอาจเป็นลิสต์หรือกลุ่มข้อมูลอื่นที่ประกอบด้วยหลายค่าในขั้นตอนถัดไป
  • AAP-1.A.2 การใช้ชื่อตัวแปรที่มีความหมายช่วยให้โค้ดโปรแกรมอ่านง่ายขึ้นและเข้าใจได้ว่าตัวแปรเหล่านั้นแทนค่าอะไร
  • AAP-1.A.3 ภาษาโปรแกรมบางภาษาจัดเตรียม ประเภท (types) เพื่อแสดงข้อมูล ซึ่งสามารถอ้างอิงผ่านตัวแปร ประเภทเหล่านี้รวมถึงตัวเลข บูลีน ลิสต์ และสตริง
  • AAP-1.A.4 บางค่าเหมาะต่อการแสดงด้วยชนิดของข้อมูลอย่างใดอย่างหนึ่งมากกว่าอีกชนิดหนึ่ง

จุดประสงค์การเรียนรู้ AAP-1.B: หาค่าของตัวแปรจากผลลัพธ์ของการกำหนดค่า [ทักษะ 4.B]

  • AAP-1.B.1 ตัวดำเนินการกำหนดค่า (assignment operator) ช่วยให้โปรแกรมสามารถเปลี่ยนค่าที่ตัวแปรแทนได้

  • ** AAP-1.B.2** ใบสรุปข้อสอบให้ใช้ตัวดำเนินการ "$\leftarrow$" สำหรับการกำหนดค่า ตัวอย่างเช่น,

    ข้อความ:

    a ← expression

    บล็อก:

    a ← expression

    จะประเมิน expression แล้วนำสำเนาของผลลัพธ์มากำหนดให้กับตัวแปร a

  • AAP-1.B.3 ค่าที่เก็บอยู่ในตัวแปรจะเป็นค่าล่าสุดที่ถูกกำหนดให้ ตัวอย่างเช่น:

    a ← 1 b ← a a ← 2 display(b)

    ยังแสดง 1 อยู่

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A variable 变量 is a named place that holds a value. The assignment 赋值 operator stores the value on the right into the variable on the left:

A variable holds one value at a time; assigning again replaces it. Variables let a program store input, remember results, and reuse them.

ไทย

ตัวแปร คือตำแหน่งที่มีชื่อเพื่อเก็บค่า ตัวดำเนินการกำหนดค่า จะจัดเก็บค่าทางขวาลงในตัวแปรทางซ้าย:

ตัวแปรคือที่เก็บที่มีชื่อซึ่งค่าสามารถเปลี่ยนแปลงได้
ตัวแปรคือที่เก็บที่มีชื่อซึ่งค่าสามารถเปลี่ยนแปลงได้
a ← 5
b ← a + 3      // b is now 8

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

Explore · ⁨สำรวจ⁩

Watch a variable hold and change its value · ⁨สังเกตตัวแปรที่ยึดไว้และเปลี่ยนค่านั้น⁩

A variable is a named box that stores one value at a time. An assignment copies a value into the box; assigning again overwrites whatever was there. · ⁨ตัวแปร คือกล่องที่มีชื่อซึ่งจัดเก็บค่าเพียงค่าเดียวในหนึ่งเวลา การกำหนดค่า คัดลอกค่าเข้าไปในกล่อง; การกำหนดค่าใหม่จะ ทับ ค่าเดิมที่มีอยู่⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
variable/ˈveərɪəbl/ ตัวแปร
assignment/əˈsaɪnmənt/ การกำหนดค่า (assignment)
Data abstraction/ˈdeɪtə əbˈstrækʃn/ การนามธรรมของข้อมูล
remainder/rɪˈmeɪndə/ เศษ
string/strɪŋ/ สตริง (String)
concatenation/kənˌkætəˈneɪʃn/ การต่อสตริง (concatenation)
Boolean expression/ˈbuːlɪən ekˈspreʃn/ expression บูลีน
3.2

Data Abstraction · ⁨การ تجريงข้อมูล⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-1): To find specific solutions to generalizable problems, programmers represent and organize data in multiple ways.

Learning Objective AAP-1.C: Represent a list or string using a variable. [Skill 3.A]

  • AAP-1.C.1 A list is an ordered sequence of elements. For example,

    [value1, value2, value3, ...]

    describes a list where value1 is the first element, value2 is the second element, value3 is the third element, and so on.

  • AAP-1.C.2 An element is an individual value in a list that is assigned a unique index.

  • AAP-1.C.3 An index is a common method for referencing the elements in a list or string using natural numbers.

  • AAP-1.C.4 A string is an ordered sequence of characters.

Learning Objective AAP-1.D: For data abstraction: a. Develop data abstraction using lists to store multiple elements. [Skill 3.B] b. Explain how the use of data abstraction manages complexity in program code. [Skill 3.C]

  • AAP-1.D.1 Data abstraction provides a separation between the abstract properties of a data type and the concrete details of its representation.

  • AAP-1.D.2 Data abstractions manage complexity in programs by giving a collection of data a name without referencing the specific details of the representation.

  • AAP-1.D.3 Data abstractions can be created using lists.

  • AAP-1.D.4 Developing a data abstraction to implement in a program can result in a program that is easier to develop and maintain.

  • AAP-1.D.5 Data abstractions often contain different types of elements.

  • AAP-1.D.6 The use of lists allows multiple related items to be treated as a single value. Lists are referred to by different names, such as array, depending on the programming language.

    • Exclusion statement (EK AAP-1.D.6): The use of linked lists is outside the scope of this course and the AP Exam.
  • AAP-1.D.7 The exam reference sheet provides the notation

    [value1, value2, value3, ...]

    to create a list with those values as the first, second, third, and so on items. For example,

    • Text:

      aList ← [value1, value2, value3, ...]

      Block:

      aList ← value1, value2, value3

      creates a new list that contains the values value1, value2, value3, and ... at indices 1, 2, 3, and ... respectively and assigns it to aList.

    • Text:

      aList ← []

      Block:

      aList ← (empty)

      creates a new empty list and assigns it to aList.

    • Text:

      aList ← bList

      Block:

      aList ← bList

      assigns a copy of the list bList to the list aList. For example, if bList contains [20, 40, 60], then aList will also contain [20, 40, 60] after the assignment.

  • AAP-1.D.8 The exam reference sheet describes a list structure whose index values are 1 through the number of elements in the list, inclusive. For all list operations, if a list index is less than 1 or greater than the length of the list, an error message is produced and the program will terminate.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-1): เพื่อหาคำตอบเฉพาะสำหรับปัญหาทั่วไป นักเขียนโปรแกรมจะแทนที่และจัดระเบียบข้อมูลในหลายรูปแบบ

จุดประสงค์การเรียนรู้ AAP-1.C: แสดงรายการหรือสตริงโดยใช้ตัวแปร [ทักษะ 3.A]

  • AAP-1.C.1 รายการ คือลำดับขององค์ประกอบที่มีลำดับ สำหรับตัวอย่าง,

    [value1, value2, value3, ...]

    แสดงรายการที่ value1 เป็นองค์ประกอบแรก, value2 เป็นองค์ประกอบที่สอง, value3 เป็นองค์ประกอบที่สาม และอื่นๆ ตามลำดับ

  • AAP-1.C.2 องค์ประกอบ คือค่าเดี่ยวในรายการที่ถูกกำหนดดัชนีเฉพาะ

  • AAP-1.C.3 ดัชนี เป็นวิธีการทั่วไปในการอ้างอิงองค์ประกอบในรายการหรือสตริงโดยใช้จำนวนเต็มบวก

  • AAP-1.C.4 สตริง คือลำดับของตัวอักษรที่มีลำดับ

จุดประสงค์การเรียนรู้ AAP-1.D: สำหรับการลดทอนข้อมูล: ก. พัฒนาการใช้การลดทอนข้อมูลโดยใช้รายการเพื่อจัดเก็บองค์ประกอบหลายอย่าง [ทักษะ 3.B] ข. อธิบายว่าการใช้การลดทอนข้อมูลช่วยจัดการความซับซ้อนในโค้ดโปรแกรมได้อย่างไร [ทักษะ 3.C]

  • AAP-1.D.1 การลดทอนข้อมูลให้ความแยกแยะระหว่างคุณสมบัติเชิงนามธรรมของชนิดข้อมูลกับรายละเอียดเชิงรูปธรรมของการนำเสนอ

  • AAP-1.D.2 การลดทอนข้อมูลจัดการความซับซ้อนในโปรแกรมโดยการตั้งชื่อชุดข้อมูลโดยไม่อ้างอิงรายละเอียดเฉพาะของการนำเสนอ

  • AAP-1.D.3 สามารถสร้างข้อมูลเชิงนามธรรม (Data abstractions) โดยใช้ลิสต์ได้

  • AAP-1.D.4 การพัฒนาข้อมูลเชิงนามธรรมเพื่อนำไปใช้ในโปรแกรม อาจทำให้โปรแกรมนั้นพัฒนาและบำรุงรักษาง่ายขึ้น

  • AAP-1.D.5 ข้อมูลเชิงนามธรรมมักประกอบด้วยองค์ประกอบหลายประเภท

  • AAP-1.D.6 การใช้ลิสต์ช่วยให้สามารถจัดการกับรายการที่เกี่ยวข้องกันหลายรายการในฐานะค่าเดียว ลิสต์อาจถูกเรียกว่าชื่ออื่น ๆ เช่น array ขึ้นอยู่กับภาษาการเขียนโปรแกรมที่ใช้

    • ข้อยกเว้น (EK AAP-1.D.6): การใช้ลิงค์ลิสต์ (linked lists)อยู่นอกขอบเขตของหลักสูตรนี้และข้อสอบ AP
  • AAP-1.D.7 แผ่นอ้างอิงข้อสอบให้สัญลักษณ์สำหรับ

    [value1, value2, value3, ...]

    เพื่อสร้างลิสต์ที่มีค่าเหล่านั้นเป็นรายการแรก, รายการที่สอง, รายการที่สาม และ seterusnya ตัวอย่างเช่น,

    • ข้อความ:

      aList ← [value1, value2, value3, ...]

      บล็อก:

      aList ← value1, value2, value3

      สร้างรายการใหม่ที่มีค่า value1, value2, value3 และ ... ที่ตำแหน่ง 1, 2, 3 และ ... ตามลำดับ และกำหนดให้รายการนั้นเป็น aList

    • ข้อความ:

      aList ← []

      บล็อก:

      aList ← (ว่างเปล่า)

      สร้างลิสต์ว่างเปล่าใหม่และกำหนดให้ลิสต์นี้เป็น aList

    • ข้อความ:

      aList ← bList

      บล็อก:

      aList ← bList

      คัดลอกลิสต์ bList ไปยังลิสต์ aList ตัวอย่างเช่น หาก bList มีค่า [20, 40, 60] แล้ว послеการคัดลอก aList จะยังมีค่า [20, 40, 60] อยู่ด้วย

  • AAP-1.D.8 แผ่นอ้างอิงข้อสอบอธิบายโครงสร้างลิสต์ซึ่งค่าดรรชนีมีตั้งแต่ 1 ไปจนถึงจำนวนองค์ประกอบในลิสต์ รวมทั้งต้น สำหรับทุกการดำเนินการกับลิสต์ หากดรรชนีลิสต์น้อยกว่า 1 หรือมากกว่าความยาวของลิสต์ จะเกิดข้อความข้อผิดพลาดและโปรแกรมจะหยุดทำงาน

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Data abstraction 数据抽象 lets you manage complexity by giving a single name to a collection of data – for example, a list rather than dozens of separate variables. It hides detail: you use the named collection without worrying about how it is stored. Lists (below) are the course's main data abstraction.

ไทย

การ تجريงข้อมูล ช่วยให้คุณจัดการกับความซับซ้อน bằngการตั้งชื่อชุดข้อมูลเป็นชื่อเดียว – เช่น ลิสต์ แทนที่จะมีตัวแปรแยกหลายสิบตัว มันซ่อนรายละเอียด: คุณใช้ชุดข้อมูลที่ตั้งชื่อนั้นโดยไม่ต้องกังวลว่ามันถูกจัดเก็บอย่างไร ลิสต์ (ด้านล่าง) เป็นวิธีการ تجريงข้อมูลหลักของหลักสูตรนี้

3.3

Mathematical Expressions · ⁨นิพจน์ทางคณิตศาสตร์⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.A: Express an algorithm that uses sequencing without using a programming language. [Skill 2.A]

  • AAP-2.A.1 An algorithm is a finite set of instructions that accomplish a specific task.
  • AAP-2.A.2 Beyond visual and textual programming languages, algorithms can be expressed in a variety of ways, such as natural language, diagrams, and pseudocode.
  • AAP-2.A.3 Algorithms executed by programs are implemented using programming languages.
  • AAP-2.A.4 Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

Learning Objective AAP-2.B: Represent a step-by-step algorithmic process using sequential code statements. [Skill 2.B]

  • AAP-2.B.1 Sequencing is the application of each step of an algorithm in the order in which the code statements are given.
  • AAP-2.B.2 A code statement is a part of program code that expresses an action to be carried out.
  • AAP-2.B.3 An expression can consist of a value, a variable, an operator, or a procedure call that returns a value.
  • AAP-2.B.4 Expressions are evaluated to produce a single value.
  • AAP-2.B.5 The evaluation of expressions follows a set order of operations defined by the programming language.
  • AAP-2.B.6 Sequential statements execute in the order they appear in the code segment.
  • AAP-2.B.7 Clarity and readability are important considerations when expressing an algorithm in a programming language.

Learning Objective AAP-2.C: Evaluate expressions that use arithmetic operators. [Skill 4.B]

  • AAP-2.C.1 Arithmetic operators are part of most programming languages and include addition, subtraction, multiplication, division, and modulus operators.

  • AAP-2.C.2 The exam reference sheet provides a MOD b, which evaluates to the remainder when a is divided by b. Assume that a is an integer greater than or equal to 0 and b is an integer greater than 0. For example, 17 MOD 5 evaluates to 2.

  • AAP-2.C.3 The exam reference sheet provides the arithmetic operators +, -, *, /, and MOD.

    Text and Block:

    • a + b
    • a - b
    • a * b
    • a / b
    • a MOD b

    These are used to perform arithmetic on a and b. For example, 17 / 5 evaluates to 3.4.

  • AAP-2.C.4 The order of operations used in mathematics applies when evaluating expressions. The MOD operator has the same precedence as the * and / operators.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.A: เขียนอัลกอริทึมที่ใช้การเรียงลำดับโดยไม่ใช้ภาษาการเขียนโปรแกรม [ทักษะ 2.A]

  • AAP-2.A.1 อัลกอริทึม คือชุดคำสั่งที่มีจำนวนจำกัดเพื่อทำภารกิจเฉพาะอย่าง
  • AAP-2.A.2 นอกเหนือจากภาษาการเขียน_programming แบบภาพและแบบข้อความ อัลกอริทึมสามารถแสดงออกได้ในหลากหลายรูปแบบ เช่น ภาษาธรรมชาติ แผนภาพ และโค้ดลวง
  • AAP-2.A.3 อัลกอริทึมที่ถูกดำเนินการโดยโปรแกรมจะถูกนำไปใช้ผ่านภาษาการเขียนโปรแกรม
  • AAP-2.A.4 อัลกอริทึมทุกชนิดสามารถสร้างได้จากการผสมผสานของการเรียงลำดับ การเลือก และการวนซ้ำ

จุดประสงค์การเรียนรู้ AAP-2.B: แสดงกระบวนการทางอัลกอริทึมทีละขั้นตอนโดยใช้คำสั่งโค้ดแบบเรียงลำดับ [ทักษะ 2.B]

  • AAP-2.B.1 การเรียงลำดับ คือการนำแต่ละขั้นตอนของอัลกอริทึมไปใช้ตามลำดับที่คำสั่งโค้ดถูกกำหนดไว้
  • AAP-2.B.2 คำสั่งโค้ด เป็นส่วนหนึ่งของโค้ดโปรแกรมที่แสดงถึงการกระทำที่จะดำเนินการ
  • AAP-2.B.3 สมการ สามารถประกอบด้วยค่า ตัวแปร ตัวดำเนินการ หรือการเรียกฟังก์ชันที่คืนค่า
  • AAP-2.B.4 สมการจะถูกประเมินผลเพื่อสร้างค่าเดียว
  • AAP-2.B.5 การประเมินผลสมการจะ遵循ลำดับการดำเนินการที่กำหนดโดยภาษาการเขียนโปรแกรม
  • AAP-2.B.6 คำสั่งแบบเรียงลำดับจะถูกดำเนินการตามลำดับที่ปรากฏในส่วนโค้ด
  • AAP-2.B.7 ความชัดเจนและการอ่านง่ายเป็นปัจจัยสำคัญเมื่อแสดงอัลกอริทึมผ่านภาษาการเขียนโปรแกรม

จุดประสงค์การเรียนรู้ AAP-2.C: ประเมินผลสมการที่ใช้ตัวดำเนินการทางคณิตศาสตร์ [ทักษะ 4.B]

  • AAP-2.C.1 ตัวดำเนินการทางคณิตศาสตร์เป็นส่วนหนึ่งของภาษาการเขียนโปรแกรมส่วนใหญ่และรวมถึงตัวดำเนินการบวก ลบ คูณ หาร และโมดูลัส

  • AAP-2.C.2 ใบอ้างอิงสำหรับการสอบให้ a MOD b ซึ่งประเมินผลลัพธ์เป็นเศษเหลือเมื่อ a หารด้วย b ให้สมมติว่า a เป็นจำนวนเต็มที่มีค่ามากกว่าหรือเท่ากับ 0 และ b เป็นจำนวนเต็มที่มีค่ามากกว่า 0 ตัวอย่างเช่น 17 MOD 5 ประเมินได้ 2

  • AAP-2.C.3 แผ่นอ้างอิงข้อสอบให้ตัวดำเนินการทางคณิตศาสตร์ +, -, *, /, และ MOD

    ข้อความและบล็อก:

    • a + b
    • a - b
    • a * b
    • a / b
    • a MOD b

    ใช้สำหรับการคำนวณทางคณิตศาสตร์บน a และ b ตัวอย่างเช่น 17 / 5 ประเมินผลเป็น 3.4

  • AAP-2.C.4 ลำดับการดำเนินการที่ใช้ในคณิตศาสตร์จะใช้เมื่อประเมินผลสมการ ตัวดำเนินการ MOD มีระดับความสำคัญเท่ากับตัวดำเนินการ * และ /

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Programs compute with the operators +, -, *, /, and MOD (the remainder 余数 of a division, e.g. 17 MOD 5 is 2). Expressions follow the usual order of operations. MOD is especially useful for testing divisibility (n MOD 2 = 0 means n is even) and for wrapping values around a range.

ไทย

โปรแกรมคำนวณด้วยตัวดำเนินการ +, -, *, /, และ MOD (คือ เศษจากการหาร, เช่น 17 MOD 5 คือผลของ 2) นิพจน์ปฏิบัติตามลำดับความสำคัญในการคำนวณปกติ MOD มีประโยชน์มากสำหรับการทดสอบการหาร habis (n MOD 2 = 0 หมายความว่า n เป็นจำนวนคู่) และการวนรอบค่าภายในช่วงที่กำหนด

Explore · ⁨สำรวจ⁩

Evaluate an expression step by step · ⁨คำนวณนิพจน์ทีละขั้นตอน⁩

An expression is evaluated with order of operations: multiplication and division happen before addition and subtraction, left to right. · ⁨นิพจน์ถูกคำนวณตาม ลำดับการดำเนินการ: การคูณและการหารเกิดขึ้นก่อนการบวกและการลบ ทำจากซ้ายไปขวา⁩

3.4

Strings · ⁨สตริง (ข้อความ)⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.D: Evaluate expressions that manipulate strings. [Skill 4.B]

  • AAP-2.D.1 String concatenation joins together two or more strings end-to-end to make a new string.
  • AAP-2.D.2 A substring is part of an existing string.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.D: ประเมินผลสมการที่จัดการกับสตริง [ทักษะ 4.B]

  • AAP-2.D.1 การต่อสตริง (String concatenation) เป็นการเชื่อมสตริงสองตัวขึ้นไปเข้าด้วยกันต่อท้ายกันเพื่อสร้างสตริงใหม่
  • AAP-2.D.2 สับสตริง (Substring) คือส่วนของสตริงที่มีอยู่เดิม

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A string 字符串 is an ordered sequence of characters, like "hello". Programs join strings (concatenation 拼接) and find their length. Strings represent text – names, messages, sequences – and are a common program input and output.

ไทย

สตริง คือลำดับที่มีระเบียบของตัวอักษร เช่น "hello" โปรแกรมสามารถเชื่อมสตริง (การเชื่อมต่อ) และหา ความยาว ของมัน สตริงใช้แทนข้อความ – ชื่อ, ข้อความ, ลำดับ – และเป็นอินพุตและเอาต์พุตของโปรแกรมที่พบบ่อย

3.5

Boolean Expressions · ⁨นิพจน์ boolean⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.E: For relationships between two variables, expressions, or values: a. Write expressions using relational operators. [Skill 2.B] b. Evaluate expressions that use relational operators. [Skill 4.B]

  • AAP-2.E.1 A Boolean value is either true or false.

  • AAP-2.E.2 The exam reference sheet provides the following relational operators: =, ≠, >, <, ≥, and ≤.

    Text and Block:

    • a = b
    • a ≠ b
    • a > b
    • a < b
    • a ≥ b
    • a ≤ b

    These are used to test the relationship between two variables, expressions, or values. A comparison using a relational operator evaluates to a Boolean value. For example, a = b evaluates to true if a and b are equal; otherwise, it evaluates to false.

Learning Objective AAP-2.F: For relationships between Boolean values: a. Write expressions using logical operators. [Skill 2.B] b. Evaluate expressions that use logic operators. [Skill 4.B]

  • AAP-2.F.1 The exam reference sheet provides the logical operators NOT, AND, and OR, which evaluate to a Boolean value.

  • AAP-2.F.2 The exam reference sheet provides

    Text:

    NOT condition

    Block:

    NOT condition

    which evaluates to true if condition is false; otherwise it evaluates to false.

  • AAP-2.F.3 The exam reference sheet provides

    Text:

    condition1 AND condition2

    Block:

    condition1 AND condition2

    which evaluates to true if both condition1 and condition2 are true; otherwise it evaluates to false.

  • AAP-2.F.4 The exam reference sheet provides

    Text:

    condition1 OR condition2

    Block:

    condition1 OR condition2

    which evaluates to true if condition1 is true or if condition2 is true or if both condition1 and condition2 are true; otherwise it evaluates to false.

  • AAP-2.F.5 The operand for a logical operator is either a Boolean expression or a single Boolean value.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.E: สำหรับความสัมพันธ์ระหว่างตัวแปรสองตัว สมการ หรือค่า: a. เขียนสมการโดยใช้ตัวดำเนินการเปรียบเทียบ [ทักษะ 2.B] b. ประเมินผลสมการที่ใช้ตัวดำเนินการเปรียบเทียบ [ทักษะ 4.B]

  • AAP-2.E.1 ค่าบूलีน (Boolean value) มีเพียงจริง (true) หรือเท็จ (false) เท่านั้น

  • AAP-2.E.2 แผ่นอ้างอิงข้อสอบให้ตัวดำเนินการเปรียบเทียบดังนี้: =, ≠, >, <, ≥, และ ≤

    ข้อความและบล็อก:

    • a = b
    • a ≠ b
    • a > b
    • a < b
    • a ≥ b
    • a ≤ b

ใช้เพื่อทดสอบความสัมพันธ์ระหว่างตัวแปรสองตัว นิพจน์ หรือค่า การเปรียบเทียบโดยใช้ relational operator จะประเมินผลเป็นค่า Boolean ตัวอย่างเช่น a = b ประเมินได้ true หาก a และ b เท่ากัน; ในกรณีอื่นจะประเมินได้ false

จุดประสงค์การเรียนรู้ AAP-2.F: สำหรับความสัมพันธ์ระหว่างค่าบูลีน: a. เขียนสมการโดยใช้ตัวดำเนินการตรรกะ [ทักษะ 2.B] b. ประเมินผลสมการที่ใช้ตัวดำเนินการตรรกะ [ทักษะ 4.B]

  • AAP-2.F.1 แผ่นอ้างอิงข้อสอบให้ตัวดำเนินการตรรกะ NOT, AND, และ OR ซึ่งประเมินผลเป็นค่าบูลีน

  • AAP-2.F.2 แผ่นอ้างอิงข้อสอบให้

    ข้อความ:

    NOT condition

    บล็อก:

    NOT condition

    ซึ่งจะให้ค่าเป็น true หาก condition มีค่าเป็น false; ในกรณีอื่นจะให้ค่าเป็น false

  • AAP-2.F.3 แผ่นอ้างอิงข้อสอบให้

    ข้อความ:

    condition1 AND condition2

    บล็อก:

    condition1 AND condition2

    ซึ่งจะให้ค่าเป็น true หากทั้ง condition1 และ condition2 มีค่าเป็น true; ในกรณีอื่นจะให้ค่าเป็น false

  • AAP-2.F.4 ใบสรุปสำหรับการสอบให้

    ข้อความ:

    condition1 OR condition2

    บล็อก:

    condition1 OR condition2

    ซึ่งจะให้ค่าเป็น true หาก condition1 มีค่าเป็น true หรือหาก condition2 มีค่าเป็น true หรือหากทั้ง condition1 และ condition2 มีค่าเป็น true; ในกรณีอื่นจะให้ค่าเป็น false

  • AAP-2.F.5 ตัว operands ของตัวดำเนินการตรรกศาสตร์อาจเป็น expression แบบ Boolean หรือค่า Boolean ค่าเดียว

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A Boolean expression 布尔表达式 evaluates to true or false. It uses relational operators (=, ≠, <, >, ≤, ≥) and logical operators NOT, AND, OR:

  • NOT reverses a value,
  • AND is true only when both sides are true,
  • OR is true when at least one side is true.

These conditions drive every decision and loop.

ไทย

นิพจน์บูลีน มีค่าเป็น true หรือ false ใช้ ตัวดำเนินการเปรียบเทียบ (=, ≠, <, >, ≤, ≥) และ ตัวดำเนินการตรรกะ NOT, AND, OR:

ครอบครัวของ operator สามกลุ่ม: arithmetic, relational, และ logical
ครอบครัวของ operator สามกลุ่ม: arithmetic, relational, และ logical
  • NOT จะกลับค่าหรือผกผันค่า,
  • AND จะเป็นจริงก็ต่อเมื่อ ทั้งสอง ด้านเป็นจริง,
  • OR เป็นจริงเมื่อ อย่างน้อยหนึ่ง ด้านเป็นจริง

เงื่อนไขเหล่านี้ขับเคลื่อนทุกการตัดสินใจและวงลูป

Explore · ⁨สำรวจ⁩

Try the OR truth table · ⁨ลองตารางความจริง OR⁩

A Boolean expression is either true (1) or false (0). OR is true when at least one input is true; flip the inputs to see every case. · ⁨นิพจน์ Boolean เป็นจริง (1) หรือเท็จ (0) OR เป็นจริงเมื่อ อย่างน้อยหนึ่ง อินพุตเป็นจริง; สลับอินพุตเพื่อดูทุกกรณี⁩

3.6

Conditionals · ⁨เงื่อนไข (Conditional)⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.G: Express an algorithm that uses selection without using a programming language. [Skill 2.A]

  • AAP-2.G.1 Selection determines which parts of an algorithm are executed based on a condition being true or false.

Learning Objective AAP-2.H: For selection: a. Write conditional statements. [Skill 2.B] b. Determine the result of conditional statements. [Skill 4.B]

  • AAP-2.H.1 Conditional statements, or "if-statements," affect the sequential flow of control by executing different statements based on the value of a Boolean expression.

  • AAP-2.H.2 The exam reference sheet provides

    Text:

    IF(condition) { <block of statements> }

    Block:

    IF condition block of statements

    in which the code in block of statements is executed if the Boolean expression condition evaluates to true; no action is taken if condition evaluates to false.

  • AAP-2.H.3 The exam reference sheet provides

    Text:

    IF(condition) { <first block of statements> } ELSE { <second block of statements> }

    Block:

    IF condition first block of statements ELSE second block of statements

    in which the code in first block of statements is executed if the Boolean expression condition evaluates to true; otherwise, the code in second block of statements is executed.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.G: เขียนอัลกอริทึมที่ใช้การเลือกโดยไม่ใช้ภาษาโปรแกรมมิ่ง [ทักษะ 2.A]

  • AAP-2.G.1 การเลือก (Selection) กำหนดว่าส่วนใดของอัลกอริทึมจะถูกดำเนินการตามเงื่อนไขที่เป็น true หรือ false

จุดประสงค์การเรียนรู้ AAP-2.H: สำหรับการเลือก: ข. เขียนคำสั่งแบบเงื่อนไข [ทักษะ 2.B] ค. พิจารณาผลลัพธ์ของคำสั่งแบบเงื่อนไข [ทักษะ 4.B]

  • AAP-2.H.1 คำสั่งเงื่อนไข (conditional statements) หรือ "if-statements" มีผลต่อลำดับการทำงานของการควบคุมโดย اجرایคำสั่งที่แตกต่างกันตามค่าของนิพจน์ Boolean

  • AAP-2.H.2 ใบสรุปสำหรับการสอบให้

    ข้อความ:

    IF(condition) { <block of statements> }

    บล็อก:

    IF condition block of statements

    ซึ่งโค้ดใน block of statements จะถูกดำเนินการหาก expression แบบ Boolean condition ให้ค่าเป็น true; ไม่มีการกระทำใดๆ หาก condition ให้ค่าเป็น false

  • AAP-2.H.3 ใบสรุปสำหรับการสอบให้

    ข้อความ:

    IF(condition) { <first block of statements> } ELSE { <second block of statements> }

    บล็อก:

    IF condition first block of statements ELSE second block of statements

    ซึ่งโค้ดใน first block of statements จะถูกดำเนินการหาก expression แบบ Boolean condition ให้ค่าเป็น true; ในกรณีอื่น โค้ดใน second block of statements จะถูกดำเนินการ

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A conditional (selection) 条件语句 chooses which code to run. IF runs a block only when its condition is true; ELSE gives an alternative:

ไทย

เงื่อนไข (การเลือก) เลือกว่าควรรันโค้ดส่วนไหน IF รันบล็อกเฉพาะเมื่อเงื่อนไขเป็นจริง; ELSE ให้ทางเลือกอื่น:

Selection chooses between paths based on a condition
การเลือก (Selection) จะเลือกเส้นทางตามเงื่อนไข
IF (score ≥ 60)
{
    DISPLAY("Pass")
}
ELSE
{
    DISPLAY("Fail")
}
Explore · ⁨สำรวจ⁩

Follow an if / else decision · ⁨ติดตามการตัดสินใจ if / else⁩

A conditional runs one branch or another depending on whether its condition is true. Slide the value across the threshold and watch which branch is taken. · ⁨เงื่อนไข จะเรียกใช้สาขาหนึ่งหรืออีกสาขาหนึ่งขึ้นอยู่กับว่าเงื่อนไขเป็นจริงหรือไม่ เลื่อนค่าข้ามเกณฑ์ดูว่าสาขาใดถูกเลือก⁩

3.7

Nested Conditionals · ⁨เงื่อนไขซ้อนกัน⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.I: For nested selection: a. Write nested conditional statements. [Skill 2.B] b. Determine the result of nested conditional statements. [Skill 4.B]

  • AAP-2.I.1 Nested conditional statements consist of conditional statements within conditional statements.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

วัตถุประสงค์การเรียนรู้ AAP-2.I: สำหรับโครงสร้างการเลือก: a. เขียนคำสั่งเงื่อนไขแบบซ้อนกัน [ทักษะ 2.B] b. กำหนดผลลัพธ์ของคำสั่งเงื่อนไขแบบซ้อนกัน [ทักษะ 4.B]

  • AAP-2.I.1 คำสั่งเงื่อนไขแบบซ้อนกันประกอบด้วยคำสั่งเงื่อนไขที่อยู่ภายในคำสั่งเงื่อนไขอื่น

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A nested conditional 嵌套条件 places one IF inside another (or chains ELSE IF) to choose among more than two paths. Only the first matching branch runs:

ไทย

เงื่อนไขแบบซ้อน (Nested conditional) จะวาง IF หนึ่งตัวภายในอีกตัวหนึ่ง (หรือเชื่อม ELSE IF) เพื่อเลือกจาก มากกว่าสอง ทาง只会 executes the first matching branch:

IF (g ≥ 90)      { grade ← "A" }
ELSE IF (g ≥ 80) { grade ← "B" }
ELSE             { grade ← "C" }
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
conditional (selection)/kənˈdɪʃənl/ เงื่อนไข (การเลือก)
nested conditional/ˈnestɪd kənˈdɪʃənl/ เงื่อนไขซ้อน
Iteration (a loop)/ˌɪtəˈreɪʃn/ การซ้ำ (ลูป)
3.8

Iteration · ⁨การวนซ้ำ⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.J: Express an algorithm that uses iteration without using a programming language. [Skill 2.A]

  • AAP-2.J.1 Iteration is a repeating portion of an algorithm. Iteration repeats a specified number of times or until a given condition is met.

Learning Objective AAP-2.K: For iteration: a. Write iteration statements. [Skill 2.B] b. Determine the result or side effect of iteration statements. [Skill 4.B]

  • AAP-2.K.1 Iteration statements change the sequential flow of control by repeating a set of statements zero or more times, until a stopping condition is met.

  • AAP-2.K.2 The exam reference sheet provides

    Text:

    REPEAT n TIMES { <block of statements> }

    Block:

    REPEAT n TIMES block of statements

    in which the block of statements is executed n times.

  • AAP-2.K.3 The exam reference sheet provides

    Text:

    REPEAT UNTIL(condition) { <block of statements> }

    Block:

    REPEAT UNTIL condition block of statements

    in which the code in block of statements is repeated until the Boolean expression condition evaluates to true.

  • AAP-2.K.4 In REPEAT UNTIL(condition) iteration, an infinite loop occurs when the ending condition will never evaluate to true.

  • AAP-2.K.5 In REPEAT UNTIL(condition) iteration, if the conditional evaluates to true initially, the loop body is not executed at all, due to the condition being checked before the loop.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

วัตถุประสงค์การเรียนรู้ AAP-2.J: แสดงอัลกอริทึมที่ใช้การทำซ้ำโดยไม่ใช้ภาษาโปรแกรม [ทักษะ 2.A]

  • AAP-2.J.1 การทำซ้ำ คือส่วนที่ซ้ำกันในอัลกอริทึม การทำซ้ำจะทำงานจำนวนครั้งที่กำหนดหรือจนกว่าจะมีเงื่อนไขที่กำหนดเกิดขึ้น

วัตถุประสงค์การเรียนรู้ AAP-2.K: สำหรับการทำซ้ำ: a. เขียนคำสั่งการทำซ้ำ [ทักษะ 2.B] b. กำหนดผลลัพธ์หรือ side effect ของ iteration statements [Skill 4.B]

  • AAP-2.K.1 คำสั่งการทำซ้ำจะเปลี่ยนการไหลตามลำดับของการควบคุมโดยการทำซ้ำชุดคำสั่งไปเป็นศูนย์หรือมากกว่าหนึ่งครั้ง จนกว่าจะมีเงื่อนไขหยุดเกิด

  • ** AAP-2.K.2** ใบสรุปข้อสอบให้ไว้สำหรับ

    ข้อความ:

    REPEAT n TIMES { <block of statements> }

    บล็อก:

    REPEAT n TIMES block of statements

    ซึ่ง block of statements จะถูกดำเนินการ n ครั้ง

  • ** AAP-2.K.3** ใบสรุปข้อสอบให้ไว้สำหรับ

    ข้อความ:

    REPEAT UNTIL(condition) { <block of statements> }

    บล็อก:

    REPEAT UNTIL condition block of statements

    ซึ่งโค้ดใน block of statements จะถูกทำซ้ำจนกว่านิพจน์布尔 condition จะประเมินค่าได้ true

  • ** AAP-2.K.4** ในการทำซ้ำ REPEAT UNTIL(condition) การวนลูป vô hạn (infinite loop) จะเกิดขึ้นเมื่อเงื่อนไขสิ้นสุดจะไม่ pernahประเมินค่าได้ true

  • ** AAP-2.K.5** ในการทำซ้ำ REPEAT UNTIL(condition) หากเงื่อนไขประเมินค่าได้ true ในเริ่มต้น ร่าง(loop body) จะไม่ถูกดำเนินการเลย เนื่องจากมีการตรวจสอบเงื่อนไขก่อนการวนลูป

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Iteration (a loop) 迭代 repeats instructions. AP pseudocode has two forms:

A loop that never meets its stopping condition is an infinite loop 无限循环.

ไทย

การวนซ้ำ (a loop) ทำซ้ำคำสั่ง AP Pseudocode มีสองรูปแบบ:

เงื่อนไขก่อนเริ่ม (WHILE) ตรวจสอบก่อน執行 body ดังนั้นอาจไม่ทำงานเลย
เงื่อนไขก่อนเริ่ม (WHILE) ตรวจสอบก่อน執行 body ดังนั้นอาจไม่ทำงานเลย
REPEAT 5 TIMES        // a fixed count
{
    DISPLAY("hi")
}

REPEAT UNTIL (found)  // until a condition becomes true
{
    ...
}

Loop ที่ไม่มีวันตรงตามเงื่อนไขหยุดคือ loop ลวง (infinite loop)

Explore · ⁨สำรวจ⁩

Trace a loop one pass at a time · ⁨ติดตามลูปหนึ่งรอบต่อครั้ง⁩

A loop repeats a block while its counter runs through a range. Step through to watch the counter and the running total update each pass. · ⁨ลูป ทำซ้ำบล็อกขณะที่ตัวนับวนผ่านช่วงหนึ่ง ก้าวไปทีละขั้นเพื่อดูว่าตัวนับและผลรวมที่สะสมอัปเดตในรอบถัดไปอย่างไร⁩

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
infinite loop/ˈɪnfɪnət luːp/ ลูปไม่สิ้นสุด
algorithm/ˈælɡərɪθəm/ อัลกอริทึม
3.9

Developing Algorithms · ⁨การพัฒนาอัลกอริทึม⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.L: Compare multiple algorithms to determine if they yield the same side effect or result. [Skill 1.D]

  • AAP-2.L.1 Algorithms can be written in different ways and still accomplish the same tasks.
  • AAP-2.L.2 Algorithms that appear similar can yield different side effects or results.
  • AAP-2.L.3 Some conditional statements can be written as equivalent Boolean expressions.
  • AAP-2.L.4 Some Boolean expressions can be written as equivalent conditional statements.
  • AAP-2.L.5 Different algorithms can be developed or used to solve the same problem.

Learning Objective AAP-2.M: For algorithms: a. Create algorithms. [Skill 2.A] b. Combine and modify existing algorithms. [Skill 2.B]

  • AAP-2.M.1 Algorithms can be created from an idea, by combining existing algorithms, or by modifying existing algorithms.
  • AAP-2.M.2 Knowledge of existing algorithms can help in constructing new ones. Some existing algorithms include:
    • determining the maximum or minimum value of two or more numbers
    • computing the sum or average of two or more numbers
    • identifying if an integer is or is not evenly divisible by another integer
    • determining a robot's path through a maze
  • AAP-2.M.3 Using existing correct algorithms as building blocks for constructing another algorithm has benefits such as reducing development time, reducing testing, and simplifying the identification of errors.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

วัตถุประสงค์การเรียนรู้ AAP-2.L: เปรียบเทียบอัลกอริทึมหลายตัวเพื่อกำหนดว่าให้ผลข้างเคียงหรือผลลัพธ์เหมือนกันหรือไม่ [ทักษะ 1.D]

  • AAP-2.L.1 อัลกอริทึมสามารถเขียนได้หลายรูปแบบและยังคงทำหน้าที่เดียวกัน
  • AAP-2.L.2 อัลกอริทึมที่ดูคล้ายกันอาจก่อให้เกิดผลข้างเคียงหรือผลลัพธ์ที่แตกต่างกัน
  • AAP-2.L.3 บางเงื่อนไขสามารถเขียนเป็นนิพจน์บูลีนที่เทียบเท่ากันได้
  • AAP-2.L.4 บางนิพจน์布尔ีਅनสามารถเขียนเป็นเงื่อนไขที่เทียบเท่ากันได้
  • AAP-2.L.5 อัลกอริทึมที่แตกต่างกันสามารถพัฒนาขึ้นหรือนำไปใช้เพื่อแก้ปัญหาเดียวกันได้

วัตถุประสงค์การเรียนรู้ AAP-2.M: สำหรับอัลกอริทึม: ก. สร้างอัลกอริทึม [ทักษะ 2.A] ข. รวมและดัดแปลงอัลกอริทึมที่มีอยู่ [ทักษะ 2.B]

  • AAP-2.M.1 อัลกอริทึมสามารถสร้างจากแนวคิด通过将 existing algorithms, หรือ通过将 modifying existing algorithms.
  • AAP-2.M.2 ความรู้เกี่ยวกับอัลกอริทึมที่มีอยู่สามารถช่วยในการสร้างอัลกอริทึมใหม่阿尔กอริทึมที่มีอยู่บางตัวอย่าง ได้แก่:
    • การหาค่าสูงสุดหรือค่าต่ำสุดของตัวเลขสองตัวขึ้นไป
    • การคำนวณผลรวมหรือค่าเฉลี่ยของตัวเลขสองตัวขึ้นไป
    • การตรวจสอบว่าจำนวนเต็มหารด้วยจำนวนเต็มอีกตัวหนึ่งได้ลงตัวหรือไม่
    • การกำหนดเส้นทางของหุ่นยนต์ผ่านเขาวงกต
  • AAP-2.M.3 การใช้อัลกอริทึมที่ถูกต้องและมีอยู่แล้วเป็นองค์ประกอบในการสร้างอัลกอริทึมอื่นมีประโยชน์ เช่น ลดเวลาในการพัฒนา ลดการทดสอบ และทำให้การระบุข้อผิดพลาดง่ายขึ้น

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

An algorithm is not the same thing as code. Beyond visual and textual programming languages, an algorithm can be expressed in a variety of ways: in natural language (ordinary sentences), as a diagram such as a flowchart, or in pseudocode. Those forms are for people — they let you check the logic and agree on it before any language is chosen, and the same algorithm can then be written in any language.

When you do write it in a programming language, clarity and readability are important considerations, not decoration: meaningful variable names, consistent indentation and comments explaining why rather than what. The program has to be read and modified later by someone — often you — and an algorithm nobody can follow cannot be maintained or debugged.

An algorithm 算法 is a finite sequence of steps that solves a problem, built from sequencing, selection, and iteration. Different algorithms can solve the same problem, and you should be able to combine and modify existing algorithms (for example, count the values in a list that meet a condition, or find the largest). Trace an algorithm by hand to check it is correct.

ไทย
โค้ด Python บนหน้าจอ — อัลกอริทึมคือคำแนะนำที่แม่นยำและเรียงลำดับ
โค้ด Python บนหน้าจอ — อัลกอริทึมคือคำแนะนำที่แม่นยำและเรียงลำดับ

อัลกอริทึมไม่ใช่สิ่งที่เหมือนกับโค้ด นอกเหนือจากภาษาโปรแกรมมิ่งแบบภาพและข้อความ อัลกอริทึมสามารถแสดงออกได้เป็น หลายรูปแบบ: ใน ภาษาธรรมชาติ (ประโยคธรรมดา), เป็น แผนภาพ เช่น flowchart, หรือเป็น pseudocode รูปแบบเหล่านี้ใช้สำหรับคน — ทำให้คุณตรวจสอบตรรกะและเห็นพ้องต้องกันก่อนเลือกภาษา และอัลกอริทึมเดียวกันนั้นสามารถเขียนด้วยภาษาใดก็ได้

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

อัลกอริทึมคือลำดับขั้นตอนที่มีจำนวนจำกัดที่ใช้แก้ปัญหา สร้างขึ้นจาก การจัดลำดับ, การเลือก, และ การวนซ้ำ อัลกอริทึมที่แตกต่างกันสามารถแก้ปัญหาคู่เดียวกันได้ และคุณควรสามารถรวมและปรับอัลกอริทึมที่มีอยู่ (เช่น นับค่าในลิสต์ที่ตรงตามเงื่อนไข, หรือหาค่าสูงสุด) ทดสอบอัลกอริทึมด้วยมือเพื่อตรวจสอบความถูกต้อง

Flowchart แสดงอัลกอริทึมโดยใช้สัญลักษณ์มาตรฐาน
Flowchart แสดงอัลกอริทึมโดยใช้สัญลักษณ์มาตรฐาน
3.10

Lists · ⁨รายการ⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.N: For list operations: a. Write expressions that use list indexing and list procedures. [Skill 2.B] b. Evaluate expressions that use list indexing and list procedures. [Skill 4.B]

  • AAP-2.N.1 The exam reference sheet provides basic operations on lists, including:
    • accessing an element by index

      Text:

      aList[i]

      Block:

      aList i

      accesses the element of aList at index i. The first element of aList is at index 1 and is accessed using the notation aList[1].

    • assigning a value of an element of a list to a variable

      Text:

      x ← aList[i]

      Block:

      x ← aList i

      assigns the value of aList[i] to the variable x.

    • assigning a value to an element of a list

      Text:

      aList[i] ← x

      Block:

      aList i ← x

      assigns the value of x to aList[i].

      Text:

      aList[i] ← aList[j]

      Block:

      aList i ← aList j

      assigns the value of aList[j] to aList[i].

    • inserting elements at a given index

      Text:

      INSERT(aList, i, value)

      Block:

      INSERT aList, i, value

      shifts to the right any values in aList at indices greater than or equal to i. The length of the list is increased by 1, and value is placed at index i in aList.

    • adding elements to the end of the list

      Text:

      APPEND(aList, value)

      Block:

      APPEND aList, value

      increases the length of aList by 1, and value is placed at the end of aList.

    • removing elements

      Text:

      REMOVE(aList, i)

      Block:

      REMOVE aList, i

      removes the item at index i in aList and shifts to the left any values at indices greater than i. The length of aList is decreased by 1.

    • determining the length of a list

      Text:

      LENGTH(aList)

      Block:

      LENGTH aList

      evaluates to the number of elements currently in aList.

  • AAP-2.N.2 List procedures are implemented in accordance with the syntax rules of the programming language.

Learning Objective AAP-2.O: For algorithms involving elements of a list: a. Write iteration statements to traverse a list. [Skill 2.B] b. Determine the result of an algorithm that includes list traversals. [Skill 4.B]

  • AAP-2.O.1 Traversing a list can be a complete traversal, where all elements in the list are accessed, or a partial traversal, where only a portion of elements are accessed.

    • Exclusion statement (EK AAP-2.O.1): Traversing multiple lists at the same time using the same index for both (parallel traversals) is outside the scope of this course and the AP Exam.
  • AAP-2.O.2 Iteration statements can be used to traverse a list.

  • AAP-2.O.3 The exam reference sheet provides

    Text:

    FOR EACH item IN aList { <block of statements> }

    Block:

    FOR EACH item IN aList block of statements

    The variable item is assigned the value of each element of aList sequentially, in order, from the first element to the last element. The code in block of statements is executed once for each assignment of item.

  • AAP-2.O.4 Knowledge of existing algorithms that use iteration can help in constructing new algorithms. Some examples of existing algorithms that are often used with lists include:

    • determining a minimum or maximum value in a list
    • computing a sum or average of a list of numbers
  • AAP-2.O.5 Linear search or sequential search algorithms check each element of a list, in order, until the desired value is found or all elements in the list have been checked.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.N: สำหรับการจัดการกับลิสต์: ก. เขียนนิพจน์ที่ใช้การเข้าถึงตำแหน่ง (indexing) ของลิสต์และฟังก์ชันของลิสต์ [ทักษะ 2.B] ข. ประเมินนิพจน์ที่ใช้การเข้าถึงตำแหน่ง (indexing) ของลิสต์และฟังก์ชันของลิสต์ [ทักษะ 4.B]

  • AAP-2.N.1 ใบสรุปข้อสอบให้ใช้การดำเนินการพื้นฐานบนลิสต์ รวมถึง:
    • การเข้าถึงองค์ประกอบโดยใช้อินเด็กซ์

      ข้อความ:

      aList[i]

      บล็อก:

      aList i

      เข้าถึงองค์ประกอบของ aList ที่อินเด็กซ์ i องค์ประกอบแรกของ aList อยู่ที่อินเด็กซ์ 1 และเข้าถึงโดยใช้สัญลักษณ์ aList[1]

    • การกำหนดค่าขององค์ประกอบลิสต์ให้กับตัวแปร

      ข้อความ:

      x ← aList[i]

      บล็อก:

      x ← aList i

      กำหนดค่าของ aList[i] ให้กับตัวแปร x

    • การกำหนดค่าให้กับองค์ประกอบของลิสต์

      ข้อความ:

      aList[i] ← x

      บล็อก:

      aList i ← x

      กำหนดค่าของ x ให้กับ aList[i]

      ข้อความ:

      aList[i] ← aList[j]

      บล็อก:

      aList i ← aList j

      กำหนดค่าของ aList[j] ให้กับ aList[i]

    • การแทรกองค์ประกอบที่อินเด็กซ์ที่กำหนด

      ข้อความ:

      INSERT(aList, i, value)

      บล็อก:

      INSERT aList, i, value

      ย้ายค่าใดๆ ใน aList ที่มี index มากกว่าหรือเท่ากับ i ไปทางขวา ความยาวของรายการจะเพิ่มขึ้น 1 และ value จะถูกวางไว้ที่ index i ใน aList

    • การเพิ่มองค์ประกอบไปที่ท้ายลิสต์

      ข้อความ:

      APPEND(aList, value)

      บล็อก:

      APPEND aList, value

      เพิ่มความยาวของ aList ขึ้น 1 และ value ถูกวางไว้ที่ท้ายของ aList

    • การลบองค์ประกอบออก

      ข้อความ:

      REMOVE(aList, i)

      บล็อก:

      REMOVE aList, i

      ลบรายการที่อินเด็กซ์ i ใน aList ออก และย้ายค่าทั้งหมดที่มีอินเด็กซ์มากกว่า i ไปทางซ้าย ความยาวของ aList ลดลง 1

    • การตรวจสอบความยาวของลิสต์

      ข้อความ:

      LENGTH(aList)

      บล็อก:

      LENGTH aList

      มีค่าเท่ากับจำนวนองค์ประกอบที่มีอยู่ใน aList ปัจจุบัน

  • AAP-2.N.2 ฟังก์ชันของลิสต์ถูกนำไปใช้ตามกฎไวยากรณ์ของภาษาโปรแกรม

จุดประสงค์การเรียนรู้ AAP-2.O: สำหรับอัลกอริทึมที่เกี่ยวข้องกับองค์ประกอบของลิสต์: ก. เขียนคำสั่งการทำซ้ำเพื่อสำรวจลิสต์ [ทักษะ 2.B] ข. หาผลลัพธ์ของอัลกอริทึมที่รวมถึงการสำรวจลิสต์ [ทักษะ 4.B]

  • AAP-2.O.1 การสำรวจลิสต์อาจเป็นการสำรวจแบบเต็ม โดยเข้าถึงองค์ประกอบทั้งหมดในลิสต์ หรือเป็นการสำรวจแบบบางส่วน โดยเข้าถึงเพียงส่วนหนึ่งขององค์ประกอบเท่านั้น

    • ข้อความยกเว้น (EK AAP-2.O.1): การสำรวจหลายลิสต์พร้อมกันโดยใช้ดัชนีเดียวกันสำหรับทั้งสอง (การสำรวจแบบขนาน)อยู่นอกขอบเขตของรายวิชาและข้อสอบ AP
  • AAP-2.O.2 คำสั่งการทำซ้ำสามารถใช้เพื่อสำรวจลิสต์

  • AAP-2.O.3 ใบสรุปข้อสอบให้ใช้

    ข้อความ:

    FOR EACH item IN aList { <block of statements> }

    บล็อก:

    FOR EACH item IN aList block of statements

    ตัวแปร item จะได้รับค่าของแต่ละองค์ประกอบของ aList ตามลำดับ จากองค์ประกอบแรกไปจนถึงองค์ประกอบสุดท้าย โค้ดใน block of statements จะถูกดำเนินการหนึ่งครั้งสำหรับแต่ละการกำหนดค่าของ item

  • AAP-2.O.4 ความรู้เกี่ยวกับอัลกอริทึมที่มีอยู่เดิมที่ใช้การทำซ้ำสามารถช่วยในการสร้างอัลกอริทึมใหม่ ตัวอย่างของอัลกอริทึมที่มีอยู่เดิมที่มักใช้ร่วมกับลิสต์ ได้แก่:

    • การหาค่าต่ำสุดหรือสูงสุดในลิสต์
    • การคำนวณผลรวมหรือค่าเฉลี่ยของลิสต์ตัวเลข
  • AAP-2.O.5 อัลกอริทึมการค้นหาเชิงเส้นหรือการค้นหาลำดับ (sequential search) จะตรวจสอบแต่ละองค์ประกอบของลิสต์ตามลำดับ จนกว่าจะพบค่าที่ต้องการหรือตรวจสอบองค์ประกอบทั้งหมดในลิสต์แล้ว

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A list 列表 is an ordered collection of values under one name, the course's key data abstraction. AP pseudocode indexes from 1:

Traverse a list with a loop to sum, count, search, or find a maximum:

ไทย

ลิสต์ (list) คือกลุ่มของค่าที่เป็นลำดับภายใต้ชื่อเดียว ซึ่งเป็น abstraction ของข้อมูลหลักของรายวิชา AP Pseudocode ใช้ดัชนีเริ่มต้นที่ 1:

ลิสต์เก็บหลายค่าในตัวแปรเดียว แต่ละค่าเข้าถึงผ่านดัชนีของมัน
ลิสต์เก็บหลายค่าในตัวแปรเดียว แต่ละค่าเข้าถึงผ่านดัชนีของมัน
scores ← [88, 74, 95]
DISPLAY(scores[1])          // 88
scores[2] ← 80              // replace the 2nd value
APPEND(scores, 60)          // add to the end
INSERT(scores, 1, 100)      // insert at index 1
REMOVE(scores, 3)           // delete the 3rd element
LENGTH(scores)              // how many elements

traverse ลิสต์ด้วย loop เพื่อบวก, นับ, ค้นหา, หรือหาค่าสูงสุด:

FOR EACH x IN scores
{
    total ← total + x
}
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
list/lɪst/ รายการ
abstraction/əbˈstrækʃn/ การห่อหุ้ม (abstraction)
library/ˈlaɪbrəri/ ไลบรารี (library)
3.11

Binary Search · ⁨การค้นหาแบบเบี่ยงกลาง (Binary Search)⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-2): The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.

Learning Objective AAP-2.P: For binary search algorithms: a. Determine the number of iterations required to find a value in a data set. [Skill 1.D] b. Explain the requirements necessary to complete a binary search. [Skill 1.A]

  • AAP-2.P.1 The binary search algorithm starts at the middle of a sorted data set of numbers and eliminates half of the data; this process repeats until the desired value is found or all elements have been eliminated.
    • Exclusion statement (EK AAP-2.P.1): Specific implementations of the binary search are outside the scope of the course and the AP Exam.
  • AAP-2.P.2 Data must be in sorted order to use the binary search algorithm.
  • AAP-2.P.3 Binary search is often more efficient than sequential/linear search when applied to sorted data.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-2): วิธีการเรียงลำดับและรวมคำสั่งในโปรแกรมจะกำหนดผลลัพธ์ที่ได้จากการคำนวณ โปรแกรมมีการใช้โครงสร้างการทำซ้ำและการเลือกเพื่อแสดงถึงการทำซ้ำและการตัดสินใจเพื่อจัดการกับค่าอินพุตที่หลากหลาย

จุดประสงค์การเรียนรู้ AAP-2.P: สำหรับอัลกอริทึมการค้นหาแบบเบี่ยง二分: ก. หาจำนวนรอบการทำซ้ำที่จำเป็นในการหาค่าในชุดข้อมูล [ทักษะ 1.D] ข. อธิบายข้อกำหนดที่จำเป็นสำหรับการดำเนินการค้นหาแบบเบี่ยง二分 [ทักษะ 1.A]

  • AAP-2.P.1 อัลกอริทึมการค้นหาแบบเบี่ยง二分เริ่มที่ตรงกลางของชุดข้อมูลที่เรียงลำดับแล้วและตัดข้อมูลออกครึ่งหนึ่ง กระบวนการนี้จะทำซ้ำจนกว่าจะพบค่าที่ต้องการหรือองค์ประกอบทั้งหมดถูกตัดออก
    • ข้อความยกเว้น (EK AAP-2.P.1): การนำไปใช้เฉพาะของ Binary Search อยู่ภายนอกขอบเขตของรายวิชาและข้อสอบ AP
  • AAP-2.P.2 ข้อมูลต้องอยู่ในรูปแบบที่เรียงลำดับแล้วจึงจะใช้ algoritme การค้นหาแบบเบี่ยง二分
  • AAP-2.P.3 การค้นหาแบบเบี่ยง二分มักมีประสิทธิภาพมากกว่าการค้นหาลำดับ/linear search เมื่อใช้กับข้อมูลที่เรียงลำดับแล้ว

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Binary search 二分搜索 finds a value in a sorted list far faster than checking each element. It looks at the middle element, then discards the half that cannot contain the target, repeating until found. Each step halves the search space, so a list of $n$ items takes about $\log_2 n$ steps. It requires the data to be sorted first.

Worked example. Searching a sorted list of $8$ items, binary search halves the range each step: $8\rightarrow4\rightarrow2\rightarrow1$, at most $3$ comparisons ($\log_2 8=3$), whereas a linear search could take up to $8$. The advantage grows explosively: about $1{,}000$ items need only $\approx10$ binary-search steps (but up to $1{,}000$ linear ones), and $1{,}000{,}000$ items need just $\approx20$. Halving is what makes it a reasonable-time algorithm.

ไทย
สมุดโทรศัพท์: การค้นหาแบบเบี่ยงกลางลดจำนวนหน้าที่เหลือลงครึ่งหนึ่งในแต่ละขั้นตอน
สมุดโทรศัพท์: การค้นหาแบบเบี่ยงกลางลดจำนวนหน้าที่เหลือลงครึ่งหนึ่งในแต่ละขั้นตอน

การค้นหาแบบทวิภาค (Binary search) ช่วยหาค่าในรายการที่ เรียงลำดับ แล้วได้เร็วมากเมื่อเทียบกับการตรวจสอบแต่ละองค์ประกอบ มันพิจารณาองค์ประกอบตรงกลาง จากนั้นตัดครึ่งส่วนที่ไม่อาจมีเป้าหมายไว้ ทวนซ้ำจนกว่าจะพบ Each step ลดเหลือครึ่งหนึ่ง ของพื้นที่ค้นหา ดังนั้นรายการขนาด $n$ ใช้เวลาประมาณ $\log_2 n$ ขั้นตอน มัน ต้องการให้ข้อมูลถูกเรียงลำดับก่อน

Binary search halves the range at each step (the list must be sorted)
Binary search halves the range at each step (the list must be sorted)

ตัวอย่างปฏิบัติ. การค้นหาในรายการที่เรียงลำดับ $8$ องค์ประกอบ Binary search ลดครึ่งช่วงในแต่ละขั้นตอน: $8\rightarrow4\rightarrow2\rightarrow1$, ทำการเปรียบเทียบสูงสุด $3$ ครั้ง ($\log_2 8=3$), ในขณะที่การค้นหาแบบเชิงเส้นอาจใช้ถึง $8$ ครั้ง ความได้เปรียบเพิ่มขึ้นอย่างมหาศาล: รายการประมาณ $1{,}000$ องค์ประกอบ ต้องการขั้นตอน binary search เพียง $\approx10$ ขั้น (แต่สูงสุดถึง $1{,}000$ ขั้นสำหรับ linear search), และรายการ $1{,}000{,}000$ องค์ประกอบ ต้องใช้เพียง $\approx20$ ขั้น การลดเหลือครึ่งหนึ่งคือสิ่งที่ทำให้มันเป็นอัลกอริทึมที่มี ระยะเวลาในการคำนวณสมเหตุสมผล

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
Binary search/ˈbaɪnəri sɜːtʃ/ การค้นหาแบบทวิภาคี
3.12

Calling Procedures · ⁨การเรียกใช้งาน Procedure⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-3): Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Learning Objective AAP-3.A: For procedure calls: a. Write statements to call procedures. [Skill 3.B] b. Determine the result or effect of a procedure call. [Skill 4.B]

  • AAP-3.A.1 A procedure is a named group of programming instructions that may have parameters and return values.

  • AAP-3.A.2 Procedures are referred to by different names, such as method or function, depending on the programming language.

  • AAP-3.A.3 Parameters are input variables of a procedure. Arguments specify the values of the parameters when a procedure is called.

  • AAP-3.A.4 A procedure call interrupts the sequential execution of statements, causing the program to execute the statements within the procedure before continuing. Once the last statement in the procedure (or a return statement) has executed, flow of control is returned to the point immediately following where the procedure was called.

  • AAP-3.A.5 The exam reference sheet provides

    procName(arg1, arg2, ...)

    as a way to call

    Text:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

    Block:

    PROCEDURE procName parameter1, parameter2,... block of statements

    which takes zero or more arguments; arg1 is assigned to parameter1, arg2 is assigned to parameter2, and so on.

  • AAP-3.A.6 The exam reference sheet provides the procedure

    Text:

    DISPLAY(expression)

    Block:

    DISPLAY expression

    to display the value of expression, followed by a space.

  • AAP-3.A.7 The exam reference sheet provides the

    Text:

    RETURN(expression)

    Block:

    RETURN expression

    statement, which is used to return the flow of control to the point where the procedure was called and to return the value of expression.

  • AAP-3.A.8 The exam reference sheet provides

    result ← procName(arg1, arg2, ...)

    to assign to result the "value of the procedure" being returned by calling

    Text:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

    Block:

    PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

  • AAP-3.A.9 The exam reference sheet provides procedure

    Text:

    INPUT()

    Block:

    INPUT

    which accepts a value from the user and returns the input value.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-3): นักพัฒนาโปรแกรมแยกปัญหาออกเป็นส่วนย่อยๆ ที่จัดการได้ง่ายขึ้น通过将创建过程和利用参数,开发者可以概括出可重复使用的流程。过程允许开发者调用已经测试过的现有代码,从而能够更快速、更有信心地编写程序。

**学习目标 AAP-3.A:**对于过程调用: a. 编写语句以调用过程。[技能 3.B] b. 确定过程调用的结果或效果。[技能 4.B]

  • AAP-3.A.1 过程是命名的一组编程指令,可能包含参数和返回值。

  • AAP-3.A.2 根据编程语言的不同,过程也被称为方法或函数等不同的名称。

  • AAP-3.A.3 参数是过程的输入变量。实参指定了过程被调用时参数的值。

  • AAP-3.A.4 过程调用会中断顺序执行的语句流,导致程序在执行完过程内的语句后才继续执行。一旦过程内的最后一条语句(或返回语句)执行完毕,控制流将返回到调用过程后的下一个位置。

  • AAP-3.A.5 考试参考表提供了

    procName(arg1, arg2, ...)

作为调用

ข้อความ:

PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

บล็อก:

PROCEDURE procName parameter1, parameter2,... block of statements

的一种方式,它接受零个或多个实参;arg1 被赋值给 parameter1,arg2 被赋值给 parameter2,以此类推。

  • AAP-3.A.6 考试参考表提供了过程

    ข้อความ:

    DISPLAY(expression)

    บล็อก:

    DISPLAY expression

用于显示 expression 的值,后跟一个空格。

  • AAP-3.A.7 考试参考表提供了

    ข้อความ:

    RETURN(expression)

    บล็อก:

    RETURN expression

语句,该语句用于将控制流返回到过程被调用的位置,并返回 expression 的值。

  • AAP-3.A.8 考试参考表提供了

    result ← procName(arg1, arg2, ...)

用于将“过程的值”赋值给 result,该值是通过调用

ข้อความ:

PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

บล็อก:

PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

  • AAP-3.A.9 ใบข้อสอบให้ขั้นตอน

    ข้อความ:

    INPUT()

    บล็อก:

    INPUT

    ซึ่งรับค่าจากผู้ใช้งานและคืนค่าที่รับเข้ามา

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A procedure (function) 过程 is a named, reusable block of code. Calling it runs its code with the arguments you supply, and it may return a value:

Procedures let you use code without knowing its inner workings – procedural abstraction 过程抽象.

ไทย

Procedure (ฟังก์ชัน) คือบล็อกโค้ดที่มีชื่อและนำไปใช้ซ้ำได้ การเรียกใช้งาน จะรันโค้ดนั้นด้วย อาร์กิวเมนต์ ที่คุณส่งไป และอาจ คืนค่า ได้:

sum ← Add(3, 4)      // call, passing 3 and 4

Procedures ทำให้คุณสามารถใช้โค้ดโดยไม่ต้องรู้รายละเอียดภายใน – ซึ่งเรียกว่า การนามธรรมแบบ procedure (procedural abstraction).

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
procedure (function)/prəˈsiːdʒə/ กระบวนการ (ฟังก์ชัน)
procedural abstraction/prəˈsiːdʒərəl əbˈstrækʃn/ procedural abstraction
3.13

Developing Procedures · ⁨การพัฒนา Procedures⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-3): Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Learning Objective AAP-3.B: Explain how the use of procedural abstraction manages complexity in a program. [Skill 3.C]

  • AAP-3.B.1 One common type of abstraction is procedural abstraction, which provides a name for a process and allows a procedure to be used only knowing what it does, not how it does it.
  • AAP-3.B.2 Procedural abstraction allows a solution to a large problem to be based on the solutions of smaller subproblems. This is accomplished by creating procedures to solve each of the subproblems.
  • AAP-3.B.3 The subdivision of a computer program into separate subprograms is called modularity.
  • AAP-3.B.4 A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for program code reuse, which helps manage complexity.
  • AAP-3.B.5 Using parameters allows procedures to be generalized, enabling the procedures to be reused with a range of input values or arguments.
  • AAP-3.B.6 Using procedural abstraction helps improve code readability.
  • AAP-3.B.7 Using procedural abstraction in a program allows programmers to change the internals of the procedure (to make it faster, more efficient, use less storage, etc.) without needing to notify users of the change as long as what the procedure does is preserved.

Learning Objective AAP-3.C: Develop procedural abstractions to manage complexity in a program by writing procedures. [Skill 3.B]

  • AAP-3.C.1 The exam reference sheet provides

    Text:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

    Block:

    PROCEDURE procName parameter1, parameter2,... block of statements

    which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements.

  • AAP-3.C.2 The exam reference sheet provides

    Text:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

    Block:

    PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

    which is used to define a procedure that takes zero or more arguments. The procedure contains block of statements and returns the value of expression. The RETURN statement may appear at any point inside the procedure and causes an immediate return from the procedure back to the calling statement.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-3): นักพัฒนาโปรแกรมแยกปัญหาออกเป็นส่วนย่อยๆ ที่จัดการได้ง่ายขึ้น通过将创建过程和利用参数,开发者可以概括出可重复使用的流程。过程允许开发者调用已经测试过的现有代码,从而能够更快速、更有信心地编写程序。

จุดประสงค์การเรียนรู้ AAP-3.B: อธิบายว่าการใช้ procedural abstraction ช่วยจัดการความซับซ้อนในโปรแกรมได้อย่างไร [Skill 3.C]

  • AAP-3.B.1 รูปแบบหนึ่งของ abstraction ที่พบบ่อยคือ procedural abstraction ซึ่งให้ชื่อแก่กระบวนการและอนุญาตให้ใช้ procedure โดยรู้เพียงว่าทำอะไร แต่ไม่ต้องรู้ว่าทำอย่างไร
  • AAP-3.B.2 Procedural abstraction ช่วยในการแก้ปัญหาขนาดใหญ่โดยอาศัยการแก้ปัญหาย่อยๆ ที่เล็กกว่า ซึ่งทำได้โดยการสร้าง procedures เพื่อแก้ปัญหาย่อยแต่ละส่วน
  • AAP-3.B.3 การแบ่งโปรแกรมคอมพิวเตอร์ออกเป็น subprograms แยกต่างหากเรียกว่า modularity (ความเป็นโมดูลาร์)
  • AAP-3.B.4 Procedural abstraction อาจดึงคุณสมบัติร่วมกันออกมาเพื่อทำให้ฟังก์ชัน性工作เป็นทั่วไปแทนที่จะทำซ้ำโค้ด ซึ่งช่วยให้สามารถนำโค้ดโปรแกรมกลับมาใช้ใหม่ได้ และช่วยจัดการความซับซ้อน
  • AAP-3.B.5 การใช้ parameters ช่วยทำให้ procedures เป็นทั่วไปขึ้น ทำให้สามารถนำ程序和กลับมาใช้ใหม่กับชุดค่า input หรือ arguments ต่างๆ ได้
  • AAP-3.B.6 การใช้ procedural abstraction ช่วยปรับปรุงความอ่านง่ายของโค้ด
  • AAP-3.B.7 การใช้ procedural abstraction ในโปรแกรมช่วยให้นักเขียนโปรแกรมสามารถเปลี่ยนรายละเอียดภายในของ procedure (เช่น ให้เร็วขึ้น มีประสิทธิภาพมากขึ้น ใช้พื้นที่จัดเก็บน้อยลง ฯลฯ) โดยไม่ต้องแจ้งให้ผู้ใช้งานทราบ ตราบใดที่สิ่งที่ procedure ทำนั้นยังคงเดิมอยู่

จุดประสงค์การเรียนรู้ AAP-3.C: พัฒนา procedural abstractions เพื่อจัดการความซับซ้อนในโปรแกรมโดยการเขียน procedures [Skill 3.B]

  • AAP-3.C.1 ใบสรุปข้อสอบให้ข้อมูลถึง

    ข้อความ:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> }

    บล็อก:

    PROCEDURE procName parameter1, parameter2,... block of statements

    ซึ่งใช้สำหรับการกำหนดขั้นตอนการทำงานที่รับพารามิเตอร์ได้ตั้งแต่ศูนย์หรือมากกว่า ขั้นตอนการ tersebutประกอบด้วย block of statements

  • AAP-3.C.2 ใบสรุปข้อสอบให้ข้อมูลถึง

    ข้อความ:

    PROCEDURE procName(parameter1, parameter2, ...) { <block of statements> RETURN(expression) }

    บล็อก:

    PROCEDURE procName parameter1, parameter2,... block of statements RETURN expression

ซึ่งใช้สำหรับกำหนดนิยามของ procedure ที่รับอาร์กิวเมนต์ศูนย์หรือมากกว่า Procedure นั้นประกอบด้วย block of statements และส่งกลับค่าของ expression คำสั่ง RETURN สามารถปรากฏได้ทุกจุดภายใน procedure และจะทำให้เกิด immediate return จาก procedure กลับไปยังคำสั่งที่เรียกใช้

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

You define a procedure with a name, parameters (inputs), and a body, and optionally RETURN a result:

Writing your own procedures reduces repetition, breaks a big problem into named pieces, and makes programs readable and easier to test – the essence of abstraction 抽象.

ไทย

คุณ นิยาม procedure ด้วยชื่อ, พารามิเตอร์ (อินพุต), และบอดี้ พร้อมตัวเลือกว่า RETURN จะคืนผลลัพธ์หรือไม่:

Decomposing a program into procedures and sub-procedures
Decomposing a program into procedures and sub-procedures
PROCEDURE Add(a, b)
{
    RETURN(a + b)
}

การเขียน程序的ของคุณเองช่วยลดความซ้ำซ้อน แยกปัญหาใหญ่ออกเป็นชิ้นที่มีชื่อ และทำให้โปรแกรมอ่านง่ายและทดสอบได้ง่ายขึ้น – ซึ่งเป็นแก่นแท้ของ การนามธรรม (abstraction)

3.14

Libraries · ⁨เลปเบรารี⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-3): Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Learning Objective AAP-3.D: Select appropriate libraries or existing code segments to use in creating new programs. [Skill 2.B]

  • AAP-3.D.1 A software library contains procedures that may be used in creating new programs.
  • AAP-3.D.2 Existing code segments can come from internal or external sources, such as libraries or previously written code.
  • AAP-3.D.3 The use of libraries simplifies the task of creating complex programs.
  • AAP-3.D.4 Application program interfaces (APIs) are specifications for how the procedures in a library behave and can be used.
  • AAP-3.D.5 Documentation for an API/library is necessary in understanding the behaviors provided by the API/library and how to use them.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-3): นักพัฒนาโปรแกรมแยกปัญหาออกเป็นส่วนย่อยๆ ที่จัดการได้ง่ายขึ้น通过将创建过程和利用参数,开发者可以概括出可重复使用的流程。过程允许开发者调用已经测试过的现有代码,从而能够更快速、更有信心地编写程序。

วัตถุประสงค์การเรียนรู้ AAP-3.D: เลือกใช้คลังไลบรารีหรือส่วนโค้ดที่มีอยู่เพื่อสร้างโปรแกรมใหม่ [ทักษะ 2.B]

  • AAP-3.D.1 คลังซอฟต์แวร์ประกอบด้วยขั้นตอนการทำงานที่สามารถนำไปใช้ในการสร้างโปรแกรมใหม่ได้
  • AAP-3.D.2 ส่วนโค้ดที่มีอยู่อาจมาจากแหล่งภายในหรือภายนอก เช่น คลังไลบรารีหรือโค้ดที่เขียนไว้ก่อนหน้า
  • AAP-3.D.3 การใช้คลังไลบรือช่วยให้งานการสร้างโปรแกรมที่ซับซ้อนมีง่ายขึ้น
  • AAP-3.D.4 อินเตอร์เฟซสำหรับแอปพลิเคชัน (APIs) คือข้อกำหนดเกี่ยวกับพฤติกรรมและการใช้งานขั้นตอนการทำงานในคลังไลบรารี
  • AAP-3.D.5 เอกสารประกอบสำหรับ API/library จำเป็นต่อการทำความเข้าใจพฤติกรรมที่ API/library มอบ以及如何ใช้งาน

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A library 库 is a collection of ready-made procedures that others can reuse. An API (Application Program Interface) 应用程序接口 documents what each procedure does, its parameters, and its result – so you can use it without seeing its code. Libraries save time and let you build on existing, tested work.

The documentation is part of the library. Documentation for an API or library is necessary in order to understand the behaviours it provides and how to use them — what each procedure expects as parameters, what it returns, and what it does at the edges. Without it you would have to read the source, which defeats the point of abstraction; with it you can use a procedure correctly without knowing how it works inside.

ไทย

เลปเบรารี คือชุดของ procedures พร้อมใช้ที่其他人สามารถนำไปใช้ซ้ำได้ API (Application Program Interface) เป็นเอกสารที่อธิบายว่าแต่ละ procedure ทำงานอย่างไร มีพารามิเตอร์อะไร และคืนค่าอะไร – เพื่อให้คุณใช้งานได้โดยไม่ต้องเห็นโค้ดของมัน เลปเบรารีช่วยประหยัดเวลาและให้คุณสร้างบนงานที่พร้อมใช้และผ่านการทดสอบแล้ว

เอกสาร部分是เลปเบรารี的一部分。 เอกสารสำหรับ API หรือเลปเบรารีเป็น สิ่งจำเป็น เพื่อเข้าใจพฤติกรรมที่มันมอบ以及如何ใช้งาน – ว่าแต่ละ procedure คาดหวังพารามิเตอร์อะไร Return อะไร และทำอะไรที่ขอบเขตต่างๆ หากไม่มีเอกสาร คุณจะต้องอ่านซอร์สโค้ดซึ่งขัดแย้งกับจุดประสงค์ของการนามธรรม; แต่หากมีเอกสาร คุณสามารถใช้程序的ได้อย่างถูกต้องโดยไม่จำเป็นต้องรู้วิธีทำงานภายใน

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
Interface/ˈɪntəfeɪs/ อินเตอร์เฟซ
3.15

Random Values · ⁨ค่าสุ่ม⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-3): Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Learning Objective AAP-3.E: For generating random values: a. Write expressions to generate possible values. [Skill 2.B] b. Evaluate expressions to determine the possible results. [Skill 4.B]

  • AAP-3.E.1 The exam reference sheet provides

    Text:

    RANDOM(a, b)

    Block:

    RANDOM a, b

    which generates and returns a random integer from a to b, inclusive. Each result is equally likely to occur. For example, RANDOM(1, 3) could return 1, 2, or 3.

  • AAP-3.E.2 Using random number generation in a program means each execution may produce a different result.

ไทย

ความเข้าใจที่ยั่งยืน (AAP-3): นักพัฒนาโปรแกรมแยกปัญหาออกเป็นส่วนย่อยๆ ที่จัดการได้ง่ายขึ้น通过将创建过程和利用参数,开发者可以概括出可重复使用的流程。过程允许开发者调用已经测试过的现有代码,从而能够更快速、更有信心地编写程序。

วัตถุประสงค์การเรียนรู้ AAP-3.E: สำหรับการสร้างค่าสุ่ม: ก. เขียนนิพจน์เพื่อสร้างค่าที่เป็นไปได้ [ทักษะ 2.B] ข. ประเมินผลนิพจน์เพื่อบอกผลลัพธ์ที่เป็นไปได้ [ทักษะ 4.B]

  • AAP-3.E.1 ใบสรุปข้อสอบให้ข้อมูลถึง

    ข้อความ:

    RANDOM(a, b)

    บล็อก:

    RANDOM a, b

    ซึ่งสร้างและส่งกลับจำนวนเต็มแบบสุ่มตั้งแต่ a ถึง b รวมถึงขอบเขตทั้งสองด้าน ผลลัพธ์แต่ละตัวมีโอกาสเกิดขึ้นเท่ากัน ตัวอย่างเช่น การเรียกใช้ RANDOM(1, 3) อาจส่งกลับค่า 1, 2 หรือ 3

  • AAP-3.E.2 การใช้การสร้างตัวเลขสุ่มในโปรแกรมหมายความว่าแต่ละครั้งที่รันอาจได้ผลลัพธ์ที่แตกต่างกัน

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

RANDOM(a, b) returns a random integer from a to b (inclusive), letting a program produce unpredictable results – for games, sampling, or simulations. Each call may give a different value, so a program using randomness behaves differently each run.

ไทย

RANDOM(a, b) คืนค่าจำนวนเต็มสุ่มจาก a ถึง b (รวมทั้งสอง邊), ทำให้โปรแกรมสร้างผลลัพธ์ที่ คาดเดาไม่ได้ – สำหรับเกม, การสุ่มตัวอย่าง, หรือการจำลอง แต่ละครั้งอาจให้ค่าต่างกัน ดังนั้นโปรแกรมที่ใช้ความสุ่มจึง behavesattachment กันทุกครั้งที่รัน

3.16

Simulations · ⁨การจำลอง (Simulations)⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-3): Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing them to write programs more quickly and with more confidence.

Learning Objective AAP-3.F: For simulations: a. Explain how computers can be used to represent real-world phenomena or outcomes. [Skill 1.A] b. Compare simulations with real-world contexts. [Skill 1.D]

  • AAP-3.F.1 Simulations are abstractions of more complex objects or phenomena for a specific purpose.
  • AAP-3.F.2 A simulation is a representation that uses varying sets of values to reflect the changing state of a phenomenon.
  • AAP-3.F.3 Simulations often mimic real-world events with the purpose of drawing inferences, allowing investigation of a phenomenon without the constraints of the real world.
  • AAP-3.F.4 The process of developing an abstract simulation involves removing specific details or simplifying functionality.
  • AAP-3.F.5 Simulations can contain bias derived from the choices of real-world elements that were included or excluded.
  • AAP-3.F.6 Simulations are most useful when real-world events are impractical for experiments (e.g., too big, too small, too fast, too slow, too expensive, or too dangerous).
  • AAP-3.F.7 Simulations facilitate the formulation and refinement of hypotheses related to the objects or phenomena under consideration.
  • AAP-3.F.8 Random number generators can be used to simulate the variability that exists in the real world.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-3): นักพัฒนาโปรแกรมแยกปัญหาออกเป็นส่วนย่อยๆ ที่จัดการได้ง่ายขึ้น通过将创建过程和利用参数,开发者可以概括出可重复使用的流程。过程允许开发者调用已经测试过的现有代码,从而能够更快速、更有信心地编写程序。

วัตถุประสงค์การเรียนรู้ AAP-3.F: สำหรับการจำลอง: ก. อธิบายวิธีที่คอมพิวเตอร์สามารถใช้เพื่อแสดงปรากฏการณ์หรือผลลัพธ์ในโลกจริง [ทักษะ 1.A] a. 解释计算机如何用于表示现实世界的现象或结果。[技能 1.A]

  • AAP-3.F.1 การจำลองเป็นแบบจำลองที่ลดทอนจากวัตถุหรือปรากฏการณ์ที่ซับซ้อนขึ้นเพื่อวัตถุประสงค์เฉพาะ
  • AAP-3.F.2 การจำลอง คือการนำเสนอที่ใช้ชุดค่าต่างๆ เพื่อสะท้อนสถานะที่เปลี่ยนแปลงไปของปรากฏการณ์หนึ่ง
  • AAP-3.F.3 การจำลองมักเลียนแบบเหตุการณ์ในโลกจริงเพื่อวัตถุประสงค์ในการสรุปผล ซึ่งช่วยให้สามารถตรวจสอบปรากฏการณ์นั้นได้โดยไม่ถูกจำกัดโดยความเป็นจริง
  • AAP-3.F.4 กระบวนการสร้างการจำลองแบบลดทอนจะเกี่ยวข้องกับการกำจัดรายละเอียดเฉพาะออก หรือทำให้ฟังก์ชันการทำงานง่ายขึ้น
  • AAP-3.F.5 การจำลองอาจมีอคติซึ่งเกิดจากการเลือกองค์ประกอบในโลกจริงที่ถูกนำเข้ามาหรือตัดออกไป
  • AAP-3.F.6 การจำลองจะมีประโยชน์มากที่สุดเมื่อเหตุการณ์ในโลกจริงไม่เหมาะสมสำหรับการทดลอง (เช่น ใหญ่เกินไป เล็กเกินไป เร็วเกินไป ช้าเกินไป mahal เกินไป หรืออันตรายเกินไป)
  • AAP-3.F.7 การจำลองช่วยในการกำหนดและปรับปรุงสมมติฐานที่เกี่ยวข้องกับวัตถุหรือปรากฏการณ์ที่กำลังพิจารณา
  • AAP-3.F.8 เครื่องสร้างตัวเลขสุ่มสามารถใช้จำลองความแปรปรวนที่มีอยู่ในโลกจริงได้

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

A simulation 模拟 is a program that models a real-world process to study it safely and cheaply. Simulations simplify reality (they leave out detail) and often use randomness to imitate chance events. They let you test scenarios that would be too costly, slow, or dangerous in real life – but their results are only as good as their assumptions.

A simulation is a way of doing science, not just a picture. Because it can be run many times, cheaply and with one variable changed at a time, a simulation facilitates the formulation and refinement of hypotheses about the object or phenomenon under consideration: you propose an explanation, run the model, compare the result with reality, and adjust either the hypothesis or the model. That is why a simulation's simplifications matter — a result only supports a hypothesis about the real world to the extent that what was left out does not matter.

ไทย

การจำลอง คือโปรแกรมที่จำลองกระบวนการในโลกจริงเพื่อศึกษาอย่างปลอดภัยและประหยัด-costy Simulations ลดทอน ความจริง (โดยละรายละเอียดออก) และมักใช้ ความสุ่ม เพื่อเลียนเหตุการณ์บังเอิญ พวกมันช่วยให้คุณทดสอบสถานการณ์ที่จะ expensive, ช้า, หรืออันตรายเกินไปในชีวิตจริง – แต่ผลลัพธ์ของพวกมันดีเท่ากับความสมมติฐานของมันเท่านั้น

การจำลองเป็นวิธีการทำวิทยาศาสตร์ ไม่ใช่แค่ภาพ เพราะสามารถรันได้หลายครั้ง ประหยัด และเปลี่ยนตัวแปรได้ทีละตัว การจำลองจึง ส่งเสริมการสร้างและปรับปรุงสมมติฐาน เกี่ยวกับวัตถุหรือปรากฏการณ์ที่กำลังพิจารณา: คุณเสนอคำอธิบาย, รันโมเดล, เปรียบเทียบผลลัพธ์กับความเป็นจริง, และปรับทั้งสมมติฐานหรือโมเดล นั่นคือเหตุผลที่การลดทอนของการจำลองสำคัญ – ผลลัพธ์จะสนับสนุนสมมติฐานเกี่ยวกับโลกจริงได้ก็ต่อเท่าที่สิ่งที่ถูกทิ้งไปนั้นไม่สำคัญ

Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
simulation/ˌsɪmjʊˈleɪʃn/ การจำลอง
Efficiency/ɪˈfɪʃənsi/ ประสิทธิภาพ
3.17

Algorithmic Efficiency · ⁨ประสิทธิภาพของอัลกอริทึม⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-4): There exist problems that computers cannot solve, and even when a computer can solve a problem, it may not be able to do so in a reasonable amount of time.

Learning Objective AAP-4.A: For determining the efficiency of an algorithm: a. Explain the difference between algorithms that run in reasonable time and those that do not. [Skill 1.D] b. Identify situations where a heuristic solution may be more appropriate. [Skill 1.D]

  • AAP-4.A.1 A problem is a general description of a task that can (or cannot) be solved algorithmically. An instance of a problem also includes specific input. For example, sorting is a problem; sorting the list (2,3,1,7) is an instance of the problem.
  • AAP-4.A.2 A decision problem is a problem with a yes/no answer (e.g., is there a path from A to B?). An optimization problem is a problem with the goal of finding the "best" solution among many (e.g., what is the shortest path from A to B?).
  • AAP-4.A.3 Efficiency is an estimation of the amount of computational resources used by an algorithm. Efficiency is typically expressed as a function of the size of the input.
    • Exclusion statement (EK AAP-4.A.3): Formal analysis of algorithms (Big-O) and formal reasoning using mathematical formulas are outside the scope of this course and the AP Exam.
  • AAP-4.A.4 An algorithm's efficiency is determined through formal or mathematical reasoning.
  • AAP-4.A.5 An algorithm's efficiency can be informally measured by determining the number of times a statement or group of statements executes.
  • AAP-4.A.6 Different correct algorithms for the same problem can have different efficiencies.
  • AAP-4.A.7 Algorithms with a polynomial efficiency or slower (constant, linear, square, cube, etc.) are said to run in a reasonable amount of time. Algorithms with exponential or factorial efficiencies are examples of algorithms that run in an unreasonable amount of time.
  • AAP-4.A.8 Some problems cannot be solved in a reasonable amount of time because there is no efficient algorithm for solving them. In these cases, approximate solutions are sought.
  • AAP-4.A.9 A heuristic is an approach to a problem that produces a solution that is not guaranteed to be optimal but may be used when techniques that are guaranteed to always find an optimal solution are impractical.
    • Exclusion statement (AAP-4.A.9): Specific heuristic solutions are outside the scope of this course and the AP Exam.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-4): มีปัญหาบางประเภทที่คอมพิวเตอร์ไม่สามารถแก้ได้ และแม้ว่าคอมพิวเตอร์จะแก้ปัญหาได้ ก็อาจไม่สามารถทำเช่นนั้นได้ในระยะเวลาที่เหมาะสม

จุดประสงค์การเรียนรู้ AAP-4.A: ในการประเมินประสิทธิภาพของอัลกอริทึม: ก. อธิบายความแตกต่างระหว่างอัลกอริทึมที่ทำงานในระยะเวลาที่เหมาะสมและ那些ที่ไม่สามารถทำได้ [ทักษะ 1.D] ข. ระบุสถานการณ์ที่การหาคำตอบด้วยวิธีเชิงลึกลับอาจเหมาะสมกว่า [ทักษะ 1.D]

  • AAP-4.A.1 ปัญหา คือคำอธิบายทั่วไปของงานที่สามารถ (หรือไม่สามารถ) แก้ไขได้ด้วยอัลกอริทึม ตัวอย่าง ของปัญหายังรวมถึงอินพุตเฉพาะด้วย ตัวอย่างเช่น การจัดลำดับคือปัญหา; การจัดลำดับรายการ (2,3,1,7) เป็นตัวอย่างของปัญหานี้
  • AAP-4.A.2 ปัญหาวินิจฉัย คือปัญหาที่มีคำตอบใช่/ไม่ใช่ (เช่น มีเส้นทางจาก A ไป B หรือไม่?) ปัญหาการเพิ่มประสิทธิภาพ คือปัญหาที่มีเป้าหมายในการหา "ทางออกที่ดีที่สุด" จากหลายทางเลือก (เช่น เส้นทางสั้นที่สุดจาก A ไป B คืออะไร?)
  • AAP-4.A.3 ประสิทธิภาพ เป็นการประมาณปริมาณทรัพยากรการคำนวณที่อัลกอริทึมใช้ ประสิทธิภาพมักแสดงเป็นฟังก์ชันของขนาดของอินพุต
    • ข้อควรระวัง (EK AAP-4.A.3): การวิเคราะห์อัลกอริทึมอย่างเป็นทางการ (Big-O) และการให้เหตุผลทางการใช้สูตรคณิตศาสตร์อยู่นอกขอบเขตของรายวิชานี้และข้อสอบ AP
  • AAP-4.A.4 ประสิทธิภาพของอัลกอริทึมถูกกำหนดผ่านการให้เหตุผลอย่างเป็นทางการหรือทางคณิตศาสตร์
  • AAP-4.A.5 ประสิทธิภาพของอัลกอริทึมสามารถวัดแบบไม่ทางการได้โดยการนับจำนวนครั้งที่คำสั่งหรือกลุ่มคำสั่ง被执行
  • AAP-4.A.6 อัลกอริทึมที่ถูกต้องที่แตกต่างกันสำหรับปัญหาเดียวกันอาจมีประสิทธิภาพแตกต่างกัน
  • AAP-4.A.7 อัลกอริทึมที่มีประสิทธิภาพเป็นพหุนามหรือช้ากว่านั้น (คงที่, เชิงเส้น, สี่เหลี่ยม, ลูกบาศก์ เป็นต้น)被认为是在“合理时间内”运行的。具有指数或阶乘效率的算法是“不合理时间”内运行算法的例子。
  • AAP-4.A.8 บางปัญหาไม่สามารถแก้ไขได้ในระยะเวลาที่เหมาะสมเนื่องจากไม่มีอัลกอริทึมที่มีประสิทธิภาพในการแก้ปัญหานั้น ในกรณีเหล่านี้จะมองหาทางออกโดยประมาณ
  • AAP-4.A.9 วิธีเชิงลึกลับ คือแนวทางในการแก้ปัญหาที่สร้างทางออกซึ่งไม่รับประกันว่าจะดีที่สุด แต่อาจใช้ในกรณีที่เป็นเทคนิคที่รับประกันการหาคำตอบที่ดีที่สุดไม่เหมาะสม
    • ข้อควรระวัง (AAP-4.A.9): วิธีเชิงลึกลับเฉพาะอยู่นอกขอบเขตของรายวิชานี้และข้อสอบ AP

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Efficiency 效率 is how much time (or memory) an algorithm needs as its input grows. A reasonable-time algorithm's work grows like a polynomial of the input size (e.g. linear or quadratic); an unreasonable-time algorithm grows far faster (e.g. doubling with each added item), becoming impractical for large inputs. A faster algorithm can make a previously impossible problem solvable. Sometimes an exact answer takes too long, so a heuristic 启发式 – an approach that finds a good-enough answer quickly – is used instead.

ไทย

ประสิทธิภาพ คือปริมาณเวลา (หรือหน่วยความจำ) ที่อัลกอริทึมต้องใช้เมื่อข้อมูลเข้ามีขนาดใหญ่ขึ้น อัลกอริทึมที่ ใช้เวลามั่นใจได้ จะมีจำนวนงานเพิ่มขึ้นตามฟังก์ชันพหุนามของขนาดข้อมูลเข้า (เช่น แบบเส้นตรงหรือแบบกำลังสอง) ส่วนอัลกอริทึมที่ ใช้เวลานานเกินควร จะเพิ่มขึ้นเร็วมาก (เช่น เพิ่มเป็นสองเท่าเมื่อเพิ่มข้อมูลเข้าหนึ่งรายการ) จนไม่สามารถใช้งานได้ในข้อมูลเข้าที่มีขนาดใหญ่ อัลกอริทึมที่เร็วขึ้นสามารถทำให้ปัญหาที่เคยแก้ไม่ได้กลายเป็นแก้ได้ บางครั้งการหาคำตอบที่แม่นยำอาจใช้เวลานานเกินไป จึงใช้ heuristics – وهوวิธีการหาคำตอบที่พอใช้ได้ภายในเวลาอันรวดเร็ว – แทน

วิธีที่เวลาทำงานของอัลกอริทึมเพิ่มขึ้นตามขนาดข้อมูลเข้า n
วิธีที่เวลาทำงานของอัลกอริทึมเพิ่มขึ้นตามขนาดข้อมูลเข้า n
Vocabulary · ⁨คำศัพท์⁩ Train · ⁨ฝึกฝน⁩
English ไทย
heuristic/hjuːˈrɪstɪk/ heuristic
undecidable/ˌʌndɪˈsaɪdəbl/ ไม่สามารถตัดสินใจได้
3.18

Undecidable Problems · ⁨ปัญหาที่ไม่สามารถตัดสินใจได้⁩

Syllabus · ⁨หลักสูตร⁩
English

Enduring Understanding (AAP-4): There exist problems that computers cannot solve, and even when a computer can solve a problem, it may not be able to do so in a reasonable amount of time.

Learning Objective AAP-4.B: Explain the existence of undecidable problems in computer science. [Skill 1.A]

  • AAP-4.B.1 A decidable problem is a decision problem for which an algorithm can be written to produce a correct output for all inputs (e.g., "Is the number even?").
  • AAP-4.B.2 An undecidable problem is one for which no algorithm can be constructed that is always capable of providing a correct yes-or-no answer.
    • Exclusion statement (EK AAP-4.B.2): Determining whether a given problem is undecidable is outside the scope of this course and the AP Exam.
  • AAP-4.B.3 An undecidable problem may have some instances that have an algorithmic solution, but there is no algorithmic solution that could solve all instances of the problem.
ไทย

ความเข้าใจที่ยั่งยืน (AAP-4): มีปัญหาบางประเภทที่คอมพิวเตอร์ไม่สามารถแก้ได้ และแม้ว่าคอมพิวเตอร์จะแก้ปัญหาได้ ก็อาจไม่สามารถทำเช่นนั้นได้ในระยะเวลาที่เหมาะสม

จุดประสงค์การเรียนรู้ AAP-4.B: อธิบายการมีอยู่ของปัญหาที่ตัดสินไม่ได้ในวิทยาการคอมพิวเตอร์ [ทักษะ 1.A]

  • AAP-4.B.1 ปัญหาที่ตัดสินได้ คือปัญหาวินิจฉัยที่เขียนอัลกอริทึมเพื่อสร้างผลลัพธ์ที่ถูกต้องสำหรับอินพุตทั้งหมดได้ (เช่น "เลขนี้คู่หรือไม่?")
  • AAP-4.B.2 ปัญหาที่ตัดสินไม่ได้ คือปัญหาที่สร้างอัลกอริทึม nàoก็ตามไม่สามารถให้คำตอบใช่/ไม่ใช่ที่ถูกต้องเสมอได้
    • ข้อควรระวัง (EK AAP-4.B.2): การตัดสินว่าปัญหาระดับใดเป็นปัญหาที่ตัดสินได้นั้นอยู่นอกขอบเขตของรายวิชานี้และข้อสอบ AP
  • AAP-4.B.3 ปัญหาที่ตัดสินไม่ได้อาจมีบางตัวอย่างที่มีทางออกด้วยอัลกอริทึม แต่ไม่มีอัลกอริทึมใดที่จะสามารถแก้ได้ทุกตัวอย่างของปัญหานี้

Source: College Board AP Course and Exam Description · ⁨แหล่งที่มา: คำอธิบายหลักสูตรและข้อสอบ College Board AP⁩

English

Some problems are undecidable 不可判定: no algorithm can solve every case of them with a correct yes/no answer. This is a fundamental limit of computing – not a matter of needing a faster computer, but a proof that no such algorithm can exist.

Exam skill: be able to determine a code segment's result by tracing it, compare two algorithms' efficiency (reasonable vs unreasonable time), and recognize procedural and data abstraction in a program.

ไทย

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

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

3.18

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

English
  • Know a variable is a named store for a value and trace how assignment updates it step by step.
  • Read the AP pseudocode carefully — a <- expression assigns, and lists are 1-indexed on the exam reference sheet.
  • Distinguish a variable from a list (a collection accessed by index) and use list operations correctly.
  • Evaluate expressions with the right precedence and boolean logic (AND, OR, NOT).
  • Pick clear, meaningful variable names — the written tasks reward readable code.
ไทย
  • รู้ว่าตัวแปรคือพื้นที่จัดเก็บที่มีชื่อสำหรับค่าหนึ่ง และการติดตาม如何通过 การกำหนดค่า เพื่ออัปเดตค่า它以ขั้นตอนทีละขั้น
  • อ่าน AP 伪代码 อย่างละเอียด — a <- expression มีการกำหนดค่า, และลิสต์มีการเริ่มต้นจาก 1 ในกระดาษอ้างอิงการสอบ
  • แยกแยะระหว่างตัวแปรกับ ลิสต์ (กลุ่มข้อมูลที่เข้าถึงผ่านดัชนี) และใช้ktionลิสต์ให้ถูกต้อง
  • ประเมินนิพจน์โดยคำนึงถึงลำดับความสำคัญที่ถูกต้องและตรรกะ boolean (AND, OR, NOT)
  • เลือกชื่อบอกตัวแปรที่ชัดเจนและมีนัยสำคัญ – งานเขียนจะเน้นการอ่านโค้ดได้ง่าย

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

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

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

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

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

IGCSE, A-Level & AP