SlideShare a Scribd company logo
1152EC256 Python Programming
Unit 1 - ALGORITHMIC PROBLEM SOLVING
Welcome
You
all
Content
• Algorithms
• building blocks of algorithms (statements, state, control flow, functions),
• notation (pseudo code, flow chart, programming language)
• algorithmic problem solving
• simple strategies for developing algorithms (iteration, recursion).
• Illustrative problems:
• find minimum in a list
• insert a card in a list of sorted cards
• Guess an
• integer number in a range
• Towers of Hanoi.
PROBLEM SOLVING
• Problem solving is the 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 Techniques:
• Problem solving can be expressed in the form of
1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. programs
ALGORITHM
Algorithm
It is defined as a sequence of
instructions that describe a
method for solving a
problem.
In other words it is a step by step
procedure for solving a problem.
Properties of Algorithms
• Should be written in simple English
• Each and every instruction should be precise and
unambiguous.
• Instructions in an algorithm should not be
repeated infinitely.
• Algorithm should conclude after a finite number
of steps.
• Should have an end point
• Derived results should be obtained only after the
algorithm terminates.
Qualities of a good algorithm
• Time
• Memory
• Accuracy
• Time – To execute a program, the computer system takes
some amount of time. The lesser is the time required, the
better is the algorithm.
• Memory – To execute a program, computer system takes
some amount of memory space. The lesser is the memory
required, the better is the algorithm.
• Accuracy – Multiple algorithms may provide suitable or
correct solutions to a given problem, some of these may
provide more accurate results than others, and such
algorithms may be suitable.
Example
• Write an algorithm to print „Good Morning”
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
Algorithmic problem sloving
BUILDING BLOCKS OF ALGORITHMS
• Statements
• State
• control flow
• Functions
• Algorithms can be constructed from basic building blocks namely
• sequence,
• selection
• iteration.
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
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
1. sequence
2. selection
3. iteration
Sequence
• All the instructions are executed one after another is called sequence
execution.
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
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
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
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
Example
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
NOTATIONS
3.1.FLOW CHART
• Flow chart is defined as graphical representation of the logic for
problem solving.
• The purpose of flowchart is making the logic of the program clear in a
visual representation
Algorithmic problem sloving
Rules for drawing a flowchart
• 1. The flowchart should be clear, neat and easy to follow.
• 2. The flowchart must have a logical start and finish.
• 3. Only one flow line should come out from a process symbol.
• 4. Only one flow line should enter a decision symbol. However,
two or three flow lines may leave the decision symbol.
• 5. Only one flow line is used with a terminal symbol.
• 6. Within standard symbols, write briefly and precisely.
• 7. Intersection of flow lines should be avoided.
Advantages of flowchart
1. Communication: - Flowcharts are better way of communicating the logic
of a system to all concerned.
2. Effective analysis: - With the help of flowchart, problem can be analyzed
in more effective way.
3. Proper documentation: - Program flowcharts serve as a good program
documentation, which is needed for various purposes.
4. Efficient Coding: - The flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
5. Proper Debugging: - The flowchart helps in debugging process.
6. Efficient Program Maintenance: - The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put
efforts more efficiently on that part.
Disadvantages of flow chart
1. Complex logic: - Sometimes, the program logic is quite complicated.
In that case, flowchart becomes complex and clumsy.
2. Alterations and Modifications: - If alterations are required the
flowchart may require re-drawing completely.
3. Reproduction: - As the flowchart symbols cannot be typed,
reproduction of flowchart becomes a problem.
4. Cost: For large application the time and cost of flowchart drawing
becomes costly.
PSEUDO CODE
• Pseudo code consists of short, readable and formally styled English
languages used for explain an algorithm.
• It does not include details like variable declaration, subroutines.
• It is easier to understand for the programmer or non programmer
to understand
• the general working of the program, because it is not based on any
programming language.
• It gives us the sketch of the program before actual coding.
• It is not a machine readable
• Pseudo code can’t be compiled and executed.
• There is no standard syntax for pseudo code
Guidelines for writing pseudo code
• Write one statement per line
• Capitalize initial keyword
• Indent to hierarchy
• End multiline structure
• Keep statements language independent
Common keywords used in pseudocode
• The following gives common keywords used in pseudocodes.
• 1. //: This keyword used to represent a comment.
• 2. BEGIN,END: Begin is the first statement and end is the last statement.
• 3. INPUT, GET, READ: The keyword is used to inputting data.
• 4. COMPUTE, CALCULATE: used for calculation of the result of the given
expression.
• 5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
• 6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
• 7. IF, ELSE, ENDIF: used to make decision.
• 8. WHILE, ENDWHILE: used for iterative statements.
• 9. FOR, ENDFOR: Another iterative incremented/decremented tested
automatically.
Example
Algorithmic problem sloving
Advantages
• Pseudo is independent of any language; it can be used by most
programmers.
• It is easy to translate pseudo code into a programming language.
• It can be easily modified as compared to flowchart.
• Converting a pseudo code to programming language is very easy as
compared with converting a flowchart to programming language.
Disadvantages
• It does not provide visual representation of the program’s
logic.
• There are no accepted standards for writing pseudo codes.
• It cannot be compiled nor executed.
• For a beginner, It is more difficult to follow the logic or write
pseudo code as compared to flowchart.
• Addition of two numbers:
BEGIN
GET a,b
ADD c=a+b
PRINT c
END
Algorithm Flowchart Pseudo code
An algorithm is a sequence
of instructions used to
solve a problem
It is a graphical
representation of algorithm
It is a language
representation of
algorithm.
User needs knowledge to
write algorithm.
not need knowledge of
program to draw or
understand flowchart
Not need knowledge of
program language to
understand or write a
pseudo code.
PROGRAMMING LANGUAGE
• A programming language is a set of symbols and rules for
instructing a computer to perform specific tasks.
• The programmers have to follow all the specified rules before
writing program using programming language.
• The user has to communicate with the computer using
language which it can understand.
• Types of programming language
1. Machine language
2. Assembly language
3. High level language
Machine language
• The computer can understand only machine language which uses 0’s
and 1’s.
• In machine language the different instructions are formed by taking
different combinations of 0’s and 1’s.
Advantages
Translation free:
• Machine language is the only language which the computer
understands. For executing any program written in any
programming language, the conversion to machine language
is necessary.
• The program written in machine language can be executed
directly on computer.
• In this case any conversion process is not required.
High speed
• The machine language program is translation free. Since the
conversion time is saved, the execution of machine language
program is extremely fast
Disadvantage
• It is hard to find errors in a program written in the machine
language.
• Writhing program in machine language is a time consuming
process.
Machine dependent:
• According to architecture used, the computer differs from
each other.
• So machine language differs from computer to computer.
• So a program developed for a particular type of computer
may not run on other type of computer
Assembly language
• To overcome the issues in programming language and make
the programming process easier, an assembly language is
developed which is logically equivalent to machine language
but it is easier for people to read, write and understand.
• Assembly language is symbolic representation of machine
language.
• Assembly languages are symbolic programming language that
uses symbolic notation to represent machine language
instructions.
• They are called low level language because they are so
closely related to the machines.
• Ex: ADD a, b
• Assembler:
• Assembler is the program which translates assembly language
instruction in to a machine language.
• Advantage:
• Easy to understand and use.
• It is easy to locate and correct errors.
• Disadvantage
• Machine dependent
• Hard to learn
• Less efficient
High level language
• High level language contains English words and symbols.
• The specified rules are to be followed while writing program
in high level language.
• The interpreter or compilers are used for converting these
programs in to machine readable form.
• Translating high level language to machine language
• The programs that translate high level language in to machine
language are called interpreter or compiler.
• Compiler:
• A compiler is a program which translates the source code written in
a high level language in to object code which is in machine language
program. Compiler reads the whole program written in high level
language and translates it to machine language. If any error is found
it display error message on the screen.
• Interpreter
• Interpreter translates the high level language program in line by line
manner. The interpreter translates a high level language statement
in a source program to a machine code and executes it immediately
before translating the next statement. When an error is found the
execution of the program is halted and error message is displayed on
the screen.
Advantages
• Readability
• High level language is closer to natural language so they are easier to
learn and understand
• Machine independent
• High level language program have the advantage of being portable
between machines.
• Easy debugging
• Easy to find and correct error in high level language
• Disadvantages
• Less efficient
• The translation process increases the execution time of the program.
Programs in high level language require more memory and take
more execution time to execute.
They are divided into following categories
1. Interpreted programming languages
2. Functional programming languages
3. Compiled programming languages
4. Procedural programming languages
5. Scripting programming language
6. Markup programming language
7. Concurrent programming language
8. Object oriented programming language
Interpreted programming languages
• An interpreted language is a programming language for which
most of its implementation executes instructions directly,
without previously compiling a program into machine
language instructions.
• The interpreter executes the program directly translating each
statement into a sequence of one or more subroutines
already compiled into machine code.
• Examples:
• Pascal
• Python
Functional programming language
• Functional programming language defines every computation as a
mathematical evaluation.
• They focus on the programming languages are bound to
mathematical calculations
• Examples:
• Clean
• Haskell
Compiled Programming language
• A compiled programming is a programming language whose
implementation are typically compilers and not interpreters.
• It will produce a machine code from source code.
• Examples:
• C
• C++
• C#
• JAVA
Procedural programming language
• Procedural (imperative) programming implies specifying the
steps that the programs should take to reach to an intended
state.
• A procedure is a group of statements that can be referred
through a procedure call.
• Procedures help in the reuse of code. Procedural
programming makes the programs structured and easily
traceable for program flow.
• Examples:
• Hyper talk
• MATLAB
Scripting language
• Scripting language are programming languages that control an
application.
• Scripts can execute independent of any other application.
They are mostly embedded in the application that they
control and are used to automate frequently executed tasks
like communicating with external program.
• Examples:
• Apple script
• VB script
Markup languages:
• A markup language is an artificial language that uses annotations to
text that define hoe the text is to be displayed.
• Examples:
• HTML
• XML
Concurrent programming language:
• Concurrent programming is a computer programming technique that
provides for the execution of operation concurrently, either with in a
single computer or across a number of systems.
• Examples:
• Joule
• Limbo
Object oriented programming language:
• Object oriented programming is a programming paradigm based on
the concept of objects which may contain data in the form of
procedures often known as methods
• Examples:
• Lava
• Moto
ALGORITHMIC PROBLEM SOLVING
• Algorithmic
problem
solving is
solving
problem that
require the
formulation of
an algorithm
for the
solution.
SIMPLE STRATEGIES FOR DEVELOPING
ALGORITHMS
• 1. iterations
• 2. Recursions
Iterations
• A sequence of statements is executed until a specified
condition is true is called iterations.
• 1. for loop
• 2. While loop
Recursions
• A function that calls itself is known as recursion.
• Recursion is a process by which a function calls itself
repeatedly until some specified condition has been satisfied.
Illustrative Problems
Algorithm :
Step 1: Start
Step 2: Get a list “a”
step 3: assign the first element of the list as min
Step 4: for each element(i) in “a” go to step5 else go to step 6
Step 5: if(i<min) then min=i else go to step 4
step 6: print min value
Step 8: Stop
Minimum element in a list
Algorithmic problem sloving
step 1: Start
Step 2: get a list a
Step 3: for each element (i) in a go to step4 else go to step 8
step 4: get the index of i assign it to j and go to step 5
Step 5: while (j>0) got to step6 else go to step3
Step 6: if(a[j-1]>a[j]) then swap a[j],a[j-1] and go to step7
else go to step7
step 7:decrement j value and go to step 5
Step 8: Print the list a
Step 9: Stop
Insert a card in a list of sorted cards
Algorithmic problem sloving
Algorithmic problem sloving
Algorithmic problem sloving
step 1: Start
Step 2: Assign computer generated number as num
Step 3: Get guess value from user
Step 4: if(guess== num) then print “well-done” and got o step 8
else go to step 5
Step 5: if(guess> num) then print “too high” and go to step 7
step 6: else print “too low” and go to step 7
Step 7: if you want to guess again go to step 3 else go to step 9
Step 8: if you want to play again go to step 2 else go to step 9
Step 9: stop
Guess a integer number in a range
Flowchart
Algorithmic problem sloving
• A tower of Hanoi is a mathematical puzzle with three rods
and n number of discs.
• The mission is to move all the disks to some another tower
without violating the
• sequence of arrangement.
• A few rules to be followed for Tower of Hanoi are −
• Only one disk can be moved among the towers at any given
time.
• Only the "top" disk can be removed.
• No large disk can sit over a small disk.
Towers of Hanoi
Algorithmic problem sloving
• Steps for algorithm:
Step 1 − Move n-1 disks from source to aux
Step 2 − Move nth disk from source to dest
Step 3 − Move n-1 disks from aux to dest
• Pseudocode for tower of Hanoi
• BEGIN
• Function Hanoi (n, source, dest, aux)
• IF n == 1, THEN
• move n from source to dest
• ELSE
• Hanoi (n - 1, source, aux, dest) // Step 1
• move n from source to dest // Step 2
• Hanoi (n - 1, aux, dest, source) // Step 3
• END IF
• END Function
• END
Algorithmic problem sloving
Algorithmic problem sloving
# Recursive Python function to solve tower of hanoi
def TowerOfHanoi(n , from_rod, to_rod, aux_rod):
if n == 1:
print "Move disk 1 from rod",from_rod,"to rod",to_rod
return
TowerOfHanoi(n-1, from_rod, aux_rod, to_rod)
print "Move disk",n,"from rod",from_rod,"to rod",to_rod
TowerOfHanoi(n-1, aux_rod, to_rod, from_rod)
# Driver code
n = 4
TowerOfHanoi(n, 'A', 'C', 'B')
# A, C, B are the name of rods
Algorithmic problem sloving
Algorithmic problem sloving
Algorithmic problem sloving
Algorithmic problem sloving
Algorithmic problem sloving
Algorithmic problem sloving

