SlideShare a Scribd company logo
1
Basic Concepts of Algorithm
Basic Concepts of
Algorithm
Previously…
A program MUST be systematically and
properly designed before coding begins.
This design process results in the
construction of an ALGORITHM.
Algorithm
• There is no general definition of algorithm accepted.
• But we can say that algorithm is:
i. A step‐by‐step problem‐solving procedure.
ii. A sequence of instruction that tell how to solve a particular problem.
iii. A set of instruction for solving a problem, especially on a computer.
iv. A computable set of steps to achieve a desired result.
• However, most agree that algorithm has something to do with
defining generalized processes to get “output” from the “input”.
Algorithm
• Therefore, we can conclude that:
• Algorithm a step‐by‐step problem solving process in which a solution is
arrived in a finite amount of time
OR
• An algorithm is a finite list of sequential steps specifying actions that if
performed result in solution of a specific problem.
Algorithm & Logical Thinking
• To develop the algorithm, the programmer needs to ask:
• What data has to be fed into the computer?
• What information do I want to get out of the computer?
• Logic: Planning the processing of the program. It contains the instructions
that cause the input data to be turned into the desired output data.
Algorithm Representation
• There is no standard method of algorithm representation exist,
however there are commonly used are:
i. Flowchart
graphical representation of an orderly step by step solution to a problem.
ii. Pseudo code
Textual representations in English like to present the solution to a problem.
iii. Tree representation
graphical representation to break problem into sub‐problem and task
From Algorithm to Program
• Both are sets of instructions on how to do a task;
• Algorithm:
• talking to humans, easy to understand
• in plain (English) language
• Program:
• talking to computer (compiler)
• can be regarded as a “formal expression” of an algorithm
From Algorithm to Program
PROGRAM
ALGORITHM
a sequence of instructions
describing how to do a
task (or process)
a set of instructions which
are commands to computers
to perform specific
operations on data
Algorithm & Program
Algorithm
• A step‐by‐step problem‐solving
procedure
• A sequence of instruction that tell
how to solve a particular problem.
• A set of instruction for solving a
problem, especially on a computer.
• A computable set of steps to achieve
a desired result.
• Written in pseudo code or flowchart.
Program
• A program is a set of instructions
which are commands to computers to
perform specific operations on data.
• Instructions within a program are
organized in such a way, when the
program is run on a computer; it
results in the solution of a problem.
• Written in any programming language
Program Development Life Cycle
i. Problem solving phases
Consist of problem definition and algorithm design
Phase 1: Problem Definition (Analysis)
Phase 2: Algorithm design
Phase 3: Algorithm implementation
Phase 4: Program testing
Phase 5: Program maintenance
ii. Implementation phases
Consist of algorithm implementation, program
testing and program maintenance phases.
Phase 1: Problem Definition (Analysis)
• The problem is defined to obtain a clear understanding of the problem requirement.
• It is important before come out with the solution algorithm to do the following:
a. Analyze the problem thoroughly.
b. Understand the requirement of the problem and required solution.
c. Divide the problem into sub‐problem if the problem is complex.
• The most important and major requirement that need to be specified during problem definition (analysis):
a. Input
b. Process
c. Output
• However, to get a complete problem specification, the following questions should be asked during problem
definition (analysis):
a. What are the input data?
b. What are the output (desired) data?
c. What formula is to be used?
d. What other assumptions or constraints can be made?
e. What is the expected output screen?
Phase 2: Algorithm design
• The specifications derived earlier in the analysis phase are translated into
the algorithm. An algorithm is a step‐by‐step sequence of precise
instructions that must terminate and describes how the data is to be
processed to produce the desired outputs. The instruction may be
expressed in a human language.
• An algorithm must satisfy some requirements:
• Input : It must have zero or more input
• Output : It must produce at least one output.
• Definiteness : Every step in algorithm must be clear as to what it is supposed to do
and how many times it is expected to be executed.
• Effectiveness : It must be correct and efficiently solve the problem for it is designed.
• Finiteness : It must execute its instruction and terminate in a finite time.
Algorithm Representation
• Almost every program involves the steps of input, processing, and output.
• Therefore graphical representation are needed to separate these three
steps.
• An algorithm can be written or described or represent using several tools:
• Pseudo code
Use English‐like phrases to describe the processing process. It is not standardized
since every programmer has his or her own way of planning the algorithm.
• Flowchart
Use standardized symbol to show the steps the computer needs to take to
accomplish the program’s objective. Because flowcharts are cumbersome to revise,
they have fallen out of favor by professional programmers. Pseudo code, on the
other hand, has gained increasing acceptance.
Flowchart Symbol and Description
Name Symbol Description
Lozenge Indicates the starting or ending of flowchart
(start / stop : terminal )
Connector Used to connect break in the flowchart
Parallelelogram Use for input and output operation (data)
Rectangle Indicates any interval operation (process)
Diamond Use for asking questions that can have either
TRUE of FALSE / YES or NO (decision / selection)
Module Sub solution to solve a part of entire problem
Control flow Shows flow direction
Flowchart Logic Structure
Sequence Structure Selection Structure Loop Structure
statement
statement
DO WHILE
(test
condition)
LOOP
(statement)
DO WHILE
No
Yes
ELSE
(statement)
IF
(test
condition)
THEN
(statement)
No
Yes
Flowchart Example
Design an algorithm to find the area of a rectangle
The formulas: area = length * width
Input Process Output
Input variable:
length
width
Processing item:
area
Formula:
area = length x width
Step / Solution algorithm:
get input
calculate area
display output
Output:
area
Start
length, width
calculate area
area
End
Pseudo Code Style
Style 1 Style 2 Style 3 (Modular design)
Problem
1. Start
2. Task
3. Action
4. End
Problem
1. Start
2. Subproblem 1
Task 1,1
Action 1,1,1
Action 1,1,2
3. Subproblem 2
Task 1,2
Action 1,2,1
Action 1,2,2
4. End
Problem
1. Start
2. Subproblem 1
3. Subproblem 2
4. End
2. Subproblem 1
Task 1,1
Action 1,1,1
Action 1,1,2
3. Subproblem 2
Task 1,2
Pseudo Code Example
Start
Read length
Read width
Calculate area of a rectangle
Display area of a rectangle
End
Design an algorithm to find the area of a rectangle
The formulas: area = length * width
Input Process Output
Input variable:
length
width
Processing item:
area
Formula:
area = length x width
Step / Solution algorithm:
get input
calculate area
display output
Output:
area
Start
Prompt the user to enter a length of a rectangle
Prompt the user to enter a width of a rectangle
Calculate the area of a rectangle
Display the area of a rectangle
End
Start
Input length
Input width
Calculate area of a rectangle
Output area of a rectangle
End
OR
OR
Why Algorithm is Important?
• Describe the steps needed to perform a computation
• Important for writing efficient code
• code that execute faster & which uses less memory
Sequence Structure
• With sequence structure, an action or event is performed in order,
one after another.
• A sequence can contain any number of events but there is no chance
to branch off and skip any of the events.
• Once you start a series of events in a sequence, you must continue
step‐by‐step until the sequence ends.
Sequence Example
• Problem
• Design a software to calculate the sum of two numbers entered by user.
Step 1: Program Specification
• Understand what the problem is?
• What is needed to solve it?
• What solution should provide for the problem?
• Input to the problem
• Expected output
• Any special constraints/condition/ formulas to be used
Sequence Example
• Problem
• Design a software to calculate the sum of two numbers entered by user.
Input Process Output
Input variable:
num1
num2
Processing item:
sum
Formula:
sum = num1 + num2
Step / Solution algorithm:
get input
calculate sum
display output
Output:
sum
Sequence Example
Simple Design
1. Start
2. Get input
Read num1
Read num2
3. Calculate sum
sum = num1 + num2
4. Display output
Print sum
5. End
Pseudo Code
Modular Design
1. Start
2. get_input()
3. calculate_sum()
4. display_output()
5. End
2. get_input()
Read num1
Read num2
3. calculate_sum()
sum = num1 + num2
4. display_output()
Print sum
Simple Design Modular Design
Sequence Example
Simple Design
Flowchart
Modular Design
Simple Design Modular Design
start
Read num1,
num2
calculate sum
Print sum
end
Start
End
calculate_sum()
get_input()
display_output()
Sub-Module
Start
Read
num1
Read
num2
Return
Start
Return
calculate sum
Start
Print sum
Return
EXERCISES
Exercise
For each of the problem, analyze it using IPO table, then write the
algorithm (pseudo code and flowchart).
• Problem 1: Calculate the area of one circle.
• Problem 2: Calculate the temperature in Celsius. Temperature in
Fahrenheit will be entered. The formula is;
• Temperature in Celsius = 5/9 (temperature in Fahrenheit – 32)
• Problem 3: Calculate the final mark for a student who took CS118
paper. The final mark is the total of on-going assessment (carry mark)
and 60% of final exam. The carry mark is calculated as follow:
• Carry mark = 20% of test mark + 20% of quiz mark

