Algorithm Design Basics: Naming and Sequence
When designing algorithms, naming conventions play a crucial role. Starting with a specific name like CalculateInterest in CamelCase format sets the tone. The sequential execution process, known as SEQUENCE, follows a step-by-step approach from start to finish. This structured method, depicted by statements in a logical order, ensures efficient algorithm design. Drawing parallels to everyday tasks like making tea showcases the practical application of algorithmic thinking. Embracing a systematic ALGORITHM-Do stuff-END pattern simplifies program structuring for various tasks. Mastering the fundamentals of algorithm design, particularly the importance of names and sequential execution, lays a solid foundation for proficient programming.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Algorithm The first thing we do when designing a algorithm is to decide on a name. Let s say we want to write an algorithm to calculate interest, a good name for the algorithm would be CalculateInterest. Note the use of CamelCase.
algorithm So we start the algorithm as: ALGORITHM CalculateInterest:
Algorithm So we start the algorithm as: ALGORITHM CalculateInterest: And in general it s: ALGORITHM <AlgorithmName>:
Algorithm Our program will finish with the following: END.
Algorithm Our program will finish with the following: END. And in general it s the same: END.
Algorithm So the general structure of all programs is: ALGORITHM <AlgorithmName>: <Do stuff> END.
Algorithm When we write algorithms, we assume that the computer executes the algorithm starting at the beginning and working its way to the end. This is a basic assumption of all algorithm design. We call this SEQUENCE.
Algorithm It looks like this: Statement1; Statement2; Statement3; Statement4; Statement5; Statement6; Statement7; Statement8;
Algorithm For example, for making a cup of tea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve;
Algorithm Or as an algorithm: ALGORITHM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve; END.
Algorithm Or as an algorithm: ALGORITHM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk and/or sugar; Serve; END.
Algorithm What if we want to make a choice, for example, do we want to add sugar or not to the tea?
Algorithm What if we want to make a choice, for example, do we want to add sugar or not to the tea? We call this SELECTION.
Algorithm So, we could state this as: IF (sugar is required) THEN add sugar; ELSE don t add sugar; ENDIF;
Algorithm Or, in general: IF (<CONDITION>) THEN <Statements>; ELSE <Statements>; ENDIF;
Algorithm Or to check which number is biggest: IF (A > B) THEN Print A + is bigger ; ELSE Print B + is bigger ; ENDIF;
Algorithm Adding a selection statement in the program: ALGORITHM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.
Algorithm Adding a selection statement in the program: ALGORITHM MakeACupOfTea: Organise everything together; Plug in kettle; Put teabag in cup; Put water into kettle; Wait for kettle to boil; Add water to cup; Remove teabag with spoon/fork; Add milk; IF (sugar is required) THEN add sugar; ELSE do nothing; ENDIF; Serve; END.