More Related Content

PPTX
Recognition-of-tokens
PPT
Symbol table management and error handling in compiler design
PPTX
Demand paging
PDF
Unit 1-problem solving with algorithm
PPT
Compiler Design Basics
PPTX
Congestion control
PDF
Multithreading
PPTX
Process state in OS
Recognition-of-tokens
Symbol table management and error handling in compiler design
Demand paging
Unit 1-problem solving with algorithm
Compiler Design Basics
Congestion control
Multithreading
Process state in OS

What's hot (20)

PPTX
Chapter 10 Operating Systems silberschatz
PPT
Disk scheduling
PPTX
Critical section problem in operating system.
PDF
OS - Process Concepts
PDF
Code optimization in compiler design
PPTX
Peephole Optimization
PPT
Intermediate code generation (Compiler Design)
PPTX
Turing Machine
PPT
The process states
PDF
Memory management
PPTX
Unit 1. Problem Solving with Computer
PPTX
structured programming
PPTX
contiguous memory allocation.pptx
PPTX
And or graph
PPTX
Embedded os
PDF
Python algorithm
PPTX
Segmentation in operating systems
PPTX
Batch operating system
PDF
Cs8493 unit 2
PPT
Operating system services 9
Chapter 10 Operating Systems silberschatz
Disk scheduling
Critical section problem in operating system.
OS - Process Concepts
Code optimization in compiler design
Peephole Optimization
Intermediate code generation (Compiler Design)
Turing Machine
The process states
Memory management
Unit 1. Problem Solving with Computer
structured programming
contiguous memory allocation.pptx
And or graph
Embedded os
Python algorithm
Segmentation in operating systems
Batch operating system
Cs8493 unit 2
Operating system services 9
Ad

