Chapitre 10
Du 20 April 2026 au 24 April 2026
Lecture : 20 minQuiz de 16 questions
# Du 20 April 2026 au 24 April 2026
## UA10 : Exécution des algorithmes
### Introduction
Welcome to Unit 10! In this lesson, we will explore one of the most fundamental aspects of computer science: the execution of algorithms. An algorithm is essentially a set of step-by-step instructions designed to solve a problem or accomplish a task. Understanding how algorithms are executed is crucial for anyone who wants to create, debug, or even just understand computer programs. We will learn how to manually trace an algorithm's flow, understand what happens at each step, and predict its final outcome.
### Key Concepts
#### What is Algorithm Execution?
Algorithm execution is the process of carrying out, or running, the steps defined in an algorithm to achieve a specific result. It's how a computer (or a person, if done manually) follows the instructions to transform inputs into outputs.
* **Input:** The data or information that an algorithm needs to start its process. Without input, many algorithms cannot begin or produce meaningful results.
* **Processing:** This is the core of execution, where each instruction in the algorithm is followed in sequence. This can involve calculations, comparisons, assignments, and repetitions.
* **Output:** The final result or information produced by the algorithm after processing the input.
#### Steps in Algorithm Execution
An algorithm proceeds through a series of defined steps. These steps involve:
* **Reading Inputs:** Getting the necessary data from the user or another source.
* **Performing Operations:** This includes:
* **Arithmetic Operations:** Addition \( + \), Subtraction \( - \), Multiplication \( * \), Division \( / \).
* **Comparison Operations:** Checking if one value is less than \( < \), greater than \( > \), equal to \( = \), not equal to \( \neq \), less than or equal to \( \le \), or greater than or equal to \( \ge \) another value.
* **Logical Operations:** Combining conditions using AND, OR, NOT.
* **Assignment Operations:** Storing a value in a variable (e.g., `x = 10`).
* **Making Decisions:** Using conditional statements (like `IF-THEN-ELSE`) to choose different paths based on whether a condition is true or false.
* **Repeating Actions:** Using loops (like `FOR` or `WHILE`) to repeat a block of instructions multiple times.
* **Producing Outputs:** Displaying or storing the final results.
#### Tracing Algorithms (Manual Execution)
Tracing an algorithm means manually going through each step of the algorithm with specific input values, recording the state of all variables, and noting any output. This is a powerful technique for:
* Understanding exactly how an algorithm works.
* Identifying errors (bugs) in an algorithm's logic.
* Predicting the output for any given input.
To trace an algorithm, you typically use a **trace table** (also known as a dry run table). This table has columns for each variable and a column for the output. You update the values in the table as you move through each instruction.
### Vocabulary
* **Algorithm:** A finite set of well-defined, step-by-step instructions to solve a problem or perform a computation.
* **Execution:** The process of carrying out the instructions of an algorithm or computer program.
* **Input:** Data provided to an algorithm to be processed.
* **Output:** The result or information generated by an algorithm after processing its input.
* **Variable:** A named storage location in an algorithm that holds a value, which can change during execution.
* **Trace Table:** A table used to track the values of variables and outputs step-by-step during the manual execution of an algorithm.
* **Conditional Statement (Selection):** An instruction (e.g., IF-THEN-ELSE) that allows an algorithm to make decisions and execute different blocks of code based on whether a condition is true or false.
* **Loop (Iteration):** A control structure (e.g., FOR, WHILE) that allows a block of code to be repeated a specific number of times or until a certain condition is met.
### Examples
#### Example 1: Sum of Two Numbers
**Algorithm:**
1. START
2. INPUT `num1`
3. INPUT `num2`
4. `sum` = `num1` + `num2`
5. PRINT `sum`
6. END
**Trace Table (Input: `num1 = 10`, `num2 = 15`):**
| Step | `num1` | `num2` | `sum` | Output |
|------|--------|--------|-------|--------|
| 2 | 10 | - | - | - |
| 3 | 10 | 15 | - | - |
| 4 | 10 | 15 | 25 | - |
| 5 | 10 | 15 | 25 | 25 |
#### Example 2: Check if a Number is Positive
**Algorithm:**
1. START
2. INPUT `number`
3. IF `number` > 0 THEN
4. PRINT "The number is positive."
5. ELSE
6. PRINT "The number is not positive."
7. END IF
8. END
**Trace Table (Input: `number = 7`):**
| Step | `number` | Condition (`number` > 0) | Output |
|------|----------|--------------------------|------------------------------|
| 2 | 7 | - | - |
| 3 | 7 | True | - |
| 4 | 7 | - | "The number is positive." |
| 8 | 7 | - | - |
**Trace Table (Input: `number = -3`):**
| Step | `number` | Condition (`number` > 0) | Output |
|------|----------|--------------------------|------------------------------|
| 2 | -3 | - | - |
| 3 | -3 | False | - |
| 6 | -3 | - | "The number is not positive."|
| 8 | -3 | - | - |
#### Example 3: Sum of Numbers from 1 to 3
**Algorithm:**
1. START
2. `total` = 0
3. FOR `i` FROM 1 TO 3 DO
4. `total` = `total` + `i`
5. END FOR
6. PRINT `total`
7. END
**Trace Table (Input implicitly `N=3` for the loop):**
| Step | `i` | `total` | Output |
|------|-----|---------|--------|
| 2 | - | 0 | - |
| 3 | 1 | 0 | - |
| 4 | 1 | 1 | - |
| 3 | 2 | 1 | - |
| 4 | 2 | 3 | - |
| 3 | 3 | 3 | - |
| 4 | 3 | 6 | - |
| 3 | 4 | 6 | - |
| 6 | - | 6 | 6 |
### Exercises
1. **Sequential Execution:** What is the output of the following algorithm if `X = 5`?
1. START
2. `Y` = `X` + 2
3. `Z` = `Y` * 3
4. `X` = `Z` - `Y`
5. PRINT `X`
6. END
2. **Conditional Execution:** Trace the following algorithm for `age = 16` and `age = 20`. What is the output for each case?
1. START
2. INPUT `age`
3. IF `age` >= 18 THEN
4. PRINT "You are eligible to vote."
5. ELSE
6. PRINT "You are not yet eligible to vote."
7. END IF
8. END
3. **Loop Execution:** Trace the following algorithm. What will be the final value printed?
1. START
2. `count` = 0
3. WHILE `count` < 5 DO
4. PRINT `count`
5. `count` = `count` + 1
6. END WHILE
7. END
### Assignment
1. **Algorithm Design & Trace:** Write an algorithm to find the area of a rectangle. It should take `length` and `width` as inputs. Then, create a trace table for your algorithm with `length = 8` and `width = 5`.
2. **Debugging with Tracing:** An algorithm is supposed to find the average of three numbers. Identify the error and show how tracing helps find it.
1. START
2. INPUT `a`, `b`, `c`
3. `sum` = `a` + `b`
4. `average` = `sum` + `c` / 3
5. PRINT `average`
6. END
(Trace with `a=10, b=20, c=30`)
3. **Complex Trace:** Create a trace table for the following algorithm. What is the final output?
1. START
2. `num` = 10
3. `result` = 1
4. WHILE `num` > 0 DO
5. IF `num` MOD 2 = 0 THEN
6. `result` = `result` * 2
7. ELSE
8. `result` = `result` + 1
9. END IF
10. `num` = `num` - 1
11. END WHILE
12. PRINT `result`
13. END
### Summary
In this lesson, we've learned that executing an algorithm means following its instructions step-by-step to process inputs and produce outputs. We explored the core components of execution, including sequential steps, conditional decisions, and repetitive loops. The essential skill of tracing algorithms using a trace table was introduced as a powerful tool to understand, debug, and predict the behavior of any algorithm. Mastering algorithm execution is a fundamental skill that underpins all programming and problem-solving in computer science.
## Du 27 April 2026 au 01 Mai 2026
### Introduction
Welcome, Form Four students! This week, we will dive into the fundamental concepts of Computer Science, building a strong foundation for understanding how computers work and how we can instruct them. We will explore key components of computer systems, how data is represented, and the very basics of programming logic. This knowledge is essential for anyone looking to understand the digital world around us.
### Key Concepts
#### 1. Data Representation
Computers process information in a specific way. Unlike humans who use various languages and numbers, computers primarily understand only two states: on or off. This is represented using the binary system.
##### The Binary System
* **Bits**: The smallest unit of data in a computer is a **bit** (binary digit), which can be either 0 or 1.
* **Bytes**: A group of 8 bits forms a **byte**. A byte is typically the smallest addressable unit of data in memory and can represent a single character (like a letter or number).
* **Number Systems**: We will look at how decimal (base-10) numbers are converted to binary (base-2) and vice-versa. We'll also briefly touch on hexadecimal (base-16) as it's often used in computing as a shorthand for binary.
* Binary uses digits 0 and 1.
* Decimal uses digits 0-9.
* Hexadecimal uses digits 0-9 and letters A-F.
#### 2. Computer Hardware
Hardware refers to the physical components of a computer system that you can touch and see.
##### Main Components:
* **Central Processing Unit (CPU)**: Often called the 'brain' of the computer, the CPU executes instructions, performs calculations, and manages the flow of information.
* **Random Access Memory (RAM)**: This is temporary storage where the computer keeps data and programs it is currently using. RAM is volatile, meaning its contents are lost when the computer is turned off.
* **Read-Only Memory (ROM)**: Stores permanent instructions needed for the computer to boot up (start). ROM is non-volatile.
* **Storage Devices**: Devices like Hard Disk Drives (HDDs) and Solid State Drives (SSDs) store data permanently, even when the computer is off.
* **Input Devices**: Allow users to enter data into the computer (e.g., keyboard, mouse, microphone).
* **Output Devices**: Display or present information from the computer to the user (e.g., monitor, printer, speakers).
#### 3. Computer Software
Software refers to the set of instructions or programs that tell the hardware what to do.
##### Types of Software:
* **System Software**: Manages and controls the computer hardware and provides a platform for application software to run. The most important system software is the **Operating System (OS)** (e.g., Windows, macOS, Linux, Android).
* **Application Software**: Programs designed to perform specific tasks for users (e.g., word processors, web browsers, games, graphic design software).
#### 4. Introduction to Programming Concepts
Programming is the process of writing instructions that a computer can understand and execute to perform a specific task.
##### Core Concepts:
* **Algorithm**: A step-by-step procedure or set of rules to solve a specific problem or complete a task. Algorithms must be finite, unambiguous, and effective.
* **Flowchart**: A diagrammatic representation of an algorithm, using standard symbols to depict steps, decisions, and flow.
* **Pseudocode**: A high-level, informal description of an algorithm that is closer to human language than a programming language, but more structured than plain English.
* **Variables**: Named storage locations in memory used to hold data that can change during the execution of a program.
* **Data Types**: Classifications of data that tell the computer how the data should be interpreted and what operations can be performed on it (e.g., integers, floating-point numbers, characters, booleans).
* **Basic Control Structures**: These dictate the order in which instructions are executed:
* **Sequence**: Instructions are executed one after another in the order they appear.
* **Selection (Conditional)**: Instructions are executed only if a certain condition is met (e.g., `IF...THEN...ELSE`).
* **Iteration (Loop)**: A set of instructions is repeated multiple times until a certain condition is met (e.g., `FOR` loop, `WHILE` loop).
### Vocabulary
* **Bit**: A binary digit, the smallest unit of data (0 or 1).
* **Byte**: A group of 8 bits.
* **CPU (Central Processing Unit)**: The 'brain' of the computer that executes instructions.
* **RAM (Random Access Memory)**: Volatile temporary storage for active data and programs.
* **ROM (Read-Only Memory)**: Non-volatile memory storing boot-up instructions.
* **Operating System (OS)**: System software that manages computer hardware and software resources.
* **Algorithm**: A step-by-step procedure to solve a problem.
* **Flowchart**: A diagrammatic representation of an algorithm.
* **Pseudocode**: An informal, high-level description of an algorithm.
* **Variable**: A named storage location for data that can change.
* **Data Type**: Classification of data (e.g., integer, string).
* **Binary**: A base-2 number system using 0s and 1s.
* **Decimal**: A base-10 number system using digits 0-9.
* **Hexadecimal**: A base-16 number system using 0-9 and A-F.
### Examples
#### 1. Binary to Decimal Conversion
To convert binary \(1011_2\) to decimal:
\[ 1 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 \]
\[ 1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1 \]
\[ 8 + 0 + 2 + 1 = 11_{10} \]
So, \(1011_2 = 11_{10}\).
#### 2. Simple Algorithm: Calculate the Area of a Rectangle
##### Pseudocode:
```pseudocode
START
INPUT Length
INPUT Width
CALCULATE Area = Length * Width
OUTPUT Area
END
```
##### Flowchart (conceptual steps):
1. START (Oval)
2. INPUT Length (Parallelogram)
3. INPUT Width (Parallelogram)
4. Area = Length * Width (Rectangle)
5. OUTPUT Area (Parallelogram)
6. END (Oval)
#### 3. Programming Logic - Selection (IF Statement)
Imagine you want to check if a student passed an exam (pass mark is 50).
##### Pseudocode:
```pseudocode
IF Score >= 50 THEN
PRINT "Pass"
ELSE
PRINT "Fail"
END IF
```
### Exercises
1. **Data Representation**: Convert the following:
a. Binary \(1101_2\) to Decimal.
b. Decimal \(25_{10}\) to Binary.
2. **Hardware Identification**: List two input devices and two output devices.
3. **Software Classification**: Categorize the following as System Software or Application Software:
a. Microsoft Word
b. Windows 11
c. Google Chrome
d. Android OS
4. **Algorithms**: Write a simple algorithm in pseudocode to calculate the average of three numbers.
### Assignment
1. **Research**: Choose one computer hardware component (e.g., Graphics Card, Motherboard) and write a short paragraph (5-7 sentences) explaining its function and importance to the computer system.
2. **Algorithm Design**: Design an algorithm (using either pseudocode or a flowchart) for the following task: "Check if a user-entered number is even or odd."
3. **Vocabulary Review**: Define the following terms in your own words:
* Bit
* Byte
* CPU
* Operating System
* Algorithm
### Summary
This week, we've explored the foundational elements of Computer Science. We started with understanding how data is represented in binary, which is the computer's native language. We then identified the essential hardware components that make up a computer system and distinguished between system and application software. Finally, we introduced the core concepts of programming, including algorithms, variables, data types, and basic control structures like sequence, selection, and iteration. These concepts are crucial building blocks for your journey into the exciting world of computing!
## Du 04 Mai 2026 au 08 Mai 2026
### Introduction
Welcome to our lesson on **Introduction to Programming Concepts**! Over the next week (May 04 - May 08, 2026), we will explore the fundamental ideas behind computer programming. Programming is like giving a set of instructions to a computer to perform specific tasks. Understanding these basic concepts is crucial for anyone interested in creating software, apps, or even understanding how technology works around us. By the end of this week, you will have a solid grasp of what programming is, how computers understand instructions, and some basic building blocks used in almost all programming languages.
### Key Concepts
#### What is a Program?
A program is a set of step-by-step instructions that tells a computer exactly what to do. Computers are machines that can only follow instructions; they cannot think for themselves. Therefore, these instructions must be very precise and unambiguous.
* **Instructions:** These are commands given to the computer to perform actions like adding numbers, displaying text, or storing data.
* **Algorithm:** Before writing a program, we first create an algorithm, which is a detailed plan or a step-by-step procedure to solve a problem.
#### Programming Languages
Computers don't understand human languages directly. They understand machine code, which is a series of binary digits (0s and 1s). Programming languages act as a bridge between human instructions and machine code.
* **Low-Level Languages:** These are very close to machine code and are difficult for humans to write and read (e.g., Assembly language).
* **High-Level Languages:** These are closer to human language, making them easier to write, read, and understand. They need a translator (compiler or interpreter) to convert them into machine code (e.g., Python, Java, C++, JavaScript).
#### Basic Programming Constructs
All programming languages use a set of basic constructs to build programs.
##### 1. Variables and Data Types
* **Variable:** A variable is a named storage location in a computer's memory that holds a value. Think of it like a container with a label.
* **Declaration:** Giving a variable a name.
* **Assignment:** Giving a variable a value.
* **Data Types:** The type of value a variable can hold. Common data types include:
* **Integer (int):** Whole numbers (e.g., 5, -10, 0).
* **Float (float):** Numbers with decimal points (e.g., 3.14, -0.5).
* **String (str):** Text, enclosed in quotes (e.g., "Hello World", "Computer").
* **Boolean (bool):** Represents truth values, either `True` or `False`.
##### 2. Operators
Operators are special symbols used to perform operations on values and variables.
* **Arithmetic Operators:** For mathematical calculations.
* `+` (addition), `-` (subtraction), `*` (multiplication), `/` (division), `%` (modulus - remainder of division).
* **Comparison Operators:** For comparing two values, resulting in a Boolean `True` or `False`.
* `==` (equal to), `!=` (not equal to), `<` (less than), `>` (greater than), `<=` (less than or equal to), `>=` (greater than or equal to).
* **Logical Operators:** Used to combine or modify Boolean expressions.
* `AND`, `OR`, `NOT`.
##### 3. Input and Output
* **Input:** Getting data from the user or an external source (e.g., keyboard input).
* **Output:** Displaying results or information to the user (e.g., printing to the screen).
##### 4. Control Structures
These determine the order in which instructions are executed.
* **Sequential Flow:** Instructions are executed one after another, in the order they appear.
* **Selection (Conditional Statements):** Allows a program to make decisions and execute different blocks of code based on whether a condition is true or false.
* `IF...THEN...ELSE` statements are common.
* **Iteration (Loops):** Allows a program to repeat a block of instructions multiple times.
* **`FOR` loop:** Repeats a specific number of times or for each item in a sequence.
* **`WHILE` loop:** Repeats as long as a certain condition remains true.
### Vocabulary
* **Algorithm:** A step-by-step procedure for solving a problem or achieving a goal.
* **Program:** A set of instructions that a computer can execute to perform a task.
* **Programming Language:** A formal language comprising a set of instructions used to produce various kinds of output.
* **Variable:** A named storage location that holds a value, which can change during program execution.
* **Data Type:** A classification of data that tells the computer what kind of value a variable holds (e.g., integer, string).
* **Operator:** A symbol or keyword that performs an operation on one or more values or variables.
* **Conditional Statement:** A programming construct that allows different code to be executed based on whether a condition is true or false.
* **Loop:** A control structure that repeatedly executes a block of code as long as a certain condition is met or for a specified number of times.
* **Input:** Data received by a program from an external source (e.g., user keyboard).
* **Output:** Data sent from a program to an external destination (e.g., screen display).
### Examples
Here are some examples in a simplified programming syntax (like Python):
#### Example 1: Variables and Arithmetic
```python
# Declare and assign variables
num1 = 10
num2 = 5.5
name = "Alice"
# Perform arithmetic operation
sum_result = num1 + num2
# Print results
print("First number:", num1)
print("Second number:", num2)
print("Sum:", sum_result)
print("Hello,", name)
```
**Output:**
```
First number: 10
Second number: 5.5
Sum: 15.5
Hello, Alice
```
#### Example 2: Input and Output
```python
# Get input from the user
user_name = input("Enter your name: ")
user_age = int(input("Enter your age: ")) # Convert input to an integer
# Print a personalized message
print("Hello,", user_name + "! You are", user_age, "years old.")
```
**Example Interaction:**
```
Enter your name: Bob
Enter your age: 15
Hello, Bob! You are 15 years old.
```
#### Example 3: Conditional Statement (`IF-ELSE`)
```python
score = 75
if score >= 60:
print("You passed the exam!")
else:
print("You did not pass the exam. Try again!")
```
**Output:**
```
You passed the exam!
```
#### Example 4: `FOR` Loop
```python
# Print numbers from 1 to 5
for i in range(1, 6): # range(start, stop) generates numbers up to stop-1
print(i)
```
**Output:**
```
1
2
3
4
5
```
### Exercises
1. What is the main purpose of a programming language?
2. Define what a variable is and provide an example of an integer variable and a string variable.
3. Identify the data type for each of the following values:
* `"Mathematics"`
* `100`
* `True`
* `98.6`
4. Write down the output of the following pseudocode:
```
grade = 85
if grade > 90:
print("Excellent")
elif grade > 80:
print("Very Good")
else:
print("Good")
```
5. How many times will the following loop print "Hello"?
```
count = 0
while count < 3:
print("Hello")
count = count + 1
```
### Assignment
1. **Write a simple algorithm (in steps, not code) to calculate the average of three numbers.** Your algorithm should include steps for taking input, performing the calculation, and displaying the output.
2. **Think of a real-world scenario where you would use an `IF-ELSE` statement.** For example, deciding if a student passes or fails based on their score. Describe the scenario and the condition that would be checked.
3. **Research and list two different high-level programming languages other than Python and Java.** For each, briefly explain one unique feature or common use case.
### Summary
This week, we've laid the groundwork for understanding computer programming. We learned that programs are precise sets of instructions, and programming languages bridge the gap between human ideas and machine actions. We explored fundamental building blocks like variables to store data, different data types, and operators to manipulate them. Crucially, we introduced control structures: sequential flow, conditional statements (`IF-ELSE`) for decision-making, and loops (`FOR`, `WHILE`) for repetition. These concepts are the bedrock of all software development, enabling computers to perform complex tasks by following simple, logical steps.
Quiz du chapitre
16 questions — vérifie chaque réponse pour voir l'explication.