Notations, stepwise refinement and logic · Notaciones, refinamiento paso a paso y lógica
| English | Español |
|---|---|
| notation/nəʊˈteɪʃn/ | notación |
| structured English/ˈstrʌktʃəd ˈɪŋɡlɪʃ/ | inglés estructurado |
| pseudocode/ˈsuːdəʊkəʊd/ | pseudocódigo |
| flowchart/ˈfləʊtʃɑːt/ | diagrama de flujo |
| stepwise refinement/ˈstepwaɪz rɪˈfaɪnmənt/ | refinamiento paso a paso |
| logic statement/ˈlɒdʒɪk ˈsteɪtmənt/ | declaración lógica |
| Boolean/ˈbuːlɪən/ | Boolean |
| precedence/ˈpresɪdəns/ | precedencia |
| De Morgan's law/də ˈmɔːɡənz lɔː/ | ley de De Morgan |
The first algorithm had no language to be written in
- In 1843 Ada Lovelace published the steps for computing Bernoulli numbers on Babbage's Analytical Engine, a machine that was never built.
- There was no programming language, so she wrote the algorithm as a numbered table of operations: a notation 记法 of her own.
- Every algorithm still starts that way. You write it down in some notation, check it, and only then turn it into code.
- This lesson is about the three notations the exam uses, how to move between them, and how to write the conditions inside them.
El primer algoritmo no tenía un lenguaje en el que escribirlo
- En 1843, Ada Lovelace publicó los pasos para calcular los números de Bernoulli en la Máquina Analítica de Babbage, una máquina que nunca se construyó.
- No existía ningún lenguaje de programación, así que escribió el algoritmo como una tabla numerada de operaciones: una notación 记法 propia.
- Cada algoritmo comienza así. Lo escribes en alguna notación, lo revisas y solo después lo conviertes en código.
- Esta lección trata sobre las tres notaciones que utiliza el examen, cómo transitar entre ellas y cómo escribir las condiciones dentro de ellas.
Three notations
- Structured English 结构化英语: ordinary sentences, indented, with a few fixed words such as
IF,FOR EACH,REPEAT. Good for a first outline. - Pseudocode 伪代码: the keyword notation (
IF … ENDIF,WHILE … ENDWHILE,FOR … NEXT), closest to real code and marked against Cambridge's guide. - Flowchart 流程图: a diagram of standard shapes. Rounded rectangle for
START/STOP, parallelogram for input and output, rectangle for a process, diamond for a decision, arrows for the flow.
A flowchart for averaging a list of numbers, drawn with the standard shapes
Tres notaciones
- Inglés estructurado 结构化英语: oraciones comunes, con sangría, y algunas palabras fijas como
IF,FOR EACH,REPEAT. Bueno para un primer borrador. - Pseudocódigo 伪代码: la notación de palabras clave (
IF … ENDIF,WHILE … ENDWHILE,FOR … NEXT), más cercana al código real y evaluada según la guía de Cambridge. - Diagrama de flujo 流程图: un diagrama de formas estándar. Rectángulo redondeado para
START/STOP, paralelogramo para entrada y salida, rectángulo para un proceso, rombo para una decisión, flechas para el flujo.