Similar to Algorithmic problem sloving (20)

PPT
Unit 1 python (2021 r)
PPTX
Algorithms and flow charts
PPT
C programming for Computing Techniques
PPTX
FPL -Part 2 ( Sem - I 2013)
PPT
Unit 1 psp
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PDF
Algorithm.pdf
PPTX
PROBLEM SOLVING.pptx
PPTX
FLOWCHARTS.pptx
PPTX
Introduction to problem solving Techniques
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
PPTX
introduction to problem solving and programming
PPTX
Introduction to computer programming
PPT
algorithm
PPTX
Pseudo code.pptx
PPT
Unit 1 program development cycle
PPTX
Software engineering topics,coding phase in sdlc
PPTX
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
PPTX
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
PPTX
Basic syntax : Algorithm,Flow chart
Unit 1 python (2021 r)
Algorithms and flow charts
C programming for Computing Techniques
FPL -Part 2 ( Sem - I 2013)
Unit 1 psp
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Algorithm.pdf
PROBLEM SOLVING.pptx
FLOWCHARTS.pptx
Introduction to problem solving Techniques
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
introduction to problem solving and programming
Introduction to computer programming
algorithm
Pseudo code.pptx
Unit 1 program development cycle
Software engineering topics,coding phase in sdlc
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
COMPUTING AND PROGRAMMING FUNDAMENTAL.pptx
Basic syntax : Algorithm,Flow chart
Ad

