SlideShare a Scribd company logo
3
Most read
4
Most read
6
Most read
UNIT I
Building Blocks of Algorithms
Dr. Nisha Soms, AP(Sr.Gr.)/CSE
UCSG004 Python Programming for Engineers
PROBLEM SOLVING
 Problem solving is a systematic approach to define the
problem and creating number of solutions.
 The problem solving process starts with the problem
specifications and ends with a correct program.
PROBLEM SOLVING TECHNIQUES
 Problem solving technique is a set of techniques that helps in
providing logic for solving a problem.
 Problem solving can be expressed in the form of
1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. Programs
18-01-2024
2
THE PROBLEM SOLVING ASPECT
18-01-2024
3
 Is a creative process that involves the following
phases
 Problem Definition Phase
 Getting started on a problem
 The use of specific examples
 Similarities among problems
 Working backwards from solutions
ALGORITHMS
 An algorithm is a procedure consisting of a finite set of
unambiguous rules (instructions) which specify a finite
sequence of operations that provides the solution to a
problem.
OR
 A sequence of activities to be processed for getting
desired output from a given input.
OR
 Formal Definition: An algorithm is a finite number of
clearly described, unambiguous “double” steps that can
be systematically followed to produce a desired result for
the given inputs in a finite amount of time.
18-01-2024
4
ALGORITHMS
18-01-2024
5
 Convert temperature Fahrenheit to Celsius
 Inputs to the algorithm: Temperature in Fahrenheit
 Expected output: Temperature in Celsius
 Algorithm:
 Step1: Start
 Step 4: Read Temperature in Fahrenheit F
 Step 2: C = 5/9*(F*32)
 Step 3: Print Temperature in Celsius: C
 Step5: End
BUILDING BLOCKS OF ALGORITHMS/TYPES
18-01-2024
6
Building Block Common name
Sequence Action
Selection Decision
Iteration Repetition or Loop
 In a sequence structure, an action, or event, leads to the next
ordered action in a predetermined order.
 In a selection structure, a question is asked, and depending on the
answer, the program takes one of two courses of action, after which
the program moves on to the next event
 An iteration is a single pass through a group/set of instructions. Most
programs often contain loops of instructions that are executed over
and over again.
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
7
 Statements:
 Statement is a single action in a computer.
 In a computer statements might include some of the
following actions
 input data-information given to the program
 process data-perform operation on a given input
 output data-processed result
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
8
 State:
 Transition from one process to another process
under specified condition with in a time is called
state.
 Control flow:
 The process of executing the individual statements
in a given order is called control flow.
 The control can be executed in three ways
 Sequence
 Selection
 Iteration
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
9
 Sequence:
 All the instructions are executed one after another is
called sequence execution.
 Example:
Add two numbers:
Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
10
 Selection:
 A selection statement causes the program control to be
transferred to a specific part of the program based upon
the condition.
 If the conditional test is true, one part of the program will
be executed, otherwise it will execute the other part of
the program.
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
11
 Example
Write an algorithm to check whether he is eligible
to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
12
 Iteration:
 In some programs, certain set of statements are executed again and
again based upon conditional test. i.e. executed more than one time.
This type of execution is called looping or iteration.
 Example
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: go to step 4
Step 7: Stop
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
13
 Functions:
 Function is a sub program which consists of block of
code(set of instructions) that performs a particular task.
 For complex problems, the problem is been divided into
smaller and simpler tasks during algorithm design.
 Benefits of Using Functions
 Reduction in line of code
 code reuse
 Better readability
 Information hiding
 Easy to debug and test
 Improved maintainability
BUILDING BLOCKS OF ALGORITHMS
(statements, state, control flow, functions)
18-01-2024
14
 Algorithm for addition of
two numbers using
function
 Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop

 sub function add()
Step 1: Function start
Step 2: Get a, b Values
Step 3: add c=a+b
Step 4: Print c
Step 5: Return
THANK YOU
18-01-2024
15

More Related Content

PPTX
Maximum sum subarray
PDF
Sets automata
PDF
27 NP Completness
PPT
Set in discrete mathematics
PPTX
Fundamental principle of counting -Discrete Mathematics
PPS
Applications of linear programming
PDF
Dynamic Programming knapsack 0 1
PPTX
UNIT-1.pptx python for engineering first year students
Maximum sum subarray
Sets automata
27 NP Completness
Set in discrete mathematics
Fundamental principle of counting -Discrete Mathematics
Applications of linear programming
Dynamic Programming knapsack 0 1
UNIT-1.pptx python for engineering first year students