Un diagrama de flujo para promediar una lista de números, dibujado con las formas estándar
In a flowchart, which shape represents a decision? · En un diagrama de flujo, ¿qué forma representa una decisión?
A diamond is a decision; rounded rectangle = start/stop, parallelogram = input/output, rectangle = process. · Un rombo es una decisión; rectángulo redondeado = inicio/fin, paralelogramo = entrada/salida, rectángulo = proceso.
Match each flowchart shape to its meaning. · Empareja cada forma del diagrama de flujo con su significado.
Parallelogram = I/O, rectangle = process, rounded rectangle = start/stop, diamond = decision. · Paralelogramo = E/S, rectángulo = proceso, rectángulo redondeado = inicio/fin, rombo = decisión.
Match each notation to its description. · Empareja cada notación con su descripción.
All three describe the same algorithm at different distances from the code. · Las tres describen el mismo algoritmo a diferentes distancias del código.
Worked example: structured English to pseudocode
- Structured English: Set the total to zero. For each of the N numbers, add it to the total. Divide the total by N and output the result.
- Each sentence becomes one construct: an assignment, a
FORloop with an assignment inside it, then an assignment and an output.
- The order of the sentences is the order of the statements. Nothing is added and nothing is left out.
Ejemplo resuelto: inglés estructurado a pseudocódigo
- Inglés estructurado: Establecer el total en cero. Para cada uno de los N números, sumarlo al total. Dividir el total por N y mostrar el resultado.
- Cada oración se convierte en una construcción: una asignación, un bucle
FORcon una asignación dentro, luego una asignación y una salida.
Total <- 0
FOR Index <- 1 TO N
Total <- Total + Number[Index]
NEXT Index
Average <- Total / N
OUTPUT Average
- El orden de las oraciones es el orden de las sentencias. No se añade nada ni se omite nada.
In the averaging algorithm, the FOR loop that adds each number to the total is an example of the ____ construct. · En el algoritmo de promedio, el bucle FOR que suma cada número al total es un ejemplo de la construcción de ____.
Repeating a block for each number is iteration. The assignment inside it stores the running total. · Repetir un bloque para cada número es iteración. La asignación dentro de él almacena el total acumulado.
Worked example: pseudocode to flowchart
- Take the same algorithm.
STARTgoes in a rounded rectangle,Total ← 0andIndex ← 1in rectangles. - The
FORloop becomes a diamond askingIndex <= N?. The Yes exit leads to the rectangleTotal ← Total + Number[Index], thenIndex ← Index + 1, and an arrow back up to the diamond. - The No exit continues to
Average ← Total / N, an output parallelogram, andSTOP. - Label both exits of every diamond. A diamond with one unlabelled exit is not a decision.
Ejemplo resuelto: pseudocódigo a diagrama de flujo
- Toma el mismo algoritmo.
STARTva en un rectángulo redondeado,Total ← 0eIndex ← 1en rectángulos. - El bucle
FORse convierte en un rombo que preguntaIndex <= N?. La salida Sí lleva al rectánguloTotal ← Total + Number[Index], luegoIndex ← Index + 1, y una flecha hacia arriba de vuelta al rombo. - La salida No continúa a
Average ← Total / N, un paralelogramo de salida, ySTOP. - Etiqueta ambas salidas de cada rombo. Un rombo con una sola salida sin etiquetar no es una decisión.
Stepwise refinement
- Stepwise refinement 逐步求精 means writing an algorithm as a short outline, then expanding each step into more detailed sub-steps, and repeating until every step can be coded directly.
- Each level keeps the structure of the level above and adds detail. The outline is not thrown away: it becomes the structure of the program.
- The design stops when a step is one line of pseudocode or one module you already have.
Stepwise refinement expands each step until it can be coded
Refinamiento progresivo
- Refinamiento progresivo 逐步求精 significa escribir un algoritmo como un breve esquema, luego expandir cada paso en subpasos más detallados, y repetir hasta que cada paso pueda programarse directamente.
- Cada nivel mantiene la estructura del nivel superior y añade detalles. El esquema no se descarta: se convierte en la estructura del programa.
- El diseño termina cuando un paso equivale a una línea de pseudocódigo o a un módulo que ya tienes.