More Related Content

Similar to Algorithm.pdf

Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.ppt
malik681299
 
Lecture1
Lecture1Lecture1
Lecture1
Andrew Raj
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
MMRF2
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
Prof. Dr. K. Adisesha
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Kirti Verma
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
ssuser586772
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
lekha572836
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
miansaad18
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Sangheethaa Sukumaran
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
Muhammadalizardari
 
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx
Lec 2 -algorithms-flowchart-and-pseudocode1.pptxLec 2 -algorithms-flowchart-and-pseudocode1.pptx
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx
AbdelrahmanRagab36
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
Frankie Jones
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
TadiwaMawere
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
ssuserb7c8b8
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
Rohit Shrivastava
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
Saurabh846965
 

Similar to Algorithm.pdf (20)

Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
 
Programs_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.pptPrograms_Problem_Solving_Algorithms.ppt
Programs_Problem_Solving_Algorithms.ppt
 
Lecture1
Lecture1Lecture1
Lecture1
 
L1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdfL1. Basic Programming Concepts.pdf
L1. Basic Programming Concepts.pdf
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
 
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.pptBCE L-2 Algorithms-and-Flowchart-ppt.ppt
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
 
part_1 (1).ppt
part_1 (1).pptpart_1 (1).ppt
part_1 (1).ppt
 