Similar to Building blocks of Algblocks of Alg.pptx (20)

PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PPTX
Data Structures_Introduction to algorithms.pptx
PDF
GE8151 notes pdf.pdf
PDF
Introduction to Problem Solving Techniques- Python
PDF
Unit 1-problem solving with algorithm
PPT
Unit 1 python (2021 r)
PPTX
building blocks of algorithm.pptx
PPTX
UNIT I.pptxpython unit 1 engineering full unit completed
PPSX
Algorithm and flowchart
PDF
Algorithmic problem sloving
PPTX
Introduction to problem solving Techniques
PPTX
PROBLEM SOLVING.pptx
PPTX
1 Introduction to C Programming.pptx
DOCX
Algorithm design and problem solving
PPT
Programs_Problem_Solving_Algorithms.ppt
PPTX
asic computer is an electronic device that can receive, store, process, and o...
PPTX
UNIT 1.pptx
PPT
Unit 1 psp
PPT
Chapter 1.ppt
PPTX
Algorithm and flowchart
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Data Structures_Introduction to algorithms.pptx
GE8151 notes pdf.pdf
Introduction to Problem Solving Techniques- Python
Unit 1-problem solving with algorithm
Unit 1 python (2021 r)
building blocks of algorithm.pptx
UNIT I.pptxpython unit 1 engineering full unit completed
Algorithm and flowchart
Algorithmic problem sloving
Introduction to problem solving Techniques
PROBLEM SOLVING.pptx
1 Introduction to C Programming.pptx
Algorithm design and problem solving
Programs_Problem_Solving_Algorithms.ppt
asic computer is an electronic device that can receive, store, process, and o...
UNIT 1.pptx
Unit 1 psp
Chapter 1.ppt
Algorithm and flowchart
Ad

More from NISHASOMSCS113 (18)

PPTX
CN module for the fourth od momodule.ppt
PPTX
CN module for the second od momodule.ppt
PPTX
CN module for the first mod momodule.ppt
PPT
Foundation of computerr nnetworks strong
PPT
Data and Signals ppt in physical layersn
PPTX
Assymmetric Cryptosystem in cryptography
PPT
Data communications and networking basics
PPT
Data Transmission chapter from stallings
PDF
U21CS502--Compiler Design--Question Bank
PPT
dokumen.tips_1-cryptography-and-network-security-third-edition-by-william-sta...
PPTX
Unit 1.pptx
PPTX
Exception handling.pptx
PPTX
Introduction to Information Storage.pptx
PPT
recursion.ppt
PPTX
social.pptx
PPTX
Data Management.pptx
PPT
intro to sna.ppt
PPT
intro.ppt
CN module for the fourth od momodule.ppt
CN module for the second od momodule.ppt
CN module for the first mod momodule.ppt
Foundation of computerr nnetworks strong
Data and Signals ppt in physical layersn
Assymmetric Cryptosystem in cryptography
Data communications and networking basics
Data Transmission chapter from stallings
U21CS502--Compiler Design--Question Bank
dokumen.tips_1-cryptography-and-network-security-third-edition-by-william-sta...
Unit 1.pptx
Exception handling.pptx
Introduction to Information Storage.pptx
recursion.ppt
social.pptx
Data Management.pptx
intro to sna.ppt
intro.ppt
Ad

Recently uploaded (20)

PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Trump Administration's workforce development strategy
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Introduction to Building Materials
PDF
Empowerment Technology for Senior High School Guide
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
Unit 4 Skeletal System.ppt.pptxopresentatiom
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Supply Chain Operations Speaking Notes -ICLT Program
A systematic review of self-coping strategies used by university students to ...
Trump Administration's workforce development strategy
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Paper A Mock Exam 9_ Attempt review.pdf.
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Introduction to Building Materials
Empowerment Technology for Senior High School Guide
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
Unit 4 Skeletal System.ppt.pptxopresentatiom
Orientation - ARALprogram of Deped to the Parents.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Chinmaya Tiranga quiz Grand Finale.pdf
Computing-Curriculum for Schools in Ghana
LDMMIA Reiki Yoga Finals Review Spring Summer
UNIT III MENTAL HEALTH NURSING ASSESSMENT