Recently uploaded (20)

PDF
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
anatomy of limbus and anterior chamber .pptx
PDF
flutter Launcher Icons, Splash Screens & Fonts
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PPTX
Soil science - sampling procedures for soil science lab
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PDF
Introduction to Data Science: data science process
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
PDF
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
classification of cubic lattice structure
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PDF
MCAD-Guidelines. Modernization of command Area Development, Guideines
PDF
Queuing formulas to evaluate throughputs and servers
PDF
Chad Ayach - A Versatile Aerospace Professional
PPTX
Ship’s Structural Components.pptx 7.7 Mb
Traditional Exams vs Continuous Assessment in Boarding Schools.pdf
AgentX UiPath Community Webinar series - Delhi
anatomy of limbus and anterior chamber .pptx
flutter Launcher Icons, Splash Screens & Fonts
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Soil science - sampling procedures for soil science lab
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Introduction to Data Science: data science process
dse_final_merit_2025_26 gtgfffffcjjjuuyy
BRKDCN-2613.pdf Cisco AI DC NVIDIA presentation
Lesson 3_Tessellation.pptx finite Mathematics
classification of cubic lattice structure
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MCAD-Guidelines. Modernization of command Area Development, Guideines
Queuing formulas to evaluate throughputs and servers
Chad Ayach - A Versatile Aerospace Professional
Ship’s Structural Components.pptx 7.7 Mb