El refinamiento progresivo expande cada paso hasta que puede codificarse
Stepwise refinement is the technique of: · El refinamiento paso a paso es la técnica de:
You refine a high-level outline level by level, adding detail while keeping the structure. · Refinas un esquema de alto nivel nivel por nivel, añadiendo detalle mientras mantienes la estructura.
Worked example: three levels
- Level 1: Process the exam results.
- Level 2: Input each mark. Calculate the mean. Count how many passed. Output the report.
- Level 3, refining "count how many passed":
Passes ← 0, thenFOReach mark,IF Mark >= 40 THEN Passes ← Passes + 1. - Asked to "describe stepwise refinement", give the three ideas: start from an outline, expand each step into smaller steps, stop when each step can be programmed.
Ejemplo resuelto: tres niveles
- Nivel 1: Procesar los resultados del examen.
- Nivel 2: Entrar cada nota. Calcular la media. Contar cuántos aprobaron. Mostrar el informe.
- Nivel 3, refinando "contar cuántos aprobaron":
Passes ← 0, luegoFORcada nota,IF Mark >= 40 THEN Passes ← Passes + 1. - Al pedirte que "describas el refinamiento progresivo", da las tres ideas: empezar desde un esquema, expandir cada paso en pasos más pequeños, detenerse cuando cada paso pueda programarse.
Stepwise refinement: outline to code · Refinamiento paso a paso: de esquema a código
Step down the levels. You start with the whole task in one line and keep expanding each step into smaller ones — until every step is simple enough to code directly. · Descender los niveles. Comienza con toda la tarea en una sola línea y sigue expandiendo cada paso en pasos más pequeños — hasta que cada paso sea lo suficientemente simple para codificarse directamente.
In stepwise refinement, each new level replaces the level above it, so the original outline is thrown away. · En el refinamiento paso a paso, cada nuevo nivel reemplaza al nivel superior, por lo que el esquema original se desecha.
Each level keeps the structure of the one above and adds detail. The outline becomes the shape of the finished program. · Cada nivel conserva la estructura del anterior y añade detalles. El esquema se convierte en la forma del programa terminado.
Logic statements
- A logic statement 逻辑语句 is a Boolean 布尔 condition: it is either
TRUEorFALSE, and it controls anIF, aWHILEor anUNTIL. - It is built from comparisons (
=,<>,<,>,<=,>=) joined byAND,ORandNOT. Mark >= 0 AND Mark <= 100is true only for marks in range.Age < 12 OR Age >= 65is true for children and pensioners.
Comparisons joined by AND, OR and NOT make one condition
Sentencias lógicas
- Una sentencia lógica 逻辑语句 es una condición Booleana 布尔: es
TRUE(verdadero) oFALSE(falso), y controla unIF, unWHILEo unUNTIL. - Se construye a partir de comparaciones (
=,<>,<,>,<=,>=) unidas porAND,ORyNOT. Mark >= 0 AND Mark <= 100es verdadero solo para notas en rango.Age < 12 OR Age >= 65es verdadero para niños y jubilados.

