0% found this document useful (0 votes)
29 views

Algorithm and Logic Formulation

This document discusses algorithms and pseudocode. It begins by defining an algorithm as a list of step-by-step procedures to solve a problem, and pseudocode as a numbered list of instructions to perform a task without specific programming syntax. It then provides examples of three simple types of algorithms: sequential, conditional, and iterative. A sequential algorithm executes steps in straight linear order, a conditional algorithm includes conditions and alternative paths, and an iterative algorithm repeats a block of instructions. Several examples are given including computing gross pay, a coffee/tea vending machine, and an ATM machine to illustrate the different algorithm types.

Uploaded by

Jennifer Ventus
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Algorithm and Logic Formulation

This document discusses algorithms and pseudocode. It begins by defining an algorithm as a list of step-by-step procedures to solve a problem, and pseudocode as a numbered list of instructions to perform a task without specific programming syntax. It then provides examples of three simple types of algorithms: sequential, conditional, and iterative. A sequential algorithm executes steps in straight linear order, a conditional algorithm includes conditions and alternative paths, and an iterative algorithm repeats a block of instructions. Several examples are given including computing gross pay, a coffee/tea vending machine, and an ATM machine to illustrate the different algorithm types.

Uploaded by

Jennifer Ventus
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12

Algorithm and Logic Formulation

Algorithm and Pseudocode

Algorithm
It is a list of step-by-step procedures expressed in natural language to solve a particular problem.

Pseudo-code
Pseudo-code is simply a numbered list of instructions to perform some task.

Pseudo-code
No formatting syntax or rules

Programming statements compiled executed

Algorithm: Three Simple Types


Sequential

Also called straight-line algorithm


Executes its instructions in a straight line from top to bottom

Example of Sequential Algorithm


One way LRT Trip
1. Fall in line.

2. Buy a token or ticket.


3. Insert the token or ticket in the turnstile slot. 4. Wait for the train. 5. Ride on the train. 6. Watch out for the station. 7. Get off the train. 8. Insert the token or ticket in the turnstile slot. 9. Leave.

Algorithm: Three Simple Types


Sequential

Conditional
There is a condition to satisfy Ask questions and choose alternative actions based on the answers

Example of Conditional Algorithm


Computation of Gross Pay
1. 2. 3. get Hours_worked get Pay_rate if Hours_worked is less than or equal to 40 then 3.1 Gross_pay is equal to Pay_rate times Hours_worked else 4.1 Gross_pay is equal to Pay_rate times 40 plus 1.5 plus pay rate times (hours worked minus 40) display gross pay stop. Sequential Conditional

4.

5. 6.

Algorithm: Three Simple Types


Sequential Conditional Iterative Goes back and repeat a block of instructions

Example of Iterative Algorithm


Coffee and Tea Vendo Machine
1. 2. 3. Get ORDER. Get the QUANTITY. if ORDER = coffee then 3.1 AMOUNT = coffee rate times quantity 4. else 4.1 AMOUNT = tea rate times quantity 5. display AMOUNT 6. get CASH. 7. If CASH < AMOUNT then 7.1 display message 7.2 release CASH 7.3 go to 6 8. Else 8.1 if CASH > AMOUNT then 8.1.1 CHANGE = CASH PRICE 8.1.2 release CHANGE 8.1.3 go to 10 9. Else 9.1 if CASH = PRICE then 9.1.1 go to 10 10. COUNTER = 1 11. Do While Counter <= QUANTITY 11.1 Release cup 11.2 Pour hot water 11.3 if Order = coffee then 11.3.1 Drop coffee 11.4 else 11.4.1 Drop tea 11.5 Counter = Counter + 1 12 Loop 13. Stop
Sequential Conditional Iterative

Algorithm: Automated Teller Machine


1. Input PIN code 2. If PIN code is incorrect then 2.1 If attempt is 3 then 2.1.1. Capture card 2.1.2 Stop 2.2 Else 2.2.1 Display warning 2.2.2. Increase attempt 2.2.3. Go to #1 3. Else 3.1. Select Transaction 3.1.1 If transaction = Balance Inquiry then 3.1.1.1 Display the current balance 3.1.1.2. go to #3.1 3.1.2 Else 3.1.2.1 If transaction = Withdrawal Then 3.1.2.1.1 Enter amount 3.1.2.1.2 Check the balance 3.1.2.1.3 if balance is OK then 3.1.2.3.1 release money 3.1.2.3.2. go to #3.1 3.1.2.1.4 Else 3.1.2.4.1 go to #3.1 3.1.3 Else 3.1.3.1 If transaction = Exit Then 3.1.3.1.1 Go to #4

Class ctivity Identify the Sequential, Conditional, and Iterative steps from the given algorithm.

4 Stop

5-minute Activity:
Get the Average grade of Prelim, Midterm, and Final Grades Output if Failed if Average Grade is below 74

End.
Algorithm.ppt

You might also like