Algorithmic problem sloving

  • 1. 1152EC256 Python Programming Unit 1 - ALGORITHMIC PROBLEM SOLVING Welcome You all
  • 2. Content • Algorithms • building blocks of algorithms (statements, state, control flow, functions), • notation (pseudo code, flow chart, programming language) • algorithmic problem solving • simple strategies for developing algorithms (iteration, recursion). • Illustrative problems: • find minimum in a list • insert a card in a list of sorted cards • Guess an • integer number in a range • Towers of Hanoi.
  • 3. PROBLEM SOLVING • Problem solving is the 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.
  • 4. PROBLEM SOLVING TECHNIQUES • Problem solving technique is a set of techniques that helps in providing logic for solving a problem. • Problem Solving Techniques: • Problem solving can be expressed in the form of 1. Algorithms. 2. Flowcharts. 3. Pseudo codes. 4. programs
  • 6. Algorithm It is defined as a sequence of instructions that describe a method for solving a problem. In other words it is a step by step procedure for solving a problem. Properties of Algorithms • Should be written in simple English • Each and every instruction should be precise and unambiguous. • Instructions in an algorithm should not be repeated infinitely. • Algorithm should conclude after a finite number of steps. • Should have an end point • Derived results should be obtained only after the algorithm terminates.
  • 7. Qualities of a good algorithm • Time • Memory • Accuracy • Time – To execute a program, the computer system takes some amount of time. The lesser is the time required, the better is the algorithm. • Memory – To execute a program, computer system takes some amount of memory space. The lesser is the memory required, the better is the algorithm. • Accuracy – Multiple algorithms may provide suitable or correct solutions to a given problem, some of these may provide more accurate results than others, and such algorithms may be suitable.
  • 8. Example • Write an algorithm to print „Good Morning” Step 1: Start Step 2: Print “Good Morning” Step 3: Stop
  • 10. BUILDING BLOCKS OF ALGORITHMS • Statements • State • control flow • Functions • Algorithms can be constructed from basic building blocks namely • sequence, • selection • iteration.
  • 11. 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
  • 12. State • Transition from one process to another process under specified condition with in a • time is called state.
  • 13. 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 1. sequence 2. selection 3. iteration
  • 14. Sequence • All the instructions are executed one after another is called sequence execution.
  • 15. 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
  • 16. 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
  • 17. 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.
  • 18. 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
  • 19. 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
  • 20. Benefits of Using Functions • Reduction in line of code • code reuse • Better readability • Information hiding • Easy to debug and test • Improved maintainability
  • 21. Example 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
  • 22. NOTATIONS 3.1.FLOW CHART • Flow chart is defined as graphical representation of the logic for problem solving. • The purpose of flowchart is making the logic of the program clear in a visual representation
  • 24. Rules for drawing a flowchart • 1. The flowchart should be clear, neat and easy to follow. • 2. The flowchart must have a logical start and finish. • 3. Only one flow line should come out from a process symbol. • 4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave the decision symbol. • 5. Only one flow line is used with a terminal symbol. • 6. Within standard symbols, write briefly and precisely. • 7. Intersection of flow lines should be avoided.
  • 25. Advantages of flowchart 1. Communication: - Flowcharts are better way of communicating the logic of a system to all concerned. 2. Effective analysis: - With the help of flowchart, problem can be analyzed in more effective way. 3. Proper documentation: - Program flowcharts serve as a good program documentation, which is needed for various purposes. 4. Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and program development phase. 5. Proper Debugging: - The flowchart helps in debugging process. 6. Efficient Program Maintenance: - The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.
  • 26. Disadvantages of flow chart 1. Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. 2. Alterations and Modifications: - If alterations are required the flowchart may require re-drawing completely. 3. Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem. 4. Cost: For large application the time and cost of flowchart drawing becomes costly.
  • 27. PSEUDO CODE • Pseudo code consists of short, readable and formally styled English languages used for explain an algorithm. • It does not include details like variable declaration, subroutines. • It is easier to understand for the programmer or non programmer to understand • the general working of the program, because it is not based on any programming language. • It gives us the sketch of the program before actual coding. • It is not a machine readable • Pseudo code can’t be compiled and executed. • There is no standard syntax for pseudo code
  • 28. Guidelines for writing pseudo code • Write one statement per line • Capitalize initial keyword • Indent to hierarchy • End multiline structure • Keep statements language independent
  • 29. Common keywords used in pseudocode • The following gives common keywords used in pseudocodes. • 1. //: This keyword used to represent a comment. • 2. BEGIN,END: Begin is the first statement and end is the last statement. • 3. INPUT, GET, READ: The keyword is used to inputting data. • 4. COMPUTE, CALCULATE: used for calculation of the result of the given expression. • 5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization. • 6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program. • 7. IF, ELSE, ENDIF: used to make decision. • 8. WHILE, ENDWHILE: used for iterative statements. • 9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
  • 32. Advantages • Pseudo is independent of any language; it can be used by most programmers. • It is easy to translate pseudo code into a programming language. • It can be easily modified as compared to flowchart. • Converting a pseudo code to programming language is very easy as compared with converting a flowchart to programming language.
  • 33. Disadvantages • It does not provide visual representation of the program’s logic. • There are no accepted standards for writing pseudo codes. • It cannot be compiled nor executed. • For a beginner, It is more difficult to follow the logic or write pseudo code as compared to flowchart.
  • 34. • Addition of two numbers: BEGIN GET a,b ADD c=a+b PRINT c END
  • 35. Algorithm Flowchart Pseudo code An algorithm is a sequence of instructions used to solve a problem It is a graphical representation of algorithm It is a language representation of algorithm. User needs knowledge to write algorithm. not need knowledge of program to draw or understand flowchart Not need knowledge of program language to understand or write a pseudo code.
  • 36. PROGRAMMING LANGUAGE • A programming language is a set of symbols and rules for instructing a computer to perform specific tasks. • The programmers have to follow all the specified rules before writing program using programming language. • The user has to communicate with the computer using language which it can understand. • Types of programming language 1. Machine language 2. Assembly language 3. High level language
  • 37. Machine language • The computer can understand only machine language which uses 0’s and 1’s. • In machine language the different instructions are formed by taking different combinations of 0’s and 1’s.
  • 38. Advantages Translation free: • Machine language is the only language which the computer understands. For executing any program written in any programming language, the conversion to machine language is necessary. • The program written in machine language can be executed directly on computer. • In this case any conversion process is not required. High speed • The machine language program is translation free. Since the conversion time is saved, the execution of machine language program is extremely fast
  • 39. Disadvantage • It is hard to find errors in a program written in the machine language. • Writhing program in machine language is a time consuming process. Machine dependent: • According to architecture used, the computer differs from each other. • So machine language differs from computer to computer. • So a program developed for a particular type of computer may not run on other type of computer
  • 40. Assembly language • To overcome the issues in programming language and make the programming process easier, an assembly language is developed which is logically equivalent to machine language but it is easier for people to read, write and understand. • Assembly language is symbolic representation of machine language. • Assembly languages are symbolic programming language that uses symbolic notation to represent machine language instructions. • They are called low level language because they are so closely related to the machines. • Ex: ADD a, b
  • 41. • Assembler: • Assembler is the program which translates assembly language instruction in to a machine language. • Advantage: • Easy to understand and use. • It is easy to locate and correct errors. • Disadvantage • Machine dependent • Hard to learn • Less efficient
  • 42. High level language • High level language contains English words and symbols. • The specified rules are to be followed while writing program in high level language. • The interpreter or compilers are used for converting these programs in to machine readable form. • Translating high level language to machine language • The programs that translate high level language in to machine language are called interpreter or compiler.
  • 43. • Compiler: • A compiler is a program which translates the source code written in a high level language in to object code which is in machine language program. Compiler reads the whole program written in high level language and translates it to machine language. If any error is found it display error message on the screen. • Interpreter • Interpreter translates the high level language program in line by line manner. The interpreter translates a high level language statement in a source program to a machine code and executes it immediately before translating the next statement. When an error is found the execution of the program is halted and error message is displayed on the screen.
  • 44. Advantages • Readability • High level language is closer to natural language so they are easier to learn and understand • Machine independent • High level language program have the advantage of being portable between machines. • Easy debugging • Easy to find and correct error in high level language • Disadvantages • Less efficient • The translation process increases the execution time of the program. Programs in high level language require more memory and take more execution time to execute.
  • 45. They are divided into following categories 1. Interpreted programming languages 2. Functional programming languages 3. Compiled programming languages 4. Procedural programming languages 5. Scripting programming language 6. Markup programming language 7. Concurrent programming language 8. Object oriented programming language
  • 46. Interpreted programming languages • An interpreted language is a programming language for which most of its implementation executes instructions directly, without previously compiling a program into machine language instructions. • The interpreter executes the program directly translating each statement into a sequence of one or more subroutines already compiled into machine code. • Examples: • Pascal • Python
  • 47. Functional programming language • Functional programming language defines every computation as a mathematical evaluation. • They focus on the programming languages are bound to mathematical calculations • Examples: • Clean • Haskell
  • 48. Compiled Programming language • A compiled programming is a programming language whose implementation are typically compilers and not interpreters. • It will produce a machine code from source code. • Examples: • C • C++ • C# • JAVA
  • 49. Procedural programming language • Procedural (imperative) programming implies specifying the steps that the programs should take to reach to an intended state. • A procedure is a group of statements that can be referred through a procedure call. • Procedures help in the reuse of code. Procedural programming makes the programs structured and easily traceable for program flow. • Examples: • Hyper talk • MATLAB
  • 50. Scripting language • Scripting language are programming languages that control an application. • Scripts can execute independent of any other application. They are mostly embedded in the application that they control and are used to automate frequently executed tasks like communicating with external program. • Examples: • Apple script • VB script
  • 51. Markup languages: • A markup language is an artificial language that uses annotations to text that define hoe the text is to be displayed. • Examples: • HTML • XML
  • 52. Concurrent programming language: • Concurrent programming is a computer programming technique that provides for the execution of operation concurrently, either with in a single computer or across a number of systems. • Examples: • Joule • Limbo
  • 53. Object oriented programming language: • Object oriented programming is a programming paradigm based on the concept of objects which may contain data in the form of procedures often known as methods • Examples: • Lava • Moto
  • 54. ALGORITHMIC PROBLEM SOLVING • Algorithmic problem solving is solving problem that require the formulation of an algorithm for the solution.
  • 55. SIMPLE STRATEGIES FOR DEVELOPING ALGORITHMS • 1. iterations • 2. Recursions
  • 56. Iterations • A sequence of statements is executed until a specified condition is true is called iterations. • 1. for loop • 2. While loop
  • 57. Recursions • A function that calls itself is known as recursion. • Recursion is a process by which a function calls itself repeatedly until some specified condition has been satisfied.
  • 59. Algorithm : Step 1: Start Step 2: Get a list “a” step 3: assign the first element of the list as min Step 4: for each element(i) in “a” go to step5 else go to step 6 Step 5: if(i<min) then min=i else go to step 4 step 6: print min value Step 8: Stop Minimum element in a list
  • 61. step 1: Start Step 2: get a list a Step 3: for each element (i) in a go to step4 else go to step 8 step 4: get the index of i assign it to j and go to step 5 Step 5: while (j>0) got to step6 else go to step3 Step 6: if(a[j-1]>a[j]) then swap a[j],a[j-1] and go to step7 else go to step7 step 7:decrement j value and go to step 5 Step 8: Print the list a Step 9: Stop Insert a card in a list of sorted cards
  • 65. step 1: Start Step 2: Assign computer generated number as num Step 3: Get guess value from user Step 4: if(guess== num) then print “well-done” and got o step 8 else go to step 5 Step 5: if(guess> num) then print “too high” and go to step 7 step 6: else print “too low” and go to step 7 Step 7: if you want to guess again go to step 3 else go to step 9 Step 8: if you want to play again go to step 2 else go to step 9 Step 9: stop Guess a integer number in a range
  • 68. • A tower of Hanoi is a mathematical puzzle with three rods and n number of discs. • The mission is to move all the disks to some another tower without violating the • sequence of arrangement. • A few rules to be followed for Tower of Hanoi are − • Only one disk can be moved among the towers at any given time. • Only the "top" disk can be removed. • No large disk can sit over a small disk. Towers of Hanoi
  • 70. • Steps for algorithm: Step 1 − Move n-1 disks from source to aux Step 2 − Move nth disk from source to dest Step 3 − Move n-1 disks from aux to dest • Pseudocode for tower of Hanoi • BEGIN • Function Hanoi (n, source, dest, aux) • IF n == 1, THEN • move n from source to dest • ELSE • Hanoi (n - 1, source, aux, dest) // Step 1 • move n from source to dest // Step 2 • Hanoi (n - 1, aux, dest, source) // Step 3 • END IF • END Function • END
  • 73. # Recursive Python function to solve tower of hanoi def TowerOfHanoi(n , from_rod, to_rod, aux_rod): if n == 1: print "Move disk 1 from rod",from_rod,"to rod",to_rod return TowerOfHanoi(n-1, from_rod, aux_rod, to_rod) print "Move disk",n,"from rod",from_rod,"to rod",to_rod TowerOfHanoi(n-1, aux_rod, to_rod, from_rod) # Driver code n = 4 TowerOfHanoi(n, 'A', 'C', 'B') # A, C, B are the name of rods