Professional Documents
Culture Documents
03 Algorithm Design Elements Uml
03 Algorithm Design Elements Uml
03 Algorithm Design Elements Uml
Algorithms (DSA)
Dr Suryaprakash Kompalli
Agenda
• Introduction to Algorithm Design
• Practical representations
– Pseudo code
– Flowcharts
– Finite state machines
– Unified Modeling Language (UML)
Introduction to Algorithm Design
●
Application / Real life problem: Description of an objective that
needs to be achieved by processing data
●
Instance: A replication of the problem using specific data-set
●
Algorithm: Well-defined logic that processes the data in a finite
time to meet the objective correctly
●
Implementation: Programs or codes that can run on a computing
device and simulate the algorithm
●
Tests: Sets of instances that check whether an implementation is
meeting the objective or not
Introduction to Algorithm Design
●
The underlying data structure is central to algorithm design, ex:
– Can you design insertion sort for integers if the numbers are stored in a singly
linked list?
– If you need to sort 10 Million integers, is array the best representation?
●
Other aspects:
– Formally, an algorithm should end in finite time.
– What will you prefer, an algorithm that sorts 1 Million integers in 1 hour, or an
algorithm that sorts 1 Million integers in 1 minute?
– An implementation should be able to run on the hardware that the problems needs
it to run on. What is better: an implementation that uses 4GB of RAM or one that
uses 0.2 GB of RAM? The amount of memory consumed is also dependent on the
algorithm used.
Introduction to Algorithm Design
●
State-dependent algorithms behave differently based on certain parameters
or conditions. Generally these systems may have two or more sources of data.
One data source will determine the output; one or mode data sources can
determine the state. Examples:
– Keep water temperature at or above 60 degree Celsius. A control system for this would have to
monitor two states – water temperature less than 60 degrees, and water temperature more
than 60 degrees. Data: Quantity of water, temperature of water
– Online ad delivery: Which page is the user looking at? How many minutes was the user reading
this page? What kind of device does the user have?
●
State-less algorithms depend on a fixed quantum of data to meet an
objective. Processing is not changed midway due to other inputs.
– Sorting algorithms
– Industrial systems that take only one input; example: hydraulic jacks.
– There may be some conditions regarding inputs/outputs: example: inputs should be +ve
numbers, output should be between 0 to 1 etc
Introduction to Algorithm Design
Start Input
Step 1 Step 2 Step 3 Output
End
Step 3.A
Step 1.A
Start Input
Step 2 Step 3.B Output
End
Step 1.B
Step 3.C
Intermediate
Input Intermediate
Input
State based system
It is not always necessary that a system will change state based on intermediate input. States can change based
on input data as well. Example: If number of user requests > 100K, move those requests to critical systems
Agenda
• Introduction to Algorithm Design
• Practical representations
– Pseudo code
– Flowcharts
– Finite state machines
– Unified Modeling Language (UML)
Practical Representations: Pseudo code
●
Pseudo code represents the steps involved in an algorithm
– Pseudo code may or may not represent all the corner cases that need to be checked when an
algorithm is implemented; e.x: Check that the raw material vat is not empty, check that input
array contains valid data
– Has a human-readable structure
– Looks like a computer program but cannot be compiled to run on a machine
– Accurately represents all steps of an algorithm needed to get results for input data
– Should allow one to completely understand the algorithm and infer aspects like run-time
complexity, memory usage etc
●
There is currently no universal standard or syntax for writing pseudo code
– Many constructs like mathematical functions, variable initialization, modification of variables,
comments are allowed as part of pseudo code
Practical Representations: Pseudo code
●
Example control structures used in pseudo code:
– If then else
– Numerical loops / iterations: Do following steps “n” times
– Conditional loops / iterations: While <Condition> do following steps
●
Example condition: A < B, File end is not reached, temperature < 60
●
A set of steps that perform a specific task can be defined using functions /
procedures / processes
– Example: Process cleanCarburetor(), Function Partition(A, p, r)
Practical Representations: Pseudo code
●
Example pseudo code:
Program flow
Terminal Process Decision Input / Output Comment Predefined
Process (functions)
Connectors Preparation or
Left: On-page, Database Document Multiple Manual operation Manual input
program initialization
Right: Off page documents
Practical Representations: Flowcharts An example flow chart of a pushbutton switch control
system for wireless emergency start and stop for robots.
temp = A A=A+B
A=B B=A-B
B = temp A=A-B
Output A, B Output A, B
Stop Stop
Practical Representations: Flowcharts
Source: Developing a Human Machine Interface (HMI) for Industrial Automated Systems using Siemens
Simatic WinCC FlexibleAdvanced Software Erwin Normanyo, Francis Husinu, Ofosu Robert Agyare,
Journal of Emerging Trends in Computing and Information Sciences, Feb 2014
Agenda
• Introduction to Algorithm Design
• Practical representations
– Pseudo code
– Flowcharts
– Finite state machines
– Unified Modeling Language (UML)
Practical Representations: Finite State Machines
●
A Finite State Machine or Automata (FSM or FSA) is represented by the
system: FSM , F=(S , s0 , E , s e )
S : States in which a process can exist
s 0 ∈S : set of special states which signify the start of a process
E : Edges or transition between states, generally shown as e(s1, s 2 )
It is not necessary that all pairs of nodes should have edges.
s e : set of special states which signify the end of a process
ε/start
No oil/
overheated
Engine is Engine is
generating generating
power normally low/no power
Normal oil/
temperature
Practical Representations: Finite State Machines
Finite state machine to model a
few words in Hindi
Source: Slides on Morphology and Finite State Transducers, Intro to NLP, CS585, Fall 2014, Brendan O’Connor, https://tinyurl.com/2ch5drb3
Slides on Design and comparison of segmentation driven and recognition driven Devanagari OCR, Document Image Analysis for Libraries,
2006, https://tinyurl.com/qh83rr1k
Practical Representations: Finite State Machines
Source: Dialog Semiconductor AN-CM-231 Spec Sheet, V 0.1, Mar 2018, https://tinyurl.com/zsrvmbvu
Practical Representations: Finite State Machines
●
FSMs are very efficient at representing state of specific parts of a system
●
FSMs can become very large and difficult to interpret
●
The actual design and flow of an algorithm may not always be represented by
FSMs
Agenda
• Introduction to Algorithm Design
• Practical representations
– Pseudo code
– Flowcharts
– Finite state machines
– Unified Modeling Language (UML)
Practical Representations: Unified Modeling Language
●
Designed to provide a standard for visualizing different
components of a software system
●
Approved as an ISO standard in 2005
●
Has several standards that specify how to represent:
– System activities / processes
– Communication systems / protocols
– State dependent systems
– System interactions
– Time based systems
– Use cases
●
Combines the features of flowcharts, Finite State Machines
and many more representation systems
Practical Representations: Unified Modeling Language
Source: Sample of UML Diagrams for ATM System, CIS 375. Introduction to Software
Engineering, Univ of Michigan, https://tinyurl.com/swiwko2p
Practical Representations: Unified Modeling Language
Vending machine activites
Fill items
Owner Worker
Audit
Move / repair
Contractor
Purchase items
Code
char
/ Char
Code Slash
* /
Star /
newline Char
newline
Char Single line /
Char Comment
Slash
Comment Single line comment
/
* /
* Star
*
Comment
Char
Char
Representation of how to parse comments in C/C++ code
UML (2)
Any other Any other
value Any other
value
Value
State: Start State: Enter b b State: b
a
Null/End
of input a State: Invalid string
b
Any other
Value
UML (1)
Any other
Value