Chapter 8 - Algorithm, Pseudo Code and Flow Charts
- Authors
- Ms. Samavi Salman
- Dr. Rao Muhammad Adeel Nawab
- Supporting Material
Quick Recap
- Quick Recap – Operators and Expression
In previous Chapter, I presented the following main concepts:
- Operation
- In Computer Programming, an Operation is defined as an action that is carried out to accomplish a given Task
- Five Basic Computer Operations
- The five basic Computer Operations are
- Input
- Processing
- Output
- Store
- Control
- The five basic Computer Operations are
- Operator
- In Computer Programming, an Operator is defined as a special Symbol, which is used to carry out Arithmetic / Logical Operations
- Operand
- In Computer Programming, an Operand is defined as the Object (or Value) on which an Operator operates
- Expression
- In Programming Language, an Expression is a combination of Operands (Variables / Constants) and Operator(s) to produce an Output Value
- Main Components of an Expression
- An Expression comprises of Two Main Components
- Operator
- Operands
- An Expression comprises of Two Main Components
- Types of Operators
- The main Types of Operators (in Python) are
- Assignment Operator
- Arithmetic Operators
- Logical Operators
- Comparison Operators
- Membership Operators
- Identity Operators
- The main Types of Operators (in Python) are
- Assignment Operator
- Assignment Operator is represented with = Symbol
- Arithmetic Operator
- An Arithmetic Operator is an Operator that takes two Operands and performs Calculation on them
- Types of Arithmetic Operators in Python
- In Python, we have following six Arithmetic Operators
- Addition
- +
- Subtraction
- –
- Multiplication
- *
- Division
- /
- Exponent
- **
- Modulus
- %
- Addition
- In Python, we have following six Arithmetic Operators
- Exponent
- Exponent (or Power) of a Number tells us how many times a Number will be multiplied by itself
- Dividend, Divisor and Quotient
- In Division, a Value (Number) is divided by any other Value (Number) to get another Value (Number) as Output
- Dividend
- The Value (Number) which is getting divided is called Dividend
- Divisor
- The Value (Number) which divides a given Value (Number) is called Divisor
- Quotient
- The Output Value (Number) which we get as a result is called Quotient
- Types of Division
- In Python, two main Types of Division are
- Integer Division
- Float Division
- In Python, two main Types of Division are
- Integer Division
- In Integer Division, both Dividend (Operand 01) and Divisor (Operand 02) must be Integer Values (Constants)
- Consequently, Quotient (Output Value) will also be an Integer Value (Constant)
- Integer Division – Dividend, Divisor, Quotient and Remainder
- In Integer Division, an Integer Value (Number) is divided by any other Integer Value (Number) to get another Integer Value (Number) as Output
- Dividend
- The Integer Value (Number) which is getting divided is called Dividend
- Divisor
- The Integer Value (Number) which divides a given Value (Number) is called Divisor
- Quotient
- The Output (Integer) Value (Number) which we get as a result is called Quotient
- Remainder
- Remainder is an Integer Value, that is left over after dividing Dividend with Divisor to produce Quotient
- Float Division
- In Float Division, both (Dividend and Divisor) or one of them must be a Float Value (Constant)
- Consequently, Quotient (Output Value) will also be a Float Value (Constant)
- Precedence of Operators
- The Order in which Operators are applied on Operands in an Expression is called Precedence of Operators
Algorithm – First Step Towards Solving a Real-world Task / Problem using Computer Programming
Algorithm – In Real-world
- Algorithm – In Real-world
- Definition
- In Real-world, an Algorithm is defined as a well-defined, step-by-step procedure (or a set of rules to follow) for completing a specific Real-world Task / Problem
- Purpose
- In Computer Programming, the main purpose of an Algorithm is to
- provide an efficient solution to a Real-world Task / Problem
- In Computer Programming, the main purpose of an Algorithm is to
- Importance
- Algorithms are the backbone of Computer Programming
- Algorithms help Programmers / Software Developers to create efficient and error-free Programs / Software’s for various Real-world Tasks / Problems
- Algorithm (in Real-world) – Given and Task
- Given
- A Real-world Task / Problem
- Task
- Write an Algorithm which provides a Step-by-Step Solution to the given Real-world Task / Problem
- Algorithm (in Real-world) – Input and Output
- Input
- A Real-world Task / Problem
- Output
- An Algorithm
- Example 1: Algorithm (in Real-world) - Input and Output
- Input
- How to Get Close to Allah?
- Output
- An Algorithm
- Algorithm – Get Close to Allah
- Step 1: Accept Islam by Reading Kalima (become a Muslim)
- Step 2: Purify Your Intention i.e. Do all good deeds with one intention i.e., To Get Close to Allah?
- Step 3: Learn teachings of Islam relevant to your 24 hours life
- Step 4: Fulfill Orders of Allah, according to the Sunnat of our Beloved Prophet Hazrat Muhammad S.A.W.W.
- Step 5: Enjoy Friendship of Allah in this world and here after 😊
- Example 2: Algorithm (in Real-world) - Input and Output
- Input
- How to Get Close to Hazrat Muhammad S.A.W.W.?
- Output
- An Algorithm
- Algorithm – Get Close to Hazrat Muhammad S.A.W.W.
- Step 1: Accept Islam by Reading Kalima (become a Muslim)
- Step 2: Purify Your Intention i.e. Do all good deeds with one intention i.e., To Get Close to Allah?
- Step 3: Learn Sunnats of Hazrat Muhammad S.A.W.W. for each and every Task we do in our 24 hours life
- Step 4: Do every Task according the Sunnat of our Beloved Prophet Hazrat Muhammad S.A.W.W.
- Step 5: Recite Durood Sharif abundantly on our Beloved Prophet Hazrat Muhammad S.A.W.W.
- Step 6: Enjoy Friendship of Allah and his Beloved Prophet Hazrat Muhammad S.A.W.W. in this world and here after 😊
- Example 3: Algorithm (in Real-world) - Input and Output
- Input
- How to become a balanced and characterful person to achieve excellence in Talluq of Allah and Become No. 1 in my Field
- Output
- An Algorithm
- Algorithm – Become a balanced and characterful person
- Step 1: Purify your intention
- Step 2: Determination – Put 100% Effort with Sincerity till Death
- Step 3: Have a Guru / Mentor
- Step 4: Focus on the Following Equation to Become No. 1 in Your Field
Life = Technical Skills (15%) + Human Engineering (85%) |
- Step 5: Achieve Excellence in Human Engineering
- Step 5.1: Make a Schedule of 24 Hours to Get Excellence in Physical, Mental, Social and Spiritual Health
- Step 5.1.1: Get Excellence in Physical Health
- Go to Bed at 9 pm
- 30 Mins Brisk Walk / Running / Game
- 3 Healthy Meals per Day
- Step 5.1.1: Get Excellence in Physical Health
- Step 5.1.2: Get Excellence in Mental Health
- Step 5.1.3: Get Excellence in Spiritual Health
- Offer 5 prayers (نماز)
- Daily do دعا of at least 5 Mins
- Step 5.1: Make a Schedule of 24 Hours to Get Excellence in Physical, Mental, Social and Spiritual Health
- Step 6: Achieve Excellence in Technical Skills
- Step 6.1: Give 8 hours / week to your Field by putting 100% Effort with Sincerity
- Step 7: Do every Task (on daily basis) related to Human Engineering and Technical Skills according to the Order of Allah and Sunnat of Hazrat Muhammad S.A.W.W.
- Step 8: Report your Daily Work Progress on Human Engineering and Technical Tasks to your Guru on daily basis
- Step 9: Enjoy the blessings of becoming a balanced and characterful person (i.e., you will achieve excellence in Friendship of Allah and become No. 1 in your field 😉)
- Algorithmic Thinking – Definition
- Algorithmic Thinking is defined as the ability to define complete and correct set of steps to solve a Real-world Task / Problem
- Examples of Algorithms in Real-world
- Some of the Real-world examples of Algorithms are as follows
- Example 1
- Real-world Task
- Making Wuzu (وضو)
- Algorithm
- Method of Doing Wuzu (وضو) to Read Namaz (نماز) or Recite Quran.e.Pak (قرآن پاک)
- Real-world Task
- Example 2
- Real-world Task
- Cooking of Barley Porridge (جو کا دالیہ)
- Algorithm
- The Recipe of Making Barley Porridge (جو کا دالیہ)
- Real-world Task
- Note
- Barley Porridge (جو کا دالیہ) was one of the favorite dishes of our Beloved Prophet Hazrat Muhammad S.AW.W.
- My Respected Teacher once advised me
- Adeel! If you want to achieve Excellence in Spirituality then follow the eating habits and favorite dishes of Hazrat Muhammad S.A.W.W., particularly Milk, Honey and Dates 😊
- Example 3
- Real-world Task
- Giving Zakat on Wealth
- Algorithm
- Method of Calculating Zakat (زکوٰة) on a Muslim’s Wealth
- Important Note
- Always give Zakat of your wealth because it purifies the wealth and produces Barkat (برکت) in it
- Real-world Task
- Example 4
- Real-world Task
- Fasting
- Algorithm
- Process of Fasting in the Holy Month of Ramazan (رمضان)
- Real-world Task
- Example 5
- Real-world Task
- Hajj
- Algorithm
- Process of Performing Hajj (حج)
- May Allah accept all of us for Hajj (حج) and Umrah (عمرہ) again and again Ameen 😊
- Real-world Task
- Example 1
- Steps – How to Design an Algorithm
- In Sha Allah, for a given Real-world Task / Problem we can design an Algorithm in the following Steps
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Step 1.1: Write down the Real-world Task / Problem
- Step 1.2: Write Given and Task
- Step 1.3: Write Input and Output
- Step 1.4: Write 2 – 5 Examples based on Input and Output
- Step 2: Write down the Step-by-Step Processing required for getting form Input to Output
- Step 3: Write Algorithm in Order of Input-Processing-Output
- Step 4: Take Feedback on Algorithm from Domain Experts
- Step 5: Improve your Algorithm based on Feedback of Domain Experts (If Needed)
- Step 6: Repeat Step 1 to Step 5, until you and Domain Experts are fully satisfied with your Algorithm 😊
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Example - Steps (How to Design an Algorithm)
- In Sha Allah, in the next Slides, I will take a Real-world Task / Problem and try to explain how to solve it by designing an Algorithm
- Example - Steps (How to Design an Algorithm)
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Step 1.1: Write down the Real-world Task / Problem
- Step 1.2: Write Given and Task
- Step 1.3: Write Input and Output
- Step 1.4: Write at least 2 – 5 Examples based on Input and Output
- Real-world Task / Problem
- Calculate Zakat (زکوٰة) on Wealth
- Given and Task
- Given
- Current Assets
- Immediate Expenditures
- Task
- Calculate amount of Zakat on Wealth
- Given
- Input and Output
- Input
- Current Assets
- Immediate Expenditures
- Output
- Amount of Zakat
- Input
- Formula to Calculate Zakat
- Amount of Zakat = (Current Assets – Immediate Expenditures) x 2.5%
- Important Note
- If Amount of Zakat > 0 Rupees
- It is obligatory on you to pay Zakat on your Wealth (and if you don’t pay it will be a great sin)
- If Amount of Zakat <= 0 Rupees
- Zakat is not obligatory on you
- If Amount of Zakat > 0 Rupees
- Example 1 – Input and Output
- Input
- Current Assets = 10000 Rupees
- Immediate Expenditures = 8000 Rupees
- Output
- 50 Rupees
- Input
- Example 2 – Input and Output
- Input
- Current Assets = 10000 Rupees
- Immediate Expenditures = 10000 Rupees
- Output
- 0 Rupees
- Input
- Example 3 – Input and Output
- Input
- Current Assets = 10000 Rupees
- Immediate Expenditures = 15000 Rupees
- Output
- -75 Rupees
- Input
- Observation
- In Example 1
- Amount of Zakat is: 50 Rupees
- In Example 2
- Amount of Zakat is: 0 Rupees
- In Example 3
- Amount of Zakat is: -75 Rupees
- This shows that Zakat is obligatory in case of Example 1 only 😊
- In Example 1
- Important Note
- To completely and correctly understand a Real-world Task / Problem, in Examples of Input and Output, it is good to
- Present All Possible Combinations of Input
- For example, in above Real-world Task / Problem (i.e., Adding Two Integer Numbers), there are three Possible Combinations of Input
- Current Assets are greater than Immediate Expenditures
- Current Assets are equal to Immediate Expenditures
- Current Assets are less than Immediate Expenditures
- We have given three Examples of Input and Output, which capture all three variations in Input, Alhamdulillah 😊
- To completely and correctly understand a Real-world Task / Problem, in Examples of Input and Output, it is good to
- Example - Steps (How to Design an Algorithm)
- Step 2: Write down the Step-by-Step Processing required for getting form Input to Output
- Processing – For Getting from Input to Output
- Step 1: Calculate Current Savings
- Current Savings = Current Assets – Immediate Expenditures
- Step 2: Calculate Zakat on Current Savings
- Zakat = 2.5% of Current Savings
- Step 1: Calculate Current Savings
- Example - Steps (How to Design an Algorithm)
- Step 3: Write Algorithm in Order of Input-Processing-Output
- The Algorithm to Calculate Zakat on Wealth is as follows
- Input
- Step 1: Purify your Intention (اخلاص نیت) i.e., you will do this Task by putting your 100% Effort with Sincerity to Get Close to Allah and serve the humanity for Raza of Allah
- Step 2: Calculate your Current Assets
- Step 3: Calculate your Immediate Expenditures
- Processing
- Step 4: Subtract your Immediate Expenditures from your Current Assets to calculate your Current Savings
- Current Savings = Current Assets – Immediate Expenditures
- Step 4: Subtract your Immediate Expenditures from your Current Assets to calculate your Current Savings
- Output
- Step 5: Calculate Zakat using the following Formula
- Zakat = 2.5% of Current Savings
- Step 6: Pay Zakat to the needy people
- Step 7: Enjoy blessings of Zakat 🙂
- Step 5: Calculate Zakat using the following Formula
- Input
- Example - Steps (How to Design an Algorithm)
- Step 4: Take Feedback on Algorithm from Domain Experts
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert i.e. Alim.e.Deen (عالم دین) and
- Took Feedback from him
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert i.e. Alim.e.Deen (عالم دین) and
- Example - Steps (How to Design an Algorithm)
- Step 5: Improve your Algorithm based on Feedback of Domain Experts (If Needed)
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert i.e. Alim.e.Deen (عالم دین) said
- It is fine 😊
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert i.e. Alim.e.Deen (عالم دین) said
- Example - Steps (How to Design an Algorithm)
- Step 6: Repeat Step 1 to Step 5, until you and Domain Experts are fully satisfied with your Algorithm 😊
- We didn’t repeat Step 1 to Step 5 because
- Our Algorithm is working fine 😊
- We didn’t repeat Step 1 to Step 5 because
- Program vs Algorithm
- A Program is essentially an Algorithm that tells the Computer what specific steps to execute, in what specific order, in order to perform a specific Real-world Task
- Recall – Main Purpose of a Program
- The main purpose of Program is to provide an automatic solution to a Real-world Task / Problem
- First Step to Solve a Real-world Task / Problem using Computer Programming
- Question
- What is the First Step to solve a Real-world Task / Problem using Computer Programming?
- Answer
- Design and Analysis of an Algorithm (to solve the Real-world Task / Problem using Computer Programming)
Algorithm – In Computer Programming
- Algorithm – In Computer Programming
- Definition
- In Computer Programming, an Algorithm is defused as a well-defined, step-by-step procedure, or set of rules to follow (for getting from Input to Output), that allows a Computer to solve a Real-world Task / Problem
- Purpose
- In Computer Programming, the main purpose of an Algorithm is to
- provide an efficient solution to perform a Real-world Task / Problem
- In Computer Programming, the main purpose of an Algorithm is to
- Importance
- Algorithms are the backbone of Computer Programming
- Algorithms help Programmers / Software Developers to create efficient and error-free Programs / Software’s for various Real-world Tasks / Problems
- Applications
- Algorithms are used in designing and developing almost all online applications, for e.g.,
- Search Engines (for e.g., Google, Bing etc.)
- Ecommerce
- Digital Marketing
- Email (for e.g., Gmail, Yahoo Mail etc.)
- And many more 😊
- Algorithms are used in designing and developing almost all online applications, for e.g.,
- Strengths
- Easy to Completely and Correctly Understand a Real-world Task / Problem
- Since an algorithm is written in a Natural Language (e.g., English), it is very easy for a Programmer / Software Developer to completely and correctly understand the step-by-step procedure to solve a Real-world Task / Problem
- Design Efficient Solutions which are Independent of Programming Language
- Since an algorithm is written in a Natural Language (e.g., English), it is independent of Programming Languages, which makes it easier to design an efficient solution to the given Real-world Task / Problem instead of thinking about specific syntax / coding requirements of a specific Programming Language.
- Enable Programmers to Write High-quality Code (Program) in any High-Level Programming Language
- Since an algorithm contains a well-defined, step-by-step description of how to solve a Real-world Task / Problem, which makes it very easy for Programmers / Software Developers to write high-quality Code (Program) in any High-Level Programming Language
- Easy to Identify Logical Errors in a Program
- A well-designed algorithm helps us to quickly identify Logical Errors in a Program
- Weaknesses
- To develop efficient algorithms for various complex Real-world Tasks / Problems we need Domain Experts
- Developing efficient algorithms for various complex Real-world Tasks / Problems requires a lot of effort, cost and time
- Documenting efficient algorithms big and complex Real-world Tasks / Problems requires a lot of effort, cost and time
- Suitable to Use
- We should use Algorithms in solving almost all Real-world Tasks / Problems
- Algorithm (in Computer Programming) – Given and Task
- Given
- A Real-world Task / Problem (which can be solved using Computer Programming)
- Task
- Write an Algorithm which provides a Step-by-Step Solution to the given Real-world Task / Problem (which can be solved using Computer Programming)
- Algorithm (in Computer Programming) – Input and Output
- Input
- A Real-world Task / Problem (which can be solved using Computer Programming)
- Output
- An Algorithm
- Example 1: Algorithm (in Computer Programming) - Input and Output
- Input
- Calculate the time required (in HH:MM:SS) to recite 30 Paras of Quran.e.Pak, if 1 Para takes 25 minutes?
- Output
- An Algorithm
- Algorithm
- Declare and Initialize Variables i.e., time_for_one_para, number_of_paras, time_in_min, time_in_hours and time_in_seconds
- Multiply time_for_one_para with number_of_paras and store the value in Variable i.e., time_ in_min
- Convert the time_ in_min in time_ in_hours and time_ in_seconds
- Divide time_ in_min by 60
- Multiply time_ in_min with 60
- Display the time taken to recite 30 paras
- Example 2: Algorithm (in Computer Programming) - Input and Output
- Input
- Calculate the time required (in HH:MM:SS) to recite 1000 Durood Sharif, if recitation of 1 Durood Sharif takes 5 seconds?
- Output
- An Algorithm
- Algorithm
- Declare and Initialize Variables i.e., time_for_one_darood, total_times, time_in_min, time_in_hours and time_ in_seconds
- Multiply time_for_one_darood with total_times and store the value in Variable i.e., time_ in_seconds
- Convert the time_ in_seconds in time_in_hours and time_ in_min
- Divide time_in_seconds by 60
- Divide time_ in_seconds by 60
- Display the time taken to recite 1000 Darood Sharif
- Example 3: Algorithm (in Computer Programming) - Input and Output
- Input
- To Become No. 1 in any field, one needs to practice (by putting 100% Effort with Sincerity) for at least 10,000 hours. If you give 8 hours daily (5 days a week), then in how many Years / Months you will achieve excellence in your field?
- Output
- An Algorithm
- Algorithm
- Declare and Initialize Variable i.e., hours, years, time and days
- Multiply days with hours and store value in time
- Divide time by 24 and store the value in years
- Display years
- Multiple Algorithms for the Same Real-world Task / Problem
- Question
- Can we have multiple Algorithms to solve the same Real-world Task / Problem?
- Answer
- Yes
- Important Note
- As a Programmer / Software Developer, you job is to identify the
- Most Suitable Algorithm for a given Real-world Task / Problem
- As a Programmer / Software Developer, you job is to identify the
- Main Characteristics of an Efficient Algorithm
- Some of the Main Characteristics of an Efficient Algorithm are as follows
- Characteristics 1 – Completely and Correctly Understand the Input
- To develop an efficient Algorithm, completely and correctly understand the Input, which main comprises of: (1) Data and (2) Instruction(s)
- Characteristics 2 – Completely and Correctly Understand the Output
- To develop an efficient Algorithm, completely and correctly understand the Output, i.e., what results (outcome) you want to obtain by processing Data according to given Instruction(s)
- Characteristics 3 – Use Divide and Conquer Approach
- To develop an efficient Algorithm, use Divide and Conquer Approach i.e., break each Main Step into Sub-step, Sub-sub-step, and so on.
- Characteristics 4 – Order and Flow of Steps + Independence and Connectivity of Steps
- Since an algorithm is a Step-by-Step procedure (for getting from Input to Output), the Order and Flow of Steps must be correct. In addition, each Step must be Independent of other Steps and it must also be Connected to its Previous and Next Step.
- Characteristics 5 – Simplicity + Clarity + Ease of Understanding + Execution Time of Steps in an Algorithm
- Since an algorithm is a Step-by-Step procedure (for getting from Input to Output), each Step should be simple, clear, easy to understand and take a finite amount of Time to execute.
- Characteristics 6 – Independent of Programming Language
- To develop an efficient Algorithm, write it in such a way that it should be Independent of Programming Language, which will make it easier for Programmers / Software Developers to write high-quality Code (Program) in any High-Level Programming Language.
- Characteristics 1 – Completely and Correctly Understand the Input
- Programmer / Software Developer
- A Programmer / Software Developer implements an Algorithm in a particular Programming Language to provide an automatic solution to a Real-world Task / Problem
- Steps – How to Design an Algorithm
- In Sha Allah, to solve a Real-world Task / Problem using Computer Programming, we can design an Algorithm in the following Steps
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Step 1.1: Write down the Real-world Task / Problem
- Step 1.2: Write Given and Task
- Step 1.3: Write Input and Output
- Step 1.4: Write at least 2 – 5 Examples based on Input and Output
- Step 2: Write down the Step-by-Step Processing required for getting form Input to Output
- Step 3: Write Algorithm in Order of Input-Processing-Output
- Step 4: Take Feedback on Algorithm from Domain Experts
- Step 5: Improve your Algorithm based on Feedback of Domain Experts (If Needed)
- Step 6: Repeat Step 1 to Step 5, until you and Domain Experts are fully satisfied with your Algorithm 😊
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Example - Steps (How to Design an Algorithm)
- In Sha Allah, in the next Slides, I will take a Real-world Task / Problem and try to explain how to solve it (using Computer Programming) by designing an Algorithm
- Example - Steps (How to Design an Algorithm)
- Step 1: Completely and correctly understand the Real-world Task / Problem
- Step 1.1: Write down the Real-world Task / Problem
- Step 1.2: Write Given and Task
- Step 1.3: Write Input and Output
- Step 1.4: Write at least 2 – 5 Examples based on Input and Output
- Real-world Task / Problem
- Add Two Integer Numbers
- Given and Task
- Given
- Number 01
- Number 02
- Task
- Calculate the Sum of Number 01 and Number 02
- Given
- Input and Output
- Input
- Number 01
- Number 02
- Output
- Sum of Number 01 and Number 02
- Input
- Example 1 – Input and Output
- Input
- 10
- 7
- Output
- 17
- Input
- Example 2 – Input and Output
- Input
- -10
- 7
- Output
- -3
- Input
- Example 3 – Input and Output
- Input
- 10
- -7
- Output
- 3
- Input
- Example 4 – Input and Output
- Input
- -10
- -7
- Output
- -17
- Input
- Important Note
- To completely and correctly understand a Real-world Task / Problem, in Examples of Input and Output, it is good to
- Present All Possible Combinations of Input
- For example, in above Real-world Task / Problem (i.e., Adding Two Integer Numbers), there are Four Possible Combinations of Input
- Both Numbers are Positive
- First Number is Negative, and Second Number is Positive
- First Number is Positive, and Second Number is Negative
- Both Numbers are Negative
- We have given four Examples of Input and Output, which capture all four variations in Input, Alhamdulillah 😊
- Example - Steps (How to Design an Algorithm)
- Step 2: Write down the Step-by-Step Processing required for getting form Input to Output
- Processing – For Getting from Input to Output
- Step 1: Calculate Sum of Number 01 and Number 02
- Example - Steps (How to Design an Algorithm)
- Step 3: Write Algorithm in Order of Input-Processing-Output
- The Algorithm to Add Two Integer Numbers is as follows
- Input
- Step 1: Purify your Intention (اخلاص نیت) i.e., you will do this Task by putting your 100% Effort with Sincerity to Get Close to Allah and serve the humanity for Raza of Allah
- Step 2: Declare an Integer Variable (number1) and store Integer Value in it
- Step 3: Declare an Integer Variable (number2) and store Integer Value in it
- Processing + Output
- Step 4: Add number1 and number2 (i.e., Processing) and store result (i.e., Output) in an Integer Variable (sum)
- Display Output to User
- Step 5: Print sum on the Output Screen
- Input
- The Algorithm to Add Two Integer Numbers is as follows
- Example - Steps (How to Design an Algorithm)
- Step 4: Take Feedback on Algorithm from Domain Experts
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Took Feedback form her
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Example - Steps (How to Design an Algorithm)
- Step 5: Improve your Algorithm based on Feedback of Domain Experts (If Needed)
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- It is fine 😊
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- Example - Steps (How to Design an Algorithm)
- Step 6: Repeat Step 1 to Step 5, until you and Domain Experts are fully satisfied with your Algorithm 😊
- We didn’t repeat Step 1 to Step 5 because
- Our Algorithm is working fine 😊
- We didn’t repeat Step 1 to Step 5 because
- Example 2 - Steps (How to Design an Algorithm)
- Real-world Task
- Swap Values of Two Numbers
- Given and Task
- Given
- Number 01
- Number 02
- Task
- Calculate the Swap Value of Number 01 with Number 02
- Given
- Input and Output
- Input
- Number 01
- Number 02
- Output
- Swap Value of Number 01 with Number 02
- Input
- Example 1 – Input and Output
- Input
- 10
- 7
- Output
- 7
- 10
- Input
- Example 2 – Input and Output
- Input
- -10
- 7
- Output
- 7
- -10
- Input
- Example 3 – Input and Output
- Input
- 10
- -7
- Output
- -7
- 10
- Input
- Example 4 – Input and Output
- Input
- -10
- -7
- Output
- -7
- -10
- Input
- Example 5 – Input and Output
- Input
- 10.15
- 7.25
- Output
- 7.25
- 10.15
- Input
- Example 6 – Input and Output
- Input
- -10.25
- 7.15
- Output
- 7.15
- -10.25
- Input
- Example 7 – Input and Output
- Input
- 10.55
- -7.45
- Output
- -7.45
- 10.55
- Input
- Example 8 – Input and Output
- Input
- -10.0
- -7.0
- Output
- -7.0
- -10.0
- Input
- Important Note
- To completely and correctly understand a Real-world Task / Problem, in Examples of Input and Output, it is good to
- Present All Possible Combinations of Input
- For example, in above Real-world Task / Problem (i.e., Swap Two Numbers), there are Four Possible Combinations of Input
- Both Numbers are Positive
- First Number is Negative, and Second Number is Positive
- First Number is Positive, and Second Number is Negative
- Both Numbers are Negative
- We have given four Examples of Input and Output, which capture all four variations in Input, Alhamdulillah 😊
- Example - Steps (How to Design an Algorithm)
- Step 2: Write down the Step-by-Step Processing required for getting form Input to Output
- Processing – For Getting from Input to Output
- Step 1: Swap Number 01 with Number 02
- Example - Steps (How to Design an Algorithm)
- Step 3: Write Algorithm in Order of Input-Processing-Output
- The Algorithm to Add Two Integer Numbers is as follows
- Input
- Step 1: Purify your Intention (اخلاص نیت) i.e., you will do this Task by putting your 100% Effort with Sincerity to Get Close to Allah and serve the humanity for Raza of Allah
- Step 2: Declare an Integer Variable (number1) and store Integer Value in it
- Step 3: Declare an Integer Variable (number2) and store Integer Value in it
- Processing + Output
- Step 4: Swap number1 and number2 (i.e., Processing)
- Step 4.1: Store Value of Variable (i.e., number1) to a temporary Variable (i.e., temp)
- Step 4.2: Assign the Value of Variable (number2) to Variable (i.e., number1)
- Step 4.3: Assign the Value of temporary Variable (i.e., temp) to Variable (i.e., number2)
- Step 4: Swap number1 and number2 (i.e., Processing)
- Display Output to User
- Step 5: Print swapped numbers on the Output Screen
- Input
- The Algorithm to Add Two Integer Numbers is as follows
- Example - Steps (How to Design an Algorithm)
- Step 4: Take Feedback on Algorithm from Domain Experts
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Took Feedback form her
- We discussed our Algorithm (Designed in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Example - Steps (How to Design an Algorithm)
- Step 5: Improve your Algorithm based on Feedback of Domain Experts (If Needed)
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- It is fine 😊
- We didn’t make any changes to our Algorithm (Designed in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- Example - Steps (How to Design an Algorithm)
- Step 6: Repeat Step 1 to Step 5, until you and Domain Experts are fully satisfied with your Algorithm 😊
- We didn’t repeat Step 1 to Step 5 because
- Our Algorithm is working fine 😊
- We didn’t repeat Step 1 to Step 5 because
Representation of an Algorithm
- Representation of an Algorithm
- Question
- How can we represent an Algorithm?
- Answer
- There are many possible methods to represent an Algorithm
- Representation of Algorithm using Natural Language Text
- Question
- How can we represent an Algorithm using Natural Language Text?
- Answer
- Use Pseudo Code
- Graphical Representation of Algorithm
- Question
- How can we represent an Algorithm in graphical form?
- Answer
- Use Flow Chart
- Note
- In Sha Allah, in the next Slides, we will try to explain how to represent an Algorithm using
- Pseudo Code
- Flow Chart
Pseudo Code – Representation of an Algorithm in Natural Language Text
- Pseudo Code
- Definition
- In Computer Programming, Pseudo Code is a formally styled Natural Language (i.e., very close to English) used to write an Algorithm
- Note
- Pseudo Code has no Syntax (like a Programming Language) and therefore, it cannot be compiled / interpreted by a Compiler / Interpreter
- Purpose
- The main purpose of Pseudo Code is to
- Represent an Algorithm using a formally styled Natural Language
- The main purpose of Pseudo Code is to
- Importance
- Pseudo Code helps us to represent an Algorithm in Natural Language, which makes it easier to
- Completely and correctly understand the solution to a specific Real-world Task / Problem
- Design and draw Flow Charts to better understand the transition between various stages of a Program
- Start Documentation of the Program (which is very important to develop high-quality Programs)
- Implement an Algorithm in any High-Level Programming Language
- Identify Bugs / Errors and fix them
- Pseudo Code helps us to represent an Algorithm in Natural Language, which makes it easier to
- Applications
- To develop efficient Algorithms for a range of Real-world Tasks / Problems, we need to write Pseudo Code for each and every Algorithm 😊
- Strengths
- A well written Pseudo Code helps us to
- Completely and correctly understand the Step-by-Step solution to a Real-world Task / Problem
- Easily solve very complex and big Real-world Tasks / Problems
- Efficiently and effectively communicate with people from different backgrounds
- Provide Programming Language Independent solutions to a Real-world Task / Problem
- Provide a bridge between an Algorithm and a Flow Chart / Program
- Identify potential Bugs / Errors before writing actual Code (Program)
- Start high-quality Documentation
- Weaknesses
- To write high-quality Pseudo Code for algorithms designed to solve various complex Real-world Tasks / Problems we need Domain Experts
- Writing high-quality Pseudo Code for algorithms designed to solve various complex Real-world Tasks / Problems requires a lot of effort, cost and time
- Documenting high-quality Pseudo Code for algorithms designed to solve big and complex Real-world Tasks / Problems requires a lot of effort, cost and time
- Suitable to Use
- We write Pseudo Code for almost every Algorithm 😊
- Pseudo Code – Given and Task
- Given
- An Algorithm
- Task
- Write high-quality Pseudo Code for the given Algorithm
- Pseudo Code – Input and Output
- Input
- An Algorithm
- Output
- Pseudo Code
- Example 1 - Pseudo Code (Input and Output)
- Input
- Calculate the time required (in HH:MM:SS) to recite 30 Paras of Quran.e.Pak, if 1 Para takes 25 minutes?
- Output
- Pseudo Code
- Pseudo Code
- Step 1: START
- Step 2 – Initialize Variables
- Step 2.1: INIT – time_for_one_para
- Step 2.2: INIT – number_of_paras
- Step 2.3: INIT – time_in_min
- Step 2.4: INIT – time_in_hours
- Step 2.5: INIT – time_in_seconds
- Step 3: COMPUTE
- time_ in_min = time_for_one_para * number_of_paras
- time_ in_min / 60
- time_ in_min * 60
- Step 4: DISPLAY – Time taken to recite 30 paras
- print(“h:m:s-> %d:%d:%d” % (hour, minutes, seconds))
- Step 5: STOP
- Example 2 - Pseudo Code (Input and Output)
- Input
- Calculate the time required (in HH:MM:SS) to recite 1000 Durood Sharif, if recitation of 1 Durood Sharif takes 5 seconds?
- Output
- Pseudo Code
- Pseudo Code
- Step 1: START
- Step 2 – Initialize Variables
- Step 2.1: INIT – time_for_one_darood
- Step 2.2: INIT – total_times
- Step 2.3: INIT – time_in_min
- Step 2.4: INIT – time_in_hours
- Step 2.5: INIT – time_in_seconds
- Step 3: COMPUTE
- time_ in_seconds = time_for_one_darood * total_times
- time_in_seconds / 60
- time_ in_seconds / 60
- Step 4: DISPLAY – Display the time taken to recite 1000 Darood Sharif
- print(“h:m:s-> %d:%d:%d” % (hour, minutes, seconds))
- Step 5: STOP
- Example 3 - Pseudo Code (Input and Output)
- Input
- To Become No. 1 in any field, one needs to practice (by putting 100% Effort with Sincerity) for at least 10,000 hours. If you give 8 hours daily (5 days a week), then in how many Years / Months you will achieve excellence in your field?
- Output
- Pseudo Code
- Pseudo Code
- Step 1: START
- Step 2 – Initialize Variables
- Step 2.1: INIT – hours
- Step 2.2: INIT – years
- Step 2.3: INIT – time_in_min
- Step 2.4: INIT – time
- Step 2.5: INIT – days
- Step 3: COMPUTE
- time = days * hours
- years = time / 24
- Step 4: DISPLAY – years
- Step 5: STOP
- Algorithm vs Pseud Code vs Program
- Algorithm
- Algorithm is defused as a well-defined, step-by-step procedure, or set of rules to follow (for getting from Input to Output), that allows a Computer to solve a Real-world Task / Problem
- Pseudo Code
- Pseudo Code is used to represent an Algorithm using formally styled Natural Language before it is implemented in a specific Programming Language
- Program
- Program is the actual Code written in a specific Programming language by following all the rules of that Programming Language
- Pseudo Code Constructs
- Recall – In Python Programming, three main Python Control Structures are
- Sequential Structure
- Selection Structure
- Repetition Structure
- Pseudo Code Constructs must have representation for the above mentioned three Python Control Structures, to have a
- complete and correct representation of an Algorithm
- Pseudo Code Constructs
- Definition
- Pseudo Code Constructs is a set of Keywords, which are used to represent Six Main Constructs of High-Level Programming Languages
- Purpose
- The main purpose of Pseudo Code Constructs is to
- describe the Control Flow of an Algorithm
- The main purpose of Pseudo Code Constructs is to
- Importance
- Without Pseudo Code Constructs it is not possible to
- Write high-quality Pseudo Code, which is easy to implement in any High-Level Programming Language
- Without Pseudo Code Constructs it is not possible to
- Applications
- Pseudo Code Constructs enable us to write
- High-quality Pseudo Code, which is very easy and simple for any Programmer / Software Developer to completely and correctly understand, and implement it in any High-Level Programming Language
- Pseudo Code Constructs enable us to write
- Strengths
- Pseudo Code Constructs help us to represent all the Main Constructs of High-Level Programming Languages, which makes it
- very easy and simple to write Pseudo Code which is universally understood
- Pseudo Code Constructs help us to represent all the Main Constructs of High-Level Programming Languages, which makes it
- Weaknesses
- Since there is no Standard Set of Pseudo Code Constructs and if each Pseudo Code Construct is not properly and clearly explained before writing Pseudo Code, then it might become difficult to completely and correctly understand the Algorithm (represented by Pseudo Code)
- Suitable to Use
- We must use Pseudo Code Constructs in writing all Pseudo Codes 😊
- Representing Python Control Structures using Pseudo Code Constructs
- Question
- Which Pseudo Code Construct is used for Representation of Sequential Structure?
- Answer
- SEQUENCE
- Pseudo Code Constructs for Sequential Structure
- Some of the main Pseudo Code Constructs for Sequential Structure are as follows
- Pseudo Code Construct 01
- Name
- READ
- Purpose
- Take Input from User
- Name
- Pseudo Code Construct 02
- Name
- SET
- Purpose
- Initialize a Variable with a Value
- Name
- Pseudo Code Construct 03
- Name
- COMPUTE
- Purpose
- Perform an Arithmetic Calculation
- Name
- Pseudo Code Construct 04
- Name
- ADD
- Purpose
- Add Numbers
- Name
- Pseudo Code Construct 05
- Name
- SUBTRACT
- Purpose
- Subtract Numbers
- Name
- Pseudo Code Construct 06
- Name
- MULTIPLY
- Purpose
- Multiply Numbers
- Name
- Pseudo Code Construct 07
- Name
- DIVIDE
- Purpose
- Divide Numbers
- Name
- Pseudo Code Construct 08
- Name
- MODULUS
- Purpose
- Take Modulus of an Integer Number
- Name
- Pseudo Code Construct 09
- Name
- Purpose
- Display Output / Value of a Variable / Message on the Output Screen
- Name
- Pseudo Code Construct 01
- Representing Python Control Structures using Pseudo Code Constructs
- Question
- Which Pseudo Code Constructs are used for Representation of Selection Structure?
- Answer
- IF
- IF-ELSE
- IF-ELSE-IF
- Pseudo Code Constructs for Selection Structure
- Below we describe the Pseudo Code Constructs used to represent Selection Structure
- Pseudo Code Construct 01
- Name
- IF
- Purpose
- To Represent an if Statement in Python
- Writing Style
- IF CONDITION
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- END IF
- IF CONDITION
- Name
- Pseudo Code Construct 02
- Name
- IF-ELSE
- Purpose
- To Represent an if-else Statement in Python
- Writing Style
- IF CONDITION
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- ELSE
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- END IF-ELSE
- IF CONDITION
- Name
- Pseudo Code Construct 03
- Name
- IF-ELSE-IF
- Purpose
- To Represent an if-elif Statement in Python
- Writing Style
- IF CONDITION 01
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- ELSE IF CONDITION 02
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- ELSE IF CONDITION 03
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- ELSE IF CONDITION 04
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- ……..
- ELSE IF CONDITION N
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- END IF-ELSE-IF
- IF CONDITION 01
- Name
- Pseudo Code Construct 01
- Representing Python Control Structures using Pseudo Code Constructs
- Question
- Which Pseudo Code Constructs are used for Representation of Repetition Structure?
- Answer
- FOR
- WHILE
- Pseudo Code Constructs for Repetition Structure
- Below we describe the Pseudo Code Constructs used to represent Repetition Structure
- Pseudo Code Construct 01
- Name
- FOR
- Purpose
- To Represent a For Loop in Python
- Writing Style
- FOR CONDITION
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- END FOR
- FOR CONDITION
- Name
- Pseudo Code Construct 02
- Name
- WHILE
- Purpose
- To Represent a While Loop in Python
- Writing Style
- WHILE CONDITION
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- END WHILE
- WHILE CONDITION
- Name
- Pseudo Code Construct 01
- Pseudo Code Constructs for Functions
- Question
- Which Pseudo Code Constructs are used for Functions?
- Answer
- CALL
- RETURN
- Pseudo Code Constructs for Functions
- Below we describe the Pseudo Code Constructs for Functions
- Pseudo Code Construct 01
- Name
- CALL
- Purpose
- To Call a Function in Python
- Writing Style
- CALL FUNCTION_NAME
- Name
- Pseudo Code Construct 02
- Name
- RETURN
- Purpose
- It is used when a Function (in Python) Returns a Value
- Writing Style
- RETURN VALUE_TO_BE_RETURNED
- Name
- Pseudo Code Construct 01
- Pseudo Code Constructs for Exception Handling
- Question
- Which Pseudo Code Constructs are used for Exception Handling?
- Answer
- EXCEPTION
- WHEN
- Pseudo Code Constructs for Exception Handling
- Below we describe the Pseudo Code Constructs for Exception Handling
- Pseudo Code Construct 01
- Name
- EXCEPTION
- Purpose
- To throw exception
- Writing Style
- BEGIN
- statements
- BEGIN
- EXCEPTION
- WHEN exception type
- statements to handle exception
- WHEN exception type
- END
- Name
- Pseudo Code Construct 02
- Name
- WHEN
- Purpose
- Used to specify operation when a particular exception occurs
- Name
- Writing Style
- WHEN Exception N
- Statement(s) to Handle Exception N
- WHEN Exception N
- Pseudo Code Construct 01
- Pseudo Code Constructs for Exception Handling
- Below we describe how EXCEPTION and WHEN Pseudo Code Constructs are used for Exception Handling
- BEGIN
- Statement 01
- Statement 02
- Statement 03
- …..
- Statement N
- EXCEPTION
- WHEN Exception 01
- Statement(s) to Handle Exception 01
- WHEN Exception 02
- Statement(s) to Handle Exception 02
- WHEN Exception 03
- Statement(s) to Handle Exception 03
- ……..
- WHEN Exception N
- Statement(s) to Handle Exception N
- WHEN Exception 01
- END
- BEGIN
- Best Practices to Write High-quality Pseudo Code
- Some of the main Best Practices to write high-quality Pseudo Code, which is universally understood are as follows
- Best Practice 01: The First Word must be CAPITIALIZED 😊
- Best Practice 02: Write only
- One Statement per Line
- Best Practice 03: Use proper Indentation, to
- Show hierarchy
- Improve readability and understandability
- Best Practice 04: To end Pseudo Code Constructs which comprise of Multiple Lines (for e.g., IF, FOR, WHILE etc.)
- Always use the END keyword
- Best Practice 05: Statements in the Pseudo Code must be Independent of Programming Language
- Best Practice 06: Keep it Simple
- Examples - Best Practice for Writing High-quality Pseudo Code
Example 1 – Best Practice for Writing High-quality Pseudo Code
- Consider the following Pseudo Code and identify whether it is written using Best Practices or Not?
- Pseudo Code
- FOR i in range(1,10):
- DISPLAY – i
- ENDFOR
- FOR i in range(1,10):
- Remarks
- Good Pseudo Code
- Reasons
- The construct keyword is Capitalized
- The Pseudo code is concise
- Only One line per statement
- The Program ends with ENDFOR
- Pseudo Code
Example 2 – Best Practice for Writing High-quality Pseudo Code
- Consider the following Pseudo Code and identify whether it is written using Best Practices or Not?
- Pseudo Code
- for i in range(1,10): display – i
- Remarks
- Bad Pseudo Code
- Reasons
- The construct keyword is not Capitalized
- There are two lines per statement
- The Program lacks ENDFOR
- Pseudo Code
- Steps – Representing an Algorithm using Pseudo Code
- In Sha Allah, to Represent an Algorithm (designed to solve a Real-world Task / Problem using Computer Programming) using Pseudo Code, in the following Steps
- Step 1: Obtain the Algorithm to be Represented as Pseudo Code
- Step 2: Write down Pseudo Code Constructs
- Step 3: Write down Best Practices to Write Pseudo Code
- Step 4: Convert Algorithm (obtained in Step 1) into Pseudo Code by using Pseudo Code Constructs (mentioned in Step 2) and following the Best Practices for Pseudo Code Writing (mentioned in Step 3)
- Step 5: Take Feedback on Pseudo Code (written in Step 4) from Domain Experts
- Step 6: Improve your Pseudo Code based on Feedback of Domain Experts (If Needed)
- Step 7: Repeat Step 1 to Step 6, until you and Domain Experts are fully satisfied with your Algorithm 😊
- Example - Steps (Representing an Algorithm using Pseudo Code)
- In Sha Allah, in the next Slides, I will try to show how to Represent an Algorithm (designed to solve a Real-world Task / Problem using Computer Programming) using Pseudo Code
- Example 1 - Steps (Representing an Algorithm using Pseudo Code)
- Real-world Task / Problem
- Add Two Integer Numbers
- Example 1 - Steps (Representing an Algorithm using Pseudo Code)
- Step 1: Obtain the Algorithm to be Represented as Pseudo Code
- Below is the Algorithm which we designed in the Previous Section to solve the Real-world Task / Problem using Computer Programming i.e., Adding Two Integer Numbers
- Algorithm – Adding Two Integer Numbers
- Input
- Step 1: Purify your Intention (اخلاص نیت) i.e., you will do this Task by putting your 100% Effort with Sincerity to Get Close to Allah and serve the humanity for Raza of Allah
- Step 2: Declare an Integer Variable (number1) and store Integer Value in it
- Step 3: Declare an Integer Variable (number2) and store Integer Value in it
- Processing + Output
- Step 4: Add number1 and number2 (i.e., Processing) and store result (i.e., Output) in an Integer Variable (sum)
- Display Output to User
- Step 5: Print sum on the Output Screen
- Input
- Step 2: Write down Pseudo Code Constructs
- Alhamdulillah, we have already described Pseudo Code Constructs earlier in this Section
- Step 3: Write down Best Practices to Write Pseudo Code
- Alhamdulillah, we have already described Best Practices to Write Pseudo Code earlier in this Section
- Step 4: Convert Algorithm (obtained in Step 1) into Pseudo Code by using Pseudo Code Constructs (mentioned in Step 2) and following the Best Practices for Pseudo Code Writing (mentioned in Step 3)
- Below is the Pseudo Code for the Algorithm on Adding Two Integer Numbers
- Start 1: START
- Input
- Step 2: READ – Two Integer Numbers
- Step 2.1: READ – number1
- Step 2.2: READ – number2
- Step 2: READ – Two Integer Numbers
- Processing + Output
- Step 3: sum = number1 + number2
- Display Output to User
- Step 4: PRINT – sum
- Step 5: STOP
- Below is the Pseudo Code for the Algorithm on Adding Two Integer Numbers
- Step 5: Take Feedback on Pseudo Code (written in Step 4) from Domain Experts
- We discussed our Pseudo Code (written in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Took Feedback from her
- We discussed our Pseudo Code (written in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Step 6: Improve your Pseudo Code based on Feedback of Domain Experts (If Needed)
- We didn’t make any changes to our Pseudo Code (written in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- It is fine 😊
- We didn’t make any changes to our Pseudo Code (written in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- Step 7: Repeat Step 1 to Step 6, until you and Domain Experts are fully satisfied with your Pseudo Code 😊
- We didn’t repeat Step 1 to Step 6 because
- Our Pseudo Code is fine 😊
- We didn’t repeat Step 1 to Step 6 because
- Example 2 - Steps (Representing an Algorithm using Pseudo Code)
- Real-world Task
- Swap Values of Two Numbers
- Example 2 - Steps (Representing an Algorithm using Pseudo Code)
- Step 1: Obtain the Algorithm to be Represented as Pseudo Code
- Below is the Algorithm which we designed in the Previous Section to solve the Real-world Task / Problem using Computer Programming i.e., Swap Values of Two Numbers
- Algorithm – Swap Values of Two Numbers
- Input
- Step 1: Purify your Intention (اخلاص نیت) i.e., you will do this Task by putting your 100% Effort with Sincerity to Get Close to Allah and serve the humanity for Raza of Allah
- Step 2: Declare a Variable (number1) and store Integer Value in it
- Step 3: Declare a Variable (number2) and store Integer Value in it
- Processing + Output
- Step 4: Swap number1 and number2 (i.e., Processing)
- Step 4.1: Store Value of Variable (i.e., number1) to a temporary Variable (i.e., temp)
- Step 4.2: Assign the Value of Variable (number2) to Variable (i.e., number1)
- Step 4.3: Assign the Value of temporary Variable (i.e., temp) to Variable (i.e., number2)
- Step 4: Swap number1 and number2 (i.e., Processing)
- Display Output to User
- Step 5: Print swapped numbers on the Output Screen
- Input
- Step 2: Write down Pseudo Code Constructs
- Alhamdulillah, we have already described Pseudo Code Constructs earlier in this Section
- Step 3: Write down Best Practices to Write Pseudo Code
- Alhamdulillah, we have already described Best Practices to Write Pseudo Code earlier in this Section
- Step 4: Convert Algorithm (obtained in Step 1) into Pseudo Code by using Pseudo Code Constructs (mentioned in Step 2) and following the Best Practices for Pseudo Code Writing (mentioned in Step 3)
- Below is the Pseudo Code for the Algorithm on Swap Two Numbers
- Start 1: START
- Input
- Step 2: READ – Two Integer Numbers
- Step 2.1: READ – number1
- Step 2.2: READ – number2
- Processing + Output
- Step 3: COMPUTE
- Step 3.1: temp = number1
- Step 3.2: number1 = number2
- Step 3.3: number2 = temp
- Step 3: COMPUTE
- Display Output to User
- Step 4: PRINT – swapped numbers
- Step 5: STOP
- Below is the Pseudo Code for the Algorithm on Swap Two Numbers
- Step 5: Take Feedback on Pseudo Code (written in Step 4) from Domain Experts
- We discussed our Pseudo Code (written in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Took Feedback from her
- We discussed our Pseudo Code (written in Step 4) with a Domain Expert (Mrs. Ayesha Usman – Data Scientist) and
- Step 6: Improve your Pseudo Code based on Feedback of Domain Experts (If Needed)
- We didn’t make any changes to our Pseudo Code (written in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- It is fine 😊
- We didn’t make any changes to our Pseudo Code (written in Step 4) because Domain Expert (Mrs. Ayesha Usman – Data Scientist) said
- Step 7: Repeat Step 1 to Step 6, until you and Domain Experts are fully satisfied with your Pseudo Code 😊
- We didn’t repeat Step 1 to Step 6 because
- Our Pseudo Code is fine 😊
- We didn’t repeat Step 1 to Step 6 because
FlowChart
- Flow Chart
- Definition
- In Computer Programming, a Flow Chart is defined as a Step-by-Step Graphical Representation of an Algorithm
- Purpose
- The main purpose of a Flow Chart is to completely and correctly understand the: (1) Data Flow and (2) Logic (behind an Algorithm), to write high-quality Program
- Importance
- Flow Charts help us to
- Completely and correctly understand the Data Flow and Logic of an Algorithm before we start Coding it 😊
- Flow Charts help us to
- Applications
- Flow Charts are useful in
- Designing an Efficient Algorithm
- Efficient Analysis of an Algorithm
- Writing high-quality Code (Program)
- Identifying and Fixing Bugs in Code
- Collaboration between Different Teams involved in Software Development
- Flow Charts are useful in
- Strengths
- Flowcharts are better way of communicating the logic of a system to all concerned or involved.
- With the help of flowchart, problem can be analyzed in more effective way therefore reducing cost and wastage of time.
- Program flowcharts serve as a good program documentation, which is needed for various purposes, making things more efficient.
- The flowcharts act as a guide or blueprint during the systems analysis and program development phase.
- The flowchart helps in debugging process.
- The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part
- Flowcharts are easier to understand compare to Algorithms and Pseudo code.
- It helps us to understand Logic of given problem.
- Using only very few symbols, complex problem can be represented in flowchart.
- Flowcharts are one of the good ways of documenting programs.
- Weaknesses
- Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. This will become a pain for the user, resulting in a waste of time and money trying to correct the problem
- If alterations are required the flowchart may require re-drawing completely. This will usually waste valuable time.
- As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.
- Manual tracing is needed to check correctness of flowchart drawn on paper.
- Simple modification in problem logic may leads to complete redraw of flowchart.
- Showing many branches and looping in flowchart is difficult.
- In case of complex program/algorithm, flowchart becomes very complex and clumsy.
- Modification of flowchart is sometimes time consuming.
- Suitable to Use
- To develop understanding of how a process is done
- To study a process for improvement
- To communicate to others how a process is done
- When better communication is needed between people involved with the same process
- To document a process
- When planning a project
- Flow Chart – Given and Task
- Given
- An Algorithm
- Task
- Draw a Flow Chart which completely and correctly represents the given Algorithm
- Flow Chart – Input and Output
- Input
- An Algorithm
- Output
- A Flow Chart
- Example 1 - Flow Chart (Input and Output)
- Input
- ALGORITHM TO ADD TWO NUMBERS
- Output
- A Flow Chart
- Example 2 - Flow Chart (Input and Output)
- Input
- ALGOIRHTM TO SWAP VALUES OF TWO NUMBERS
- Output
- A Flow Chart
- Drawing a Flow Chart
- Question
- How can we draw a Flow Chart?
- Answer
- Using Symbols
- Flow Chart - Symbols
- The main Symbols used in drawing a Flow Chart for an Algorithm are as follows
- Tools for Drawing Flow Charts
- Some of the popular and widely used Tools to Draw Flow Charts are
- Microsoft Visio
- Draw.io (Online Tool)
- Steps – Representing an Algorithm using Flow Chart
- In Sha Allah, to Represent an Algorithm (designed to solve a Real-world Task / Problem using Computer Programming) using Flow Chart, in the following Steps
- Step 1: Obtain the Algorithm to be Represented as Flow Chart
- Step 2: Write down Flow Chart Constructs
- Step 3: Write down Best Practices to Draw Flow Chart
- Step 4: Convert Algorithm (obtained in Step 1) into Flow Chart by using Flow Chart Constructs (mentioned in Step 2) and following the Best Practices for Drawing Flow Chart (mentioned in Step 3)
- Step 5: Take Feedback on Flow Chart (written in Step 4) from Domain Experts
- Step 6: Improve your Flow Chart based on Feedback of Domain Experts (If Needed)
- Step 7: Repeat Step 1 to Step 6, until you and Domain Experts are fully satisfied with your Flow Chart 😊
- Example - Steps (Representing an Algorithm using Pseudo Code)
- In Sha Allah, in the next Slides, I will try to show how to Represent an Algorithm (designed to solve a Real-world Task / Problem using Computer Programming) using Flow Chart
- Example 1 - Steps (Representing an Algorithm using Flow Chart)
- Real-world Task / Problem
- Add Two Integer Numbers
- Example 2 - Steps (Representing an Algorithm using Flow Chart)
- Real-world Task / Problem
- Swap Values of Two Numbers
Algorithm vs Pseudo Code vs Flow Chart vs Program
- Program vs Flow Chart
No | Program | Flowchart |
1 | Programs are set of instructions or computer code that perform specific task | Flowchart is graphical representation of functions of program |
2 | Programs are basically coded instructions for automatic performance of task | Flowchart is basically diagrammatic representation of algorithm |
3 | Instructions are created for computer to execute by writing and testing code | Flowcharts are created to analyze, design, document or manage program |
4 | Programs are generally complex and difficult but are not needed to be coded in several languages | Flowcharts are generally simple and easy but when process is complex then process flowchart look messy and difficult to use or handle |
5 | Program is written in programming language by typing on computer | Flowchart symbols cannot be typed |
- Program vs Pseudo Code
No | Program | Pseudo Code |
1 | It is exact code written for problem following all the rules of the programming language | It is a simpler version of a programming code in plain English which uses short phrases to write code for a program before it is implemented in a specific programming language |
- Algorithm vs Pseudo Code
No | Pseudo Code | Algorithm |
1 | Pseudo Code is a method of writing an Algorithm implemented in a specific programming language | Systematic logical approach which is a well-defined, Algorithm is a step-by-step procedure to solve a given problem |
2 | Pseudo Code is a method of developing an algorithm | Algorithm helps to simplify and understand the problem |
3 | Pseudo Code is an informal high-level description of the operating principle of a computer program or other algorithm | An Algorithm is an unambiguous specification of how to solve a problem |
4 | Pseudo Code is just a syntax of the communication about solving a problem | Algorithm is the semantic |
5 | Easy to interpret | Quite hard to understand |
6 | Combination of programming language and natural language | Complicated programming language |
7 | Simpler | Moderate |
8 | Easier | Complex |
- Algorithm vs Flow Chart
No | Algorithm | Flowchart |
1 | Algorithm is step by step procedure to solve the problem | Flowchart is a diagram created by different shapes to show the flow of data |
2 | Algorithm is complex to understand | Flowchart is easy to understand |
3 | In Algorithm plain text are used | In Flowchart, symbols/shapes are used |
4 | Algorithm is easy to debug | Flowchart it is hard to debug |
5 | Algorithm is difficult to construct | Flowchart is simple to construct |
6 | Algorithm does not follow any rules | Flowchart follows rules to be constructed |
7 | Algorithm is the pseudo code for the program | Flowchart is just graphical representation of that logic |
8 | Algorithms are Hard to understand | Easily interpreted |
9 | Algorithms contains Text | Symbols |
10 | Perplexing | Simple |
11 | Algorithm is basically used in the field of computer science and mathematics only | Flowchart can be used in various fields to represent a process |
12 | It can be used to define notion of decidability | It is used in analyzing, designing, documenting, or managing a program in various fields |
13 | The user of does require knowledge of a programming language to write understand an algorithm | The user of Flowchart does not require knowledge of a programming language to write and understand a flow chart |
- Algorithm vs Program
No | Algorithm | Program |
1 | An algorithm is a list of steps, typically written in some human language, that explains how to perform a specific task | A computer program is a list of instructions that tells a computer exactly what to do from step to step. |
2 | Algorithms are generally written in a natural language or plain English language | Program on the other hand allows us to write a code in a particular programming language |
- Flow Chart vs Pseudo Code
No | Pseudo Code | Flowchart |
1 | Pseudo Code is an informal high-level description of an Algorithm | Flowchart is a pictorial representation of an Algorithm |
2 | Pseudo Code is a method of describing computer Algorithms using a combination of natural language and programming language | Flowchart s are written with program flow from the top of a page to the bottom |
Chapter Summary
- Chapter Summary
In this Chapter, I presented the following main concepts:
- Algorithm – In Real-world
- In Real-world, an Algorithm is defined as a well-defined, step-by-step procedure (or a set of rules to follow) for completing a specific Real-world Task / Problem
- Algorithmic Thinking
- Algorithmic Thinking is defined as the ability to define complete and correct set of steps to solve a Real-world Task / Problem
- Algorithm – In Computer Programming
- In Computer Programming, an Algorithm is defused as a well-defined, step-by-step procedure, or set of rules to follow (for getting from Input to Output), that allows a Computer to solve a Real-world Task / Problem
- Pseudo Code
- In Computer Programming, Pseudo Code is a formally styled Natural Language (i.e., very close to English) used to write an Algorithm
- Flow Chart
- In Computer Programming, a Flow Chart is defined as a Step-by-Step Graphical Representation of an Algorithm
In Next Chapter
- In Next Chapter
- In Sha Allah, in the next Chapter, I will present a detailed discussion on
- Best Coding Practices in Python