Resources | Subject Notes | Computer Science
This section focuses on developing and representing algorithms to solve computational problems. We will explore using pseudo-code and flowcharts to design step-by-step instructions for a computer to follow.
Pseudo-code is an informal way of describing an algorithm. It uses a combination of natural language and structured keywords to outline the steps involved. It's not a programming language but a blueprint for a program.
START
/ BEGIN
: Marks the beginning of the algorithm.INPUT
: Indicates that data is being read from the user or a source.OUTPUT
: Indicates that data is being displayed to the user or sent to a destination.IF
... THEN
... ELSE
: Used for conditional execution.WHILE
... DO
... ENDWHILE
: Used for repetitive execution based on a condition.FOR
... DO
... ENDFOR
: Used for repetitive execution a fixed number of times.RETURN
: Indicates the end of a procedure and the value to be returned.Example: Calculating the area of a rectangle
START INPUT width, height OUTPUT area area = width * height END
Flowcharts are diagrams that visually represent an algorithm. They use standard symbols to show the flow of control and the steps involved.
Symbol | Name |
---|---|
Process/Operation | |
Decision | |
Input/Output | |
Connector |
Example: Calculating the area of a rectangle (Flowchart)
START INPUT width, height Process: area = width * height OUTPUT area END
Several strategies can be used to design effective algorithms:
Let's design an algorithm to find the largest number in a list of numbers.
START INPUT list of numbers SET largest = first number in list FOR each number in list IF number > largest THEN SET largest = number ENDIF ENDFOR OUTPUT largest END
This example demonstrates how to translate a problem into a structured algorithm using both pseudo-code and a flowchart. Understanding these techniques is crucial for problem-solving in computer science.