Edexcel IGCSE Computer Science
โน้ตทบทวน 30 รายการ สร้างโดย cookie แบ่งเป็น 6 ส่วนตามหัวข้อของหลักสูตร
Notes for Edexcel IGCSE Computer Science (4CP0), in folders for the specification's six topics in its order: problem solving, programming, data, computers, communication and the internet, and the bigger picture. Each topic has one note per sub-topic or small group of them, and the programming notes use the board's pseudocode with Python examples. Follows the specification for first teaching in 2017 (Issue 1).
มีอะไรอยู่ข้างใน
โน้ตรายการแรก
Problem solving / Algorithms, flowcharts and tracing
What an algorithm is
An algorithm is an ordered set of steps that solves a problem or completes a task, and that finishes after a finite number of them. A computer does only what its steps say, so a problem has to be broken into steps it can follow exactly, with no step left to judgement. The same algorithm can be written in several notations: a written description, a flowchart, pseudocode or program code. The notation changes how the steps look on the page, but the steps themselves stay the same, which is why a good student can read an algorithm in one notation and rewrite it in another.
Every algorithm, whatever its notation, is built from three constructs. Sequence is steps carried out one after another. Selection is a choice between steps, depending on whether a condition is true. Iteration is repeating steps while, or until, a condition holds, or a fixed number of times. Almost any task a computer can do is some combination of these three.
Flowcharts
A flowchart draws the steps as shapes joined by arrows. Each shape means one kind of step:
- a rounded box shows the start and the end of the algorithm;
- a rectangle is a process, such as a calculation or an assignment;
- a diamond is a decision, with a question inside and one arrow for each possible answer, usually labelled Yes and No or True and False;
- a parallelogram is an input or an output;
- a rectangle with extra vertical lines at its sides is a subprocess, a step whose detail is drawn in a separate flowchart;
- arrows show the order in which the steps happen.
Suppose a program reads a number and prints "big" when the number is greater than 10 and "small" otherwise. The flowchart starts, reads the number (an input), asks whether the number is greater than 10 (a decision), follows the Yes arrow to print "big" or the No arrow to print "small" (outputs), and ends. Each decision must have a clear answer for every value, or the flowchart is incomplete.
Pseudocode
Pseudocode is a structured, readable notation that looks like a simple programming language without the detail of any one. The board's command set, which students are expected to read and write, uses these forms.
- SET name TO value assigns a value to a variable, and the value can be an expression such as Score + 10.
- SEND expression TO DISPLAY writes output to the screen.
- RECEIVE name FROM (INTEGER) KEYBOARD reads input of a stated type.
- IF condition THEN ... ELSE ... END IF makes a selection.
- WHILE condition DO ... END WHILE repeats while the condition is true, testing before each pass, so the body may not run at all.
- REPEAT ... UNTIL condition repeats until the condition becomes true, testing after each pass, so the body always runs at least once.
- FOR counter FROM start TO finish DO ... END FOR repeats for each value from the start to the finish, inclusive.
- # starts a comment that runs to the end of the line.
Here is a short algorithm that adds twice each of the numbers 0 to 3:
SET Total TO 0
FOR Index FROM 0 TO 3 DO
SET Total TO Total + Index * 2
END FOR
SEND Total TO DISPLAYThe same algorithm in Python is:
total = 0
for index in range(0, 4):
total = total + index * 2
print(total)Python's range(0, 4) stops before 4, which is why the Python version has 4 where the pseudocode has 3. Everything else lines up one to one. Being able to move between the two notations is a useful check that you have understood both, and that the loop bounds are right.
Tracing an algorithm
A trace table shows how the values of the variables change as the algorithm runs. It has one column for each variable and for each output, and one row for each step that changes something. To find out what an algorithm produces for a set of data, start from the first line, write down the value after each step, and keep going until the algorithm ends.
For the algorithm above, the trace table is:
| Step | Index | Total | Output |
|---|---|---|---|
| Set Total to 0 | 0 | ||
| Loop, Index 0 | 0 | 0 | |
| Loop, Index 1 | 1 | 2 | |
| Loop, Index 2 | 2 | 6 | |
| Loop, Index 3 | 3 | 12 | |
| Send Total to display | 12 | 12 |
The algorithm therefore displays 12. A trace table is most useful when the algorithm is long, has loops, or depends on conditions, because it turns a difficult question about what happens into a sequence of easy questions about one step at a time.
Tracing is also how errors are found. Choose test data that the algorithm should handle, trace it, and compare the result with the answer you expected. The first row where the trace and the expected answer part company points to the step that is wrong.
Take an algorithm meant to count how many numbers in the list 4, 12, 10, 25 are greater than 10. Suppose it uses IF Number >= 10 THEN rather than IF Number > 10 THEN. The trace adds 1 to the count for 12, adds 1 again for 10, and adds 1 for 25, so it displays 3. The expected answer is 2, and the trace shows the fault at the comparison for 10, where the boundary value has been included when it should not be. Changing >= to > fixes the algorithm, and a second trace with the same data confirms the new answer of 2.
Boundary values, the values at the edge of what an algorithm should accept, are the most common place for this kind of fault, which is why a test plan always includes them.
Reading and writing algorithms
Reading an algorithm means working out what it does, given its steps. Ask what each variable holds at the start, what each step changes, and what the algorithm outputs. Naming the purpose of an algorithm, in one sentence, makes it easier to spot a step that does not fit that purpose.
Writing an algorithm starts from the problem rather than from the notation. Decide what the inputs are, what the outputs must be, and what processing turns one into the other. Then write the steps in whichever notation is asked for or is clearest. A flowchart is good for seeing the branches of a decision; pseudocode is better for loops and for a precise statement of the data; written steps are good at the start, before either of these.
When an algorithm must be coded in a high-level language, each pseudocode step has a direct counterpart. Assignments become assignments, the IF block becomes an if statement, and the loop becomes a loop. Doing this translation by hand is a common way to find the steps that were vague in the first draft.
และอีก 29 รายการ: เปิดรายการใดก็ได้จากรายการด้านบน
รีวิว
ยังไม่มีรีวิวที่เขียนไว้ เพิ่มโน้ตเหล่านี้ลงในของคุณ แล้วคุณจะเป็นคนแรกที่เขียนรีวิว