Lec-ProblemSolving.pptx
Lec-ProblemSolving.pptxLec-ProblemSolving.pptx
Lec-ProblemSolving.pptx
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
 
Practical 01 (detailed)
Practical 01 (detailed)Practical 01 (detailed)
Practical 01 (detailed)
 
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx
Lec 2 -algorithms-flowchart-and-pseudocode1.pptxLec 2 -algorithms-flowchart-and-pseudocode1.pptx
Lec 2 -algorithms-flowchart-and-pseudocode1.pptx
 
2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem2.3 Apply the different types of algorithm to solve problem
2.3 Apply the different types of algorithm to solve problem
 
Problem-solving and design 1.pptx
Problem-solving and design 1.pptxProblem-solving and design 1.pptx
Problem-solving and design 1.pptx
 
Design and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit oneDesign and Analysis of Algorithm ppt for unit one
Design and Analysis of Algorithm ppt for unit one
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
 
L1
L1L1
L1
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 

Algorithm.pdf

  • 1. 1 Basic Concepts of Algorithm Basic Concepts of Algorithm
  • 2. Previously… A program MUST be systematically and properly designed before coding begins. This design process results in the construction of an ALGORITHM.
  • 3. Algorithm • There is no general definition of algorithm accepted. • But we can say that algorithm is: i. A step‐by‐step problem‐solving procedure. ii. A sequence of instruction that tell how to solve a particular problem. iii. A set of instruction for solving a problem, especially on a computer. iv. A computable set of steps to achieve a desired result. • However, most agree that algorithm has something to do with defining generalized processes to get “output” from the “input”.
  • 4. Algorithm • Therefore, we can conclude that: • Algorithm a step‐by‐step problem solving process in which a solution is arrived in a finite amount of time OR • An algorithm is a finite list of sequential steps specifying actions that if performed result in solution of a specific problem.
  • 5. Algorithm & Logical Thinking • To develop the algorithm, the programmer needs to ask: • What data has to be fed into the computer? • What information do I want to get out of the computer? • Logic: Planning the processing of the program. It contains the instructions that cause the input data to be turned into the desired output data.
  • 6. Algorithm Representation • There is no standard method of algorithm representation exist, however there are commonly used are: i. Flowchart graphical representation of an orderly step by step solution to a problem. ii. Pseudo code Textual representations in English like to present the solution to a problem. iii. Tree representation graphical representation to break problem into sub‐problem and task
  • 7. From Algorithm to Program • Both are sets of instructions on how to do a task; • Algorithm: • talking to humans, easy to understand • in plain (English) language • Program: • talking to computer (compiler) • can be regarded as a “formal expression” of an algorithm
  • 8. From Algorithm to Program PROGRAM ALGORITHM a sequence of instructions describing how to do a task (or process) a set of instructions which are commands to computers to perform specific operations on data
  • 9. Algorithm & Program Algorithm • A step‐by‐step problem‐solving procedure • A sequence of instruction that tell how to solve a particular problem. • A set of instruction for solving a problem, especially on a computer. • A computable set of steps to achieve a desired result. • Written in pseudo code or flowchart. Program • A program is a set of instructions which are commands to computers to perform specific operations on data. • Instructions within a program are organized in such a way, when the program is run on a computer; it results in the solution of a problem. • Written in any programming language
  • 10. Program Development Life Cycle i. Problem solving phases Consist of problem definition and algorithm design Phase 1: Problem Definition (Analysis) Phase 2: Algorithm design Phase 3: Algorithm implementation Phase 4: Program testing Phase 5: Program maintenance ii. Implementation phases Consist of algorithm implementation, program testing and program maintenance phases.
  • 11. Phase 1: Problem Definition (Analysis) • The problem is defined to obtain a clear understanding of the problem requirement. • It is important before come out with the solution algorithm to do the following: a. Analyze the problem thoroughly. b. Understand the requirement of the problem and required solution. c. Divide the problem into sub‐problem if the problem is complex. • The most important and major requirement that need to be specified during problem definition (analysis): a. Input b. Process c. Output • However, to get a complete problem specification, the following questions should be asked during problem definition (analysis): a. What are the input data? b. What are the output (desired) data? c. What formula is to be used? d. What other assumptions or constraints can be made? e. What is the expected output screen?
  • 12. Phase 2: Algorithm design • The specifications derived earlier in the analysis phase are translated into the algorithm. An algorithm is a step‐by‐step sequence of precise instructions that must terminate and describes how the data is to be processed to produce the desired outputs. The instruction may be expressed in a human language. • An algorithm must satisfy some requirements: • Input : It must have zero or more input • Output : It must produce at least one output. • Definiteness : Every step in algorithm must be clear as to what it is supposed to do and how many times it is expected to be executed. • Effectiveness : It must be correct and efficiently solve the problem for it is designed. • Finiteness : It must execute its instruction and terminate in a finite time.
  • 13. Algorithm Representation • Almost every program involves the steps of input, processing, and output. • Therefore graphical representation are needed to separate these three steps. • An algorithm can be written or described or represent using several tools: • Pseudo code Use English‐like phrases to describe the processing process. It is not standardized since every programmer has his or her own way of planning the algorithm. • Flowchart Use standardized symbol to show the steps the computer needs to take to accomplish the program’s objective. Because flowcharts are cumbersome to revise, they have fallen out of favor by professional programmers. Pseudo code, on the other hand, has gained increasing acceptance.
  • 14. Flowchart Symbol and Description Name Symbol Description Lozenge Indicates the starting or ending of flowchart (start / stop : terminal ) Connector Used to connect break in the flowchart Parallelelogram Use for input and output operation (data) Rectangle Indicates any interval operation (process) Diamond Use for asking questions that can have either TRUE of FALSE / YES or NO (decision / selection) Module Sub solution to solve a part of entire problem Control flow Shows flow direction
  • 15. Flowchart Logic Structure Sequence Structure Selection Structure Loop Structure statement statement DO WHILE (test condition) LOOP (statement) DO WHILE No Yes ELSE (statement) IF (test condition) THEN (statement) No Yes
  • 16. Flowchart Example Design an algorithm to find the area of a rectangle The formulas: area = length * width Input Process Output Input variable: length width Processing item: area Formula: area = length x width Step / Solution algorithm: get input calculate area display output Output: area Start length, width calculate area area End
  • 17. Pseudo Code Style Style 1 Style 2 Style 3 (Modular design) Problem 1. Start 2. Task 3. Action 4. End Problem 1. Start 2. Subproblem 1 Task 1,1 Action 1,1,1 Action 1,1,2 3. Subproblem 2 Task 1,2 Action 1,2,1 Action 1,2,2 4. End Problem 1. Start 2. Subproblem 1 3. Subproblem 2 4. End 2. Subproblem 1 Task 1,1 Action 1,1,1 Action 1,1,2 3. Subproblem 2 Task 1,2
  • 18. Pseudo Code Example Start Read length Read width Calculate area of a rectangle Display area of a rectangle End Design an algorithm to find the area of a rectangle The formulas: area = length * width Input Process Output Input variable: length width Processing item: area Formula: area = length x width Step / Solution algorithm: get input calculate area display output Output: area Start Prompt the user to enter a length of a rectangle Prompt the user to enter a width of a rectangle Calculate the area of a rectangle Display the area of a rectangle End Start Input length Input width Calculate area of a rectangle Output area of a rectangle End OR OR
  • 19. Why Algorithm is Important? • Describe the steps needed to perform a computation • Important for writing efficient code • code that execute faster & which uses less memory
  • 20. Sequence Structure • With sequence structure, an action or event is performed in order, one after another. • A sequence can contain any number of events but there is no chance to branch off and skip any of the events. • Once you start a series of events in a sequence, you must continue step‐by‐step until the sequence ends.
  • 21. Sequence Example • Problem • Design a software to calculate the sum of two numbers entered by user. Step 1: Program Specification • Understand what the problem is? • What is needed to solve it? • What solution should provide for the problem? • Input to the problem • Expected output • Any special constraints/condition/ formulas to be used
  • 22. Sequence Example • Problem • Design a software to calculate the sum of two numbers entered by user. Input Process Output Input variable: num1 num2 Processing item: sum Formula: sum = num1 + num2 Step / Solution algorithm: get input calculate sum display output Output: sum
  • 23. Sequence Example Simple Design 1. Start 2. Get input Read num1 Read num2 3. Calculate sum sum = num1 + num2 4. Display output Print sum 5. End Pseudo Code Modular Design 1. Start 2. get_input() 3. calculate_sum() 4. display_output() 5. End 2. get_input() Read num1 Read num2 3. calculate_sum() sum = num1 + num2 4. display_output() Print sum Simple Design Modular Design
  • 24. Sequence Example Simple Design Flowchart Modular Design Simple Design Modular Design start Read num1, num2 calculate sum Print sum end Start End calculate_sum() get_input() display_output() Sub-Module Start Read num1 Read num2 Return Start Return calculate sum Start Print sum Return
  • 26. Exercise For each of the problem, analyze it using IPO table, then write the algorithm (pseudo code and flowchart). • Problem 1: Calculate the area of one circle. • Problem 2: Calculate the temperature in Celsius. Temperature in Fahrenheit will be entered. The formula is; • Temperature in Celsius = 5/9 (temperature in Fahrenheit – 32) • Problem 3: Calculate the final mark for a student who took CS118 paper. The final mark is the total of on-going assessment (carry mark) and 60% of final exam. The carry mark is calculated as follow: • Carry mark = 20% of test mark + 20% of quiz mark