Introduction to Coding Algorithms
Introduction to Algorithms
Algorithm: A step-by-step set of instructions designed to solve a problem or perform a computation.
Objective: Enables a solution to be expressed independently of programming languages, transforming specific user input into expected output.
Flowcharts and Pseudocode
Flowchart: A visual representation of an algorithm using standardized symbols connected by directional arrows.
Start / End: Rounded rectangle or oval shape indicating program entry or exit.
Input / Output: Parallelogram shape for taking inputs or returning results.
Process: Rectangle shape for operations, calculations, or data assignments.
Decision: Diamond shape representing conditional questions that split execution paths into
TRUEorFALSE.
Pseudocode: Short, structured, readable textual statements where each numbered step corresponds directly to a flowchart shape.
Variables and Constants
Variable: A data element whose value can change during program execution (e.g.,
Height,Length,Age). A variable holds one value at a time.Constant: A fixed data item defined by the programmer whose value remains unchanged throughout program execution (e.g.,
Pi, number of letters in the alphabet).
Stages of an Algorithm
Start: Initial step marking the start of execution (
START).Input: Captures individual data inputs sequentially (e.g.,
Input,Input).Processing: Executes individual operations sequentially (e.g.,
,).Output: Returns individual output values sequentially (e.g.,
Output Sum,Output Product).End: Final step concluding program execution (
END).
Order of Instructions
Sequence Sensitivity: The order of execution is critical when subsequent processes depend on prior outcomes.
Mathematical Operations: Must strictly follow standard mathematical precedence rules such as
BODMAS.
Decision Making and Logic
Boolean Variable: A variable type limited to holding one of two possible values:
TrueorFalse.Flowchart Decision: Uses a diamond shape containing a conditional query (e.g.,
). Path branching followsTRUEorFALSEarrows.
Pseudocode IF…THEN…ELSE Structure:
IFconditionTHENaction ifTrueELSEaction ifFalseEND IF
Nested IF Statement: Used when evaluating three or more potential outcomes by embedding a secondary condition inside the
ELSEblock.