Las comparaciones unidas por AND, OR y NOT forman una condición
Precedence and brackets
- Operators are applied in a fixed order of precedence 优先级:
NOTfirst, thenAND, thenOR. - So
A OR B AND CmeansA OR (B AND C), not(A OR B) AND C. WithA = TRUE,B = FALSE,C = FALSEthe first isTRUEand the second isFALSE. - Use brackets whenever a condition mixes
ANDandOR. They cost nothing and remove the ambiguity.
Precedencia y paréntesis
- Los operadores se aplican en un orden de precedencia 优先级 fijo:
NOTprimero, luegoAND, luegoOR. - Por lo tanto,
A OR B AND CsignificaA OR (B AND C), no(A OR B) AND C. ConA = TRUE,B = FALSE,C = FALSE, el primero esTRUEy el segundo esFALSE. - Usa paréntesis siempre que una condición mezcle
ANDyOR. No tienen costo y eliminan la ambigüedad.
Put the logic operators in order of precedence, highest (evaluated first) to lowest. · Ordena los operadores lógicos según su precedencia, de mayor (se evalúa primero) a menor.
NOT binds tightest, then AND, then OR — use brackets when in doubt. · NOT tiene mayor jerarquía, seguido de AND, luego OR — usa paréntesis si tienes dudas.
With no brackets, what does A OR B AND C mean? · Sin paréntesis, ¿qué significa A OR B AND C?
AND has higher precedence than OR, so it is evaluated first. Bracket the condition anyway, so nobody has to remember. · AND tiene mayor precedencia que OR, por lo que se evalúa primero. Pon paréntesis a la condición de todos modos, para que nadie tenga que recordarlo.
De Morgan's laws
- De Morgan's law 德摩根定律:
NOT (A AND B)is the same as(NOT A) OR (NOT B), andNOT (A OR B)is the same as(NOT A) AND (NOT B). - In words: "not (registered and paid)" means "not registered, or not paid".
- Use it to simplify a condition, or to check one: pick values for
AandB, work out both sides, and they must agree in every case.
Leyes de De Morgan
- Ley de De Morgan 德摩根定律:
NOT (A AND B)es lo mismo que(NOT A) OR (NOT B), yNOT (A OR B)es lo mismo que(NOT A) AND (NOT B). - En palabras: "no (registrado y pagado)" significa "no registrado, o no pagado".
- Úsalo para simplificar una condición, o para verificarla: elige valores para
AyB, calcula ambos lados, y deben coincidir en todos los casos.
By De Morgan's law, NOT (A AND B) is the same as (NOT A) OR (NOT B). · Por la ley de De Morgan, NOT (A AND B) es lo mismo que (NOT A) OR (NOT B).
NOT distributes over the bracket and flips AND↔OR; likewise NOT (A OR B) = (NOT A) AND (NOT B). · NOT se distribuye sobre los paréntesis e invierte AND↔OR; asimismo NOT (A OR B) = (NOT A) AND (NOT B).
Worked example: a condition from words
- Rule: a student may sit the exam if they are registered and have either paid or hold a bursary, but not if they are suspended.
- Name the Boolean variables:
Registered,Paid,Bursary,Suspended. - Statement:
Registered AND (Paid OR Bursary) AND NOT Suspended. - The brackets around
Paid OR Bursaryare essential. Without them,ANDbinds first and a student with a bursary but no registration would get in.
Ejemplo resuelto: una condición de palabras
- Regla: un estudiante puede presentar el examen si está registrado y tieneeither pagado o beca, pero no si está suspendido.
- Nombra las variables Booleanas:
Registered,Paid,Bursary,Suspended. - Sentencia:
Registered AND (Paid OR Bursary) AND NOT Suspended. - Los paréntesis alrededor de
Paid OR Bursaryson esenciales. Sin ellos,ANDse une primero y un estudiante con beca pero sin registro podría entrar.
Which conditions are equivalent to NOT (Registered AND Paid)? Select all · todos that apply. · ¿Cuáles condiciones son equivalentes a NOT (Registered AND Paid)? Selecciona todas las que correspondan.
De Morgan turns NOT of an AND into an OR of the NOTs. The AND version is too strict: a student who is registered but has not paid should make the original condition TRUE, and it makes the AND version FALSE. · De Morgan transforma NOT de un AND en un OR de los NOTs. La versión AND es demasiado estricta: un estudiante que esté registrado pero no haya pagado debería hacer que la condición original sea VERDADERA, y hace que la versión AND sea FALSA.
Marks that slip away
a = 1 OR 2is not a condition. Writea = 1 OR a = 2: each side ofORmust be a complete comparison.NOTapplies only to what follows it.NOT A AND Bmeans(NOT A) AND B.- A diamond needs two labelled exits, and a loop needs an arrow that goes back up. A flowchart with no arrow returning is not a loop.
- Structured English is still precise. "Deal with the marks" is not a step; "add the mark to the total" is.
Puntos que se pierden fácilmente
a = 1 OR 2no es una condición. Escribea = 1 OR a = 2: cada lado deORdebe ser una comparación completa.NOTaplica solo a lo que le sigue.NOT A AND Bsignifica(NOT A) AND B.- Un rombo necesita dos salidas etiquetadas, y un bucle necesita una flecha que regrese hacia arriba. Un diagrama de flujo sin flecha de retorno no es un bucle.
- El inglés estructurado sigue siendo preciso. "Manejar las notas" no es un paso; "sumar la nota al total" sí lo es.
To test whether a is 1 or 2, the correct condition is: · Para probar si a es 1 o 2, la condición correcta es:
Each side of OR must be a full comparison: a = 1 OR a = 2. Writing a = 1 OR 2 is a common error. · Cada lado de OR debe ser una comparación completa: a = 1 OR a = 2. Escribir a = 1 OR 2 es un error común.
You've got it
- three notations for one algorithm: structured English, pseudocode, flowchart (diamond = decision, back-arrow = loop)
- stepwise refinement: outline → expand each step → stop when a step can be coded
- a logic statement is a Boolean condition; precedence NOT → AND → OR, so bracket anything that mixes them
- De Morgan:
NOT (A AND B)=NOT A OR NOT B;NOT (A OR B)=NOT A AND NOT B
Ya lo tienes
- tres notaciones para un algoritmo: inglés estructurado, pseudocódigo, diagrama de flujo (rombo = decisión, flecha de retorno = bucle)
- refinamiento progresivo: esquema → expandir cada paso → detenerse cuando un paso pueda codificarse
- una sentencia lógica es una condición Booleana; precedencia NOT → AND → OR, así que pon paréntesis a todo lo que los mezcle
- De Morgan:
NOT (A AND B)=NOT A OR NOT B;NOT (A OR B)=NOT A AND NOT B