Skip to content · ⁨الانتقال إلى المحتوى⁩

Algorithms and Programming · ⁨الخوارزميات والبرمجة⁩

AP Computer Science Principles · ⁨AP مبادئ علوم الحاسوب⁩ · 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 المتغير هو تجريد داخل برنامج يمكنه احتواء قيمة. كل متغير له مساحة تخزين بيانات مرتبطة به تمثل قيمة واحدة في كل مرة، لكن تلك القيمة يمكن أن تكون قائمة أو مجموعة أخرى تحتوي بدورها على قيم متعددة.
  • AAP-1.A.2 استخدام أسماء متغيرات ذات دلالة يساعد في قراءة كود البرنامج وفهم القيم التي تمثلها المتغيرات.
  • AAP-1.A.3 توفر بعض لغات البرمجة أنواعاً لتمثيل البيانات، والتي يتم الاستشهاد بها باستخدام المتغيرات. تشمل هذه الأنواع الأرقام والقيم المنطقية والقوائم والسلاسل النصية.
  • AAP-1.A.4 بعض القيم أكثر ملاءمة للتمثيل باستخدام نوع واحد من البيانات بدلاً من نوع آخر.

هدف التعلم AAP-1.B: تحديد قيمة المتغير كنتيجة لعملية إسناد. [مهارة 4.B]

  • AAP-1.B.1 يسمح مشغل الإسناد للبرنامج بتغيير القيمة التي يمثلها المتغير.

  • 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)
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 يمكن إنشاء تجريدات بيانات باستخدام القوائم.

  • AAP-1.D.4 تطوير تجريد بيانات لتنفيذه في برنامج قد يؤدي إلى برنامج أسهل في التطوير والصيانة.

  • AAP-1.D.5 تحتوي التجريدات البياناتية غالبًا على أنواع مختلفة من العناصر.

  • AAP-1.D.6 يسمح استخدام القوائم بمعاملة عناصر متعددة ذات صلة كقيمة واحدة. تُشار إلى القوائم بأسماء مختلفة، مثل مصفوفة (array)، اعتمادًا على لغة البرمجة المستخدمة.

    • استثناء (EK AAP-1.D.6): استخدام القوائم المترابطة خارج نطاق هذا المقرر وامتحان AP.
  • AAP-1.D.7 توفر ورقة إشارات الامتحان الترميز

    [value1, value2, value3, ...]

    لإنشاء قائمة بتلك القيم كأول عنصر، والثاني، والثالث، وهكذا. على سبيل المثال،

    • النص:

      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.

العربية

تجريد البيانات (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.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
Data abstraction/ˈdeɪtə əbˈstrækʃn/ تجريد البيانات
remainder/rɪˈmeɪndə/ الباقي
list/lɪst/ قائمة
abstraction/əbˈstrækʃn/ التجريد
library/ˈlaɪbrəri/ مكتبة
simulation/ˌsɪmjʊˈleɪʃn/ محاكاة
Efficiency/ɪˈfɪʃənsi/ الكفاءة
heuristic/hjuːˈrɪstɪk/ خوارزمية استدلالية (heuristic)
undecidable/ˌʌndɪˈsaɪdəbl/ غير قابل للحسم
Interface/ˈɪntəfeɪs/ واجهة
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 إلى جانب لغات البرمجة المرئية والنصية، يمكن التعبير عن الخوارزميات بطرق متنوعة، مثل اللغة الطبيعية والمخططات والرمز الوهمي (pseudocode).
  • 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 العوامل الحسابية جزء من معظم لغات البرمجة وتشمل عوامل الجمع والطرح والضرب والقسمة والباقي (modulus).

  • 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 مفيد بشكل خاص لاختبار قابلية القسمة (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 دمج النصوص يربط نصين أو أكثر معًا طرفًا تلو الآخر لتكوين نص جديد.
  • AAP-2.D.2 النص الجزئي هو جزء من نص موجود مسبقًا.

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.

العربية

السلسلة (String) هي تسلسل مرتب من الأحرف، مثل "hello". تربط البرامج السلاسل (الدمج) وتجد طولها. تمثل النصوص – الأسماء والرسائل والتسلسلات – وهي مدخلات ومخرجات شائعة للبرامج.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
string/strɪŋ/ سلسلة نصية
concatenation/kənˌkætəˈneɪʃn/ الدمج (concatenation)
Boolean expression/ˈbuːlɪən ekˈspreʃn/ تعبير بولياني
conditional (selection)/kənˈdɪʃənl/ شرطي (اختيار)
nested conditional/ˈnestɪd kənˈdɪʃənl/ شرط متداخل
Iteration (a loop)/ˌɪtəˈreɪʃn/ التكرار (الحلقة)
infinite loop/ˈɪnfɪnət luːp/ حلقة لا نهائية
algorithm/ˈælɡərɪθəm/ خوارزمية
3.5

Boolean 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.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: بالنسبة للعلاقات بين متغيرين أو تعبيران أو قيمتين: أ. اكتب تعبيرات باستخدام عوامل العلاقة. [مهارة 2.B] ب. قيّم التعبيرات التي تستخدم عوامل العلاقة. [مهارة 4.B]

  • AAP-2.E.1 القيمة المنطقية إما صحيحة (true) أو خاطئة (false).

  • AAP-2.E.2 توفر ورقة إشارات الامتحان عوامل العلاقة التالية: =، ≠، >، <، ≥، و≤.

    النص والكتلة:

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

    تُستخدم لاختبار العلاقة بين متغيرين أو تعبيران أو قيمتين. التقييم باستخدام عامل علاقة ينتج قيمة منطقية. على سبيل المثال، a = b يُحسب ليصبح true إذا كان a وb متساويين؛ وإلا فإنه يُحسب ليصبح false.

الهدف التعليمي AAP-2.F: بالنسبة للعلاقات بين القيم المنطقية: أ. اكتب تعبيرات باستخدام العوامل المنطقية. [مهارة 2.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 المعامل لعملية منطقية هو إما تعبير منطقي أو قيمة منطقية واحدة.

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:

عائلات المعاملات الثلاث: الحسابية، العلائقية، والمنطقية
عائلات المعاملات الثلاث: الحسابية، العلائقية، والمنطقية
  • 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. · ⁨التعبير المنطقي يكون إما صحيحًا (1) أو خاطئًا (0). OR تكون صحيحة عندما يدخل واحد على الأقل تكون صحيحة؛ عكس المدخلات لرؤية كل حالة.⁩

3.6

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.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 الاختيار يحدد أي أجزاء الخوارزمية يتم تنفيذها بناءً على أن يكون شرط ما true أو false.

الهدف التعليمي AAP-2.H: للاختيار: أ. اكتب جمل شرطية. [مهارة 2.B] ب. حدد نتيجة الجمل الشرطية. [مهارة 4.B]

  • AAP-2.H.1 الجمل الشرطية، أو "جمل if"، تؤثر على التدفق التسلسلي للتحكم عن طريق تنفيذ جمل مختلفة بناءً على قيمة تعبير منطقي.

  • AAP-2.H.2 يوفر ورقة مرجع الامتحان

    النص:

    IF(condition) { <block of statements> }

    الكتلة:

    IF condition block of statements

    حيث يتم تنفيذ الكود في block of statements إذا كانت القيمة المنطقية 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 إذا كانت القيمة المنطقية 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 يعطي بديلاً:

الاختيار بين مسارات بناءً على شرط
الاختيار يختار بين المسارات بناءً على شرط
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: للاختيار المتداخل: أ. اكتب جمل شرطية متداخلة. [مهارة 2.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:

العربية

الشرطية المتداخلة تضع IF واحدة داخل أخرى (أو تشابك ELSE IF) للاختيار بين أكثر من اثنين من المسارات. يتم تشغيل الفرع الأول المتطابق فقط:

IF (g ≥ 90)      { grade ← "A" }
ELSE IF (g ≥ 80) { grade ← "B" }
ELSE             { grade ← "C" }
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: للتكرار: أ. اكتب جمل تكرار. [مهارة 2.B] ب. حدد النتيجة أو الأثر الجانبي لجمل التكرار. [مهارة 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) تكرار، يحدث حلقة لا نهائية عندما لن تتحقق أبداً الشرط النهائي لـ true.

  • AAP-2.K.5 في تكرار REPEAT UNTIL(condition)، إذا كانت القيمة الشرطية تساوي true مبدئياً، فلن يتم تنفيذ جسم الحلقة على الإطلاق، بسبب فحص الشرط قبل الحلقة.

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 无限循环.

العربية

التكرار (حلقة تكرار) يعيد التعليمات. الرمز الوهمي لـ AP له شكلان:

حلقة precondition (WHILE) تختبر قبل الجسم، لذا قد لا تعمل مطلقاً
حلقة الشرط المسبق (WHILE) تختبر قبل الجسم، لذا قد تعمل أصفار مرة
REPEAT 5 TIMES        // a fixed count
{
    DISPLAY("hi")
}

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

حلقة لا تلبي أبداً شرط التوقف الخاص بها هي حلقة لا نهائية.

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. · ⁨الحلقة تكرر كتلة بينما عددها يمر عبر نطاق. انتقل خطوة بخطوة لمشاهدة العداد والمجموع الكلي يتحدّثان في كل مرور.⁩

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 يمكن إنشاء الخوارزميات من فكرة، أو بدمج خوارزميات موجودة، أو بتعديل خوارزميات موجودة.
  • 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.

العربية
كود مصدر بايثون على شاشة — الخوارزميات تعليمات دقيقة ومنظمة
كود مصدر بايثون على شاشة — الخوارزميات تعليمات دقيقة ومنظمة

الخوارزمية ليست نفس الكود. إلى جانب لغات البرمجة المرئية والنصية، يمكن التعبير عن الخوارزمية بـ طرق متنوعة: في اللغة الطبيعية (جمل عادية)، أو كـ رسم تخطيطي مثل المخطط الانسيابي، أو باستخدام الكود الوهمي. هذه الأشكال مخصصة للبشر — فهي تسمح لك بفحص المنطق والتوافق عليه قبل اختيار أي لغة، ويمكن بعد ذلك كتابة نفس الخوارزمية بأي لغة.

عند كتابتها بلغة برمجة، الوضوح والقابلية للقراءة اعتبارات مهمة، وليست مجرد زينة: أسماء متغيرات ذات معنى، مسافات بادئة متناسقة، وتعليقات تشرح لماذا بدلاً من ماذا. يجب أن يُقرأ البرنامج ويُعدّل لاحقاً بواسطة شخص آخر — وغالباً أنت — ولا يمكن صيانة خوارزمية لا أحد يتبعها أو إصلاح أخطاءها.

الخوارزمية هي تسلسل محدود من الخطوات يحل مشكلة، مبنية من التسلسل، والاختيار، والتكرار. يمكن لخوارزميات مختلفة حل نفس المشكلة، ويجب أن تكون قادراً على دمج وتعديل الخوارزميات الموجودة (على سبيل المثال، عد القيم في قائمة تحقق من شرط معين، أو ابحث عن الأكبر). تتبع الخوارزمية يدوياً للتحقق من صحتها.

المخطط الانسيابي يعرض خوارزمية باستخدام الرموز القياسية
المخطط الانسيابي يعرض خوارزمية باستخدام الرموز القياسية
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: بالنسبة لعمليات القائمة: أ. اكتب تعبيرات تستخدم فهرسة القوائم وإجراءات القائمة. [مهارة 2.B] ب. قيّم تعبيرات تستخدم فهرسة القوائم وإجراءات القائمة. [مهارة 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 عند الفهارس الأكبر من أو تساوي i. تزداد طول القائمة بمقدار 1، ويوضع value عند الفهرس 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 خوارزميات البحث الخطي أو المتتابع تتحقق من كل عنصر من عناصر القائمة، بالترتيب، حتى يتم العثور على القيمة المطلوبة أو يتم التحقق من جميع العناصر في القائمة.

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:

العربية

القائمة هي مجموعة مرتبة من القيم تحت اسم واحد، وهي التجريد الأساسي للبيانات في المسار. كود بايثون الوهمي للمناهج المتقدمة (AP) يبدأ الفهرسة من 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

تتصفح القائمة بحلقة تكرارية لجمعها، أو عدّها، أو البحث فيها، أو إيجاد قيمتها القصوى:

FOR EACH x IN scores
{
    total ← total + x
}
3.11

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): التنفيذات المحددة للبحث الثنائي خارج نطاق المقرر وامتحان AP.
  • AAP-2.P.2 يجب أن تكون البيانات مرتبة لاستخدام خوارزمية البحث الثنائي.
  • AAP-2.P.3 يكون البحث الثنائي أكثر كفاءة غالباً من البحث المتتابع/الخطي عند تطبيقه على بيانات مرتبة.

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.

العربية
دليل الهاتف: البحث الثنائي ينصف الصفحات المتبقية في كل خطوة
دليل الهاتف: البحث الثنائي ينصف الصفحات المتبقية في كل خطوة

البحث الثنائي يجد قيمة في قائمة مرتبة بسرعة أكبر بكثير من فحص كل عنصر. ينظر إلى العنصر الأوسط، ثم يتجاهل النصف الذي لا يمكن أن يحتوي على الهدف، متكرراً حتى يتم العثور عليه. في كل خطوة ينقص مساحة البحث بنصفها، لذا فإن قائمة تحتوي على $n$ عناصر تستغرق حوالي $\log_2 n$ خطوات. يتطلب الأمر أن تكون البيانات مرتبة مسبقاً.

البحث الثنائي ينصف النطاق في كل خطوة (يجب أن تكون القائمة مُرتبة)
البحث الثنائي ينصف النطاق في كل خطوة (يجب أن تكون القائمة مُرتبة)

مثال محلول. عند البحث في قائمة مرتبة من $8$ عناصر، يقلل البحث الثنائي النطاق إلى النصف في كل خطوة: $8\rightarrow4\rightarrow2\rightarrow1$، بحد أقصى $3$ مقارنات ($\log_2 8=3$)، بينما قد يستغرق البحث الخطي ما يصل إلى $8$. يتزايد الميزة بشكل انفجاري: حوالي $1{,}000$ عناصر تحتاج فقط إلى $\approx10$ خطوات بحث ثنائي (لكن حتى $1{,}000$ خطوات خطية)، و$1{,}000{,}000$ عناصر تحتاج فقط إلى $\approx20$. التقسيم إلى النصف هو ما يجعله خوارزمية ذات وقت معقول.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
Binary search/ˈbaɪnəri sɜːtʃ/ البحث الثنائي
3.12

Calling Procedures · ⁨استدعاء الإجراءات⁩

Syllabus · ⁨المنهج⁩
Enduring UnderstandingLearning ObjectiveEssential Knowledge

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.

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.

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 过程抽象.

العربية

الإجراء (الدالة) هو كتلة من الكود قابلة لإعادة الاستخدام ومُعطاة اسماً. عند استدعاؤها، يتم تنفيذ كدها بالـ الحجج التي تقدمها، وقد ترجع قيمة:

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

تسمح الإجراءات باستخدام الكود دون معرفة تفاصيله الداخلي – وهو ما يسمى بـ التجريد الإجرائي.

3.13

Developing 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: اشرح كيف أن استخدام التجريد الإجرائي يدير التعقيد في البرنامج. [مهارة 3.C]

  • AAP-3.B.1 أحد الأنواع الشائعة للتجريد هو التجريد الإجرائي، والذي يوفر اسماً لعملية ويُمكّن من استخدام إجراء مع معرفة ما يفعله فقط، دون معرفة كيفية قيامه بذلك.
  • AAP-3.B.2 يسمح التجريد الإجرائي ببناء حل لمشكلة كبيرة على حلول مشاكل فرعية أصغر. يتحقق ذلك من خلال إنشاء إجراءات لحل كل مشكلة فرعية.
  • AAP-3.B.3 يُسمى تقسيم برنامج الحاسوب إلى برامج فرعية منفصلة التعددية (modularity).
  • AAP-3.B.4 قد يستخرج التجريد الإجرائي ميزات مشتركة لتعميل الوظيفة بدلاً من تكرار الكود. هذا يسمح بإعادة استخدام كود البرنامج، مما يساعد في إدارة التعقيد.
  • AAP-3.B.5 استخدام المعاملات يسمح بتعميل الإجراءات، مما يمكنها من إعادة الاستخدام مع مجموعة متنوعة من قيم الإدخال أو الحجج.
  • AAP-3.B.6 يساعد التجريد الإجرائي على تحسين قراءة الكود.
  • AAP-3.B.7 استخدام التجريد الإجرائي في برنامج ما يسمح للمبرمجين بتغيير التفاصيل الداخلية للإجراء (لجعله أسرع، أكثر كفاءة، أو يستهلك ذاكرة أقل، إلخ) دون الحاجة إلى إخبار المستخدمين بالتغير طالما أن ما يقوم به الإجراء يبقى كما هو.

هدف التعلم AAP-3.C: تطوير التجريدات الإجرائية لإدارة التعقيد في البرنامج عن طريق كتابة الإجراءات. [المهارة 3.B]

  • AAP-3.C.1 توفر ورقة مرجع الامتحان

    النص:

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

    الكتلة:

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

    والتي تُستخدم لتعريف إجراء يأخذ صفرًا أو أكثر من المعاملات. يحتوي الإجراء على 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

    والتي تُستخدم لتعريف إجراء يأخذ صفرًا أو أكثر من المعاملات. يحتوي الإجراء على block of statements ويعيد قيمة expression. قد يظهر جملة RETURN في أي مكان داخل الإجراء وتسبب إرجاعًا فوريًا من الإجراء إلى جملة الاستدعاء.

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 抽象.

العربية

تُعرّف الإجراء باسم، ومعلمات (مدخلات)، وجسم، وخياراً RETURN النتيجة:

تجزئة برنامج إلى إجراءات وإجراءات فرعية
تجزئة برنامج إلى إجراءات وإجراءات فرعية
PROCEDURE Add(a, b)
{
    RETURN(a + b)
}

كتابة إجراءاتك الخاصة يقلل التكرار، ويحل مشكلة كبيرة إلى أجزاء مُسمَّاة، ويجعل البرامج مقروءة وأسهل في الاختبار – وهو جوهر الـ التجريد.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
procedure (function)/prəˈsiːdʒə/ إجراء (دالة)
procedural abstraction/prəˈsiːdʒərəl əbˈstrækʃn/ التجريد الإجرائي
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/المكتبة ضرورية لفهم السلوكيات التي توفرها API/المكتبة وكيفية استخدامها.

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.

العربية

المكتبة هي مجموعة من الإجراءات الجاهزة التي يمكن للآخرين إعادة استخدامها. واجهة برمجة التطبيقات (API) تُوثّق ما تفعله كل إجراء، ومعلماتها، ونتيجتها – بحيث يمكنك استخدامها دون رؤية كدها. توفر المكتبات الوقت وتتيح لك البناء على عمل موجود ومختبر مسبقاً.

التوثيق جزء من المكتبة. توثيق واجهة برمجة التطبيقات أو المكتبة ضروري لفهم السلوكيات التي توفرها وكيفية استخدامها — بما تتوقعه كل إجراء كمعلمات، وما ترديه، وما تفعله في الحالات الحدية. بدونه ستضطر لقراءة المصدر، مما يُلغي غرض التجريد؛ وبوجوده يمكنك استخدام الإجراء بشكل صحيح دون معرفة كيف يعمل داخلياً.

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 (شاملًا)، مما يسمح للبرنامج بإنتاج نتائج غير متوقعة – للألعاب، أو أخذ العينات، أو المحاكيات. قد تعطي كل استدعاء قيمة مختلفة، لذا فإن البرنامج الذي يستخدم العشوائية يتصرف بشكل مختلف في كل مرة يتم تشغيله فيها.

3.16

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] أ. اشرح كيف يمكن استخدام الحواسيب لتمثيل ظواهر العالم الحقيقي أو نتائجها. [مهارة 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 تكون المحاكيات مفيدة بشكل خاص عندما تكون الأحداث الواقية غير عملية للتجارب (مثل: كبيرة جدًا، صغيرة جدًا، سريعة جدًا، بطيئة جدًا، باهظة الثمن، أو خطيرة).
  • 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.

العربية

المحاكاة هي برنامج يحاكي عملية واقعية لدراستها بأمان وبتكلفة منخفضة. تبسّط المحاكاة الواقع (تستبعد التفاصيل) وغالبًا ما تستخدم العشوائية لمحاكاة الأحداث العشوائية. تتيح لك اختبار سيناريوهات قد تكون مكلفة أو بطيئة أو خطيرة في الحياة الحقيقية – لكن نتائجها لا تفوق جودة افتراضاتها.

المحاكاة طريقة لإجراء العلم، وليست مجرد صورة. لأنها يمكن تشغيلها مراراً وتكراراً، بتكلفة منخفضة changing متغير واحد في كل مرة، فإن المحاكاة تيسّغ صياغة وتحسين الفرضيات حول الشيء أو الظاهرة قيد النظر: تقترح شرحاً، وتشغل النموذج، وتقارن النتيجة بالواقع، وتعدل إما الفرضية أو النموذج. ولهذا السبب تُعد تبسيطات المحاكاة مهمة — فالنتيجة تدعم فرضية حول العالم الحقيقي إلى extent أن ما تم استخراجه ليس له أهمية.

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.

العربية

الكفاءة هي مقدار الوقت (أو الذاكرة) الذي يحتاجه خوارزمية ما كلما زاد حجم مدخلاتها. تعمل خوارزمية وقت معقول بزيادة تتناسب مع كثير حدود من حجم المدخلات (مثل الخطي أو التربيعي)، بينما تزداد خوارزمية وقت غير معقول بسرعة أكبر بكثير (مثل الضعف مع كل عنصر مضاف)، مما يجعلها غير عملية للمدخلات الكبيرة. يمكن أن تجعل الخوارزمية الأسرع مشكلة كانت مستحيلة الحل سابقاً قابلة للحل. أحياناً يأخذ الإجابة الدقيقة وقتاً طويلاً جداً، لذلك يتم استخدام خوارزمية استرشادية – وهي نهج يجد إجابة جيدة بما يكفي بسرعة – بدلاً منها.

كيف يزداد زمن تشغيل الخوارزمية مع حجم المدخلات n
كيف يزداد زمن تشغيل الخوارزمية مع حجم المدخلات n
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 المشكلة غير القابلة للقرار هي مشكلة لا يمكن بناء خوارزمية عليها تكون قادرة دائمًا على تقديم إجابة صحيحة بنعم أو لا.
    • عبارة الاستثناء (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.

العربية

بعض المسائل لا يمكن حلها: لا توجد خوارزمية قادرة على حل كل حالة منها بإجابة صح نعم/لا. هذا حد أساسي في الحوسبة – وليس مسألة الحاجة لحاسوب أسرع، بل هو إثبات عدم وجود مثل هذه الخوارزمية أصلاً.

مهارة الامتحان: القدرة على تحديد نتيجة جزء كود عن طريق تتبعه، ومقارنة كفاءتي خوارزميتين (وقت معقول مقابل غير معقول)، والتعرف على التجريد الإجرائي وبيانات البرمجة في البرنامج.

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 في ورقة المرجع الامتحاني.
  • التمييز بين المتغير والقائمة (مجموعة يتم الوصول إليها بالمؤشر) واستخدام عمليات القائمة بشكل صحيح.
  • تقييم التعبيرات مع أولوية العمليات والمنطق البولياني الصحيح (AND، OR، NOT).
  • اختيار أسماء متغيرات واضحة ومعبرة — حيث تُكافأ المهام الكتابية الكود المقروء.

Interactive lessons on this topic · ⁨دروس تفاعلية حول هذا الموضوع⁩

Work through it step by step, with instant-check exercises. · ⁨ا-working عليه خطوة بخطوة، مع تمارين تحقق فوري.⁩

Past Papers · ⁨أوراق الامتحانات السابقة⁩

More topics in AP Computer Science Principles · ⁨AP مبادئ علوم الحاسوب⁩ · ⁨المزيد من المواضيع في AP Computer Science Principles · ⁨AP مبادئ علوم الحاسوب⁩⁩

Log in or create account · ⁨تسجيل الدخول أو إنشاء حساب⁩

IGCSE, A-Level & AP