Building blocks of Algblocks of Alg.pptx

  • 1. UNIT I Building Blocks of Algorithms Dr. Nisha Soms, AP(Sr.Gr.)/CSE UCSG004 Python Programming for Engineers
  • 2. PROBLEM SOLVING  Problem solving is a systematic approach to define the problem and creating number of solutions.  The problem solving process starts with the problem specifications and ends with a correct program. PROBLEM SOLVING TECHNIQUES  Problem solving technique is a set of techniques that helps in providing logic for solving a problem.  Problem solving can be expressed in the form of 1. Algorithms. 2. Flowcharts. 3. Pseudo codes. 4. Programs 18-01-2024 2
  • 3. THE PROBLEM SOLVING ASPECT 18-01-2024 3  Is a creative process that involves the following phases  Problem Definition Phase  Getting started on a problem  The use of specific examples  Similarities among problems  Working backwards from solutions
  • 4. ALGORITHMS  An algorithm is a procedure consisting of a finite set of unambiguous rules (instructions) which specify a finite sequence of operations that provides the solution to a problem. OR  A sequence of activities to be processed for getting desired output from a given input. OR  Formal Definition: An algorithm is a finite number of clearly described, unambiguous “double” steps that can be systematically followed to produce a desired result for the given inputs in a finite amount of time. 18-01-2024 4
  • 5. ALGORITHMS 18-01-2024 5  Convert temperature Fahrenheit to Celsius  Inputs to the algorithm: Temperature in Fahrenheit  Expected output: Temperature in Celsius  Algorithm:  Step1: Start  Step 4: Read Temperature in Fahrenheit F  Step 2: C = 5/9*(F*32)  Step 3: Print Temperature in Celsius: C  Step5: End
  • 6. BUILDING BLOCKS OF ALGORITHMS/TYPES 18-01-2024 6 Building Block Common name Sequence Action Selection Decision Iteration Repetition or Loop  In a sequence structure, an action, or event, leads to the next ordered action in a predetermined order.  In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event  An iteration is a single pass through a group/set of instructions. Most programs often contain loops of instructions that are executed over and over again.
  • 7. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 7  Statements:  Statement is a single action in a computer.  In a computer statements might include some of the following actions  input data-information given to the program  process data-perform operation on a given input  output data-processed result
  • 8. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 8  State:  Transition from one process to another process under specified condition with in a time is called state.  Control flow:  The process of executing the individual statements in a given order is called control flow.  The control can be executed in three ways  Sequence  Selection  Iteration
  • 9. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 9  Sequence:  All the instructions are executed one after another is called sequence execution.  Example: Add two numbers: Step 1: Start Step 2: get a,b Step 3: calculate c=a+b Step 4: Display c Step 5: Stop
  • 10. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 10  Selection:  A selection statement causes the program control to be transferred to a specific part of the program based upon the condition.  If the conditional test is true, one part of the program will be executed, otherwise it will execute the other part of the program.
  • 11. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 11  Example Write an algorithm to check whether he is eligible to vote? Step 1: Start Step 2: Get age Step 3: if age >= 18 print “Eligible to vote” Step 4: else print “Not eligible to vote” Step 6: Stop
  • 12. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 12  Iteration:  In some programs, certain set of statements are executed again and again based upon conditional test. i.e. executed more than one time. This type of execution is called looping or iteration.  Example Write an algorithm to print all natural numbers up to n Step 1: Start Step 2: get n value. Step 3: initialize i=1 Step 4: if (i<=n) go to step 5 else go to step 7 Step 5: Print i value and increment i value by 1 Step 6: go to step 4 Step 7: Stop
  • 13. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 13  Functions:  Function is a sub program which consists of block of code(set of instructions) that performs a particular task.  For complex problems, the problem is been divided into smaller and simpler tasks during algorithm design.  Benefits of Using Functions  Reduction in line of code  code reuse  Better readability  Information hiding  Easy to debug and test  Improved maintainability
  • 14. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) 18-01-2024 14  Algorithm for addition of two numbers using function  Main function() Step 1: Start Step 2: Call the function add() Step 3: Stop   sub function add() Step 1: Function start Step 2: Get a, b Values Step 3: add c=a+b Step 4: Print c Step 5: Return