You are on page 1of 29

GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

UNIT I
ALGORITHMIC PROBLEM SOLVING
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 STRATEGIES:


 Requirements analysis - User‟s expectations are gathered to know build the software
 Design phase - a plan of action is made before the actual development process
 Implementation phase - the designed algorithms are converted into program code using any of the
high-level languages
 Testing - all the modules are tested together to ensure that the overall system works well as a
whole product
 Software deployment phase - the software is installed or deployed in the production environment
 Maintenance - enhancements are done to cope with newly discovered problems or new
requirements

M.Kiruthika [AP/CSE] Page 1


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

DESIGN TOOLS:
 Program – is a set of instructions that tells the computer as how to solve a particular problem
 Design tools are used to design a blueprint of the program
 Various design tools are
o Algorithms
o Flowchart
o Pseudocodes

ALGORITHMS:
 An algorithm is a well-defined computational procedure consisting of a set of instructions that
takes some value as input, and produces some value as output.
 It is a blueprint of a program that contains sequence of instructions
 It gives the logic of the program in a finite, step – by – step fashion
 Use – Software Reuse
Characteristics of Algorithm:
 Precise – Each instruction should be precise
 Unique – Each instruction should be unique
 Finite – No instruction must be repeated infinitely
 Effective – Algorithm should be effective in terms of memory and time
 Input – Must receive an input
 Output – Must produce a output
 Generality – Should work for various set of inputs
Qualities of an Algorithm:
Qualities of an Algorithm are determined by
 Accuracy – should produce accurate results
 Time – should consume less time to run
 Space – should consume less memory space

M.Kiruthika [AP/CSE] Page 2


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

BUILDING BLOCKS OF ALGORITHMS:


 The building blocks of an Algorithm are
o State
o Instructions / Statements
o Control Flow
o Functions
1. STATE:
 Refers to the current state of processing in the algorithm.
o E.g: Initial State – algorithm starts by getting input from the user
o Final State – algorithm produce final output
o Processing State – algorithm process the given input
2. INSTRUCTIONS / STATEMENTS:
 Commands given to the computer to perform specific tasks
 A program consists of set of instructions
 The instructions / statements can be categorized as
o Simple statements – Used by sequence control structure. Eg: a = 5, Read the input, etc.
o Compound statements – Used by decision and looping control structures.
3. CONTROL FLOW
 It is the order in which the instructions are executed. E.g: Sequence, Decision, Iteration or
Looping, Recursion
Sequence
 Each step of the algorithm is executed in the specified order
 Example:
Step 1 : Start
Step 2 : Input first number as A
Step 3 : Input second number as B
Step 4 : Set Sum = A + B
Step 5 : Print Sum
Step 6 : End
Decision
 Used when the outcome of the process depends on some condition

M.Kiruthika [AP/CSE] Page 3


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

IF condition then process


 Produce results as either “True” or “False”
 Other form of decision statement is
IF condition then process1
ELSE process 2
 Example:
Step 1 : Start
Step 2 : Input first number as A
Step 3 : Input second number as B
Step 4 : IF A = B
print “Equal”
ELSE
print “Not Equal”
Step 6 : End
Repetition
 Executes one or more steps for a number of times
 These are implemented using looping statements such as the while, do-while, and for loops
 Loops are executed until some condition is true
 Example:
Step 1 : Start
Step 2 : Set I = 1, N = 10
Step 3 : Repeat steps 3 & 4 while I < = N
Step 4 : Print I
Step 5 : Set I = I + 1
Step 6 : End
Recursion
 Involves a function calling itself repeatedly until a specified condition is met
 Makes use of stack to store temporary variables and return address
 Example:
Step 1 : Start
Step 2 : Input number as n

M.Kiruthika [AP/CSE] Page 4


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

Step 3 : call factorial (n)


Step 4 : End
factorial (n)
Step 1 : Set f = 1
Step 2 : IF n = = 1 then return 1
ELSE Set f = n * factorial (n – 1)
Step 3: Print f

RECURSION ITERATION

It a method in which the function calls itself It is a method in which certain part of code is
again and again until the condition is satisfied repeated using loops

Recursion is considered as another copy of the


Iteration is performed inside loops and so,
function and so, considerable memory space is
extra memory space is not assigned
occupied

Popular examples of recursion are Towers of Examples of iteration include Printing first n
Hanoi, Factorial of a number, Eight Queens Natural numbers, Fibonacci series, Sum of
problem, etc digits, etc.

4. FUNCTIONS
 They are self contained modules of code that takes input and returns a output
 It can be called any number of times. That is, when a function is written it can be called any
number of times
 The functions change the flow of control of a program
 When a function is called, the current flow is switched to the function. Once the function gets
executed, the flow returns back to the next line of code
 Have two parameters – Actual and Formal parameter
o Actual Parameter – the list of parameters actually passed during the function call
o Formal Parameter – acts as a placeholder for the actual parameters during function
definition
 Advantages – Reduce memory by providing code reusability

M.Kiruthika [AP/CSE] Page 5


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

DIFFERENT APPROACHES OF AN ALGORITHM:


 Modularizations - Complex problems are divided into modules (or functions) to solve easily
 Advantages of Modularizations are
o Makes algorithm easier & simpler
o Independence of functions
 Two main approaches to design an algorithm are
o Top-down approach
o Bottom-up approach

M.Kiruthika [AP/CSE] Page 6


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

TOP – DOWN APPROACH BOTTOM – UP APPROACH

Starts by designing the most basic or concrete


Starts by dividing the complex algorithm into one
modules and then proceed towards designing
or more modules
higher level modules
Iterated until desired level of module complexity is Repeated until the design of the complete
achieved algorithm is obtained
High level functions are decomposed into one or Groups several low level functions to form a high
more low level functions level function
Mainly used in documentation, generating test
Mainly used in testing
cases, implementation and debugging

Information Hiding is ignored Information Hiding is allowed

Procedural programming languages like C, Object Oriented programming languages like C++,
FORTRAN, etc., follow this approach JAVA, etc., follow this approach

ALGORITHMIC PROBLEM SOLVING STEPS:


 Understanding the problem
 Determining the capabilities of Computational device
 Exact / Approximate solution
 Selecting the appropriate Data structure
 Algorithm design techniques
 Methods of Specifying the algorithm
 Proving the algorithm correctness
 Analysing the Performance of an algorithm

M.Kiruthika [AP/CSE] Page 7


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

Understanding the problem


 Before designing the algorithm the problem complexity must be understood
 Problem should be clearly and completely understood
Determining the capabilities of Computational device
 After understanding the problem, the capabilities of the computing device are noted
 The capabilities include type of computer architecture, speed and memory
 Depending on the device‟s capability, the algorithm can be designed either for sequential
operation or parallel operation
Exact / Approximate solution
 Algorithm must produce exact output for all possible or legitimate input
 This solution can be an exact or appropriate solution
 For few problems, it is difficult to derive an exact solution. In such cases, only appropriate
solution can be derived. Eg: Finding Square root
Selecting the appropriate Data structure
 Data structure is a scheme of organizing related data elements under one name

M.Kiruthika [AP/CSE] Page 8


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

 It provides a way to store and organize the data in a computer for efficient use
 Few examples of data structure are Lists, Arrays, Files, Dictionaries, Sets, etc
Algorithm design techniques
 A problem can be solved in various techniques
 The technique that gives accurate solution by consuming less time and memory is chosen finally
 Various algorithm design techniques exist. Examples: Brute force method, Divide and Conquer
method, Greedy method, Dynamic programming, etc
 Hence an appropriate algorithm design technique has to be devised out for the problem
Methods of Specifying the algorithm
 Once the algorithm is designed, it can be specified either by using any natural language or with
the help of pseudocode / flowchart
 This specification must be in step by step fashion
Proving the algorithm correctness
 After writing the algorithm, it has to be validated
 Validation ensures that the algorithm works correctly for all sets of possible inputs in a finite
amount of time irrespective of the programming language
Analysing the Performance of an algorithm
 An algorithm is analysed for its performance based on its consumption of CPU time and memory
space
 Time efficiency refers to how fast the algorithm can execute while Space efficiency measures
how small memory the algorithm needs for execution

ADVANTAGES:
 Makes the problem representation easier
 Follows a finite procedure
 Even a non – programmer can understand the algorithm

LIMITATIONS:
 Time Consuming to write algorithm
 It does not reduce the difficulties of writing code

M.Kiruthika [AP/CSE] Page 9


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

FLOWCHARTS:
 Flowchart is a graphical or symbolic representation of a process.
 Users can visualize the processing / logic of the problem
 Provides better and easy understanding
 Follows top – down approach in problem solving
 Each step of the program is depicted using different symbols
 The symbols are connected using arrows to depict the logic flow
 Symbols used in flowchart are as follows:

SYMBOL NAME FUNCTION

o Represented using ovals or rounded


START and END Symbols / rectangles
Terminal Symbols o Indicates the starting and ending of a
program / process.

o Represented using rectangles


Process / Activity Symbol o Indicates arithmetic and data movement
operations

o Represented using diamond


Decision / Conditional o Indicates decision statements – true / false
Symbol o Arrows going in and coming out will have
labels

o Represented using parallelogram


Input / Output Symbols o Used to get input from user or to display
output

o Acts as a marker for some other process


Pre-defined process Symbol o Indicates sub – processes or sub –
routines

M.Kiruthika [AP/CSE] Page 10


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

o Represented using circle


o Used when flowchart spans multiple
Connector Symbol sheets
o Has a label inside and are normally
represented in pairs

o Indicates the control flow and the exact


Arrows
sequence of instruction execution

FLOWCHARTS FOR CONTROL STRUCTURES:


 Flowchart to represent sequence structure

M.Kiruthika [AP/CSE] Page 11


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

 Flowchart to represent decision structure

 Flowchart to represent looping structure

M.Kiruthika [AP/CSE] Page 12


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

EXAMPLES:
1. Flowchart to calculate sum of first 10 natural numbers

2. Flowchart to add two numbers.

M.Kiruthika [AP/CSE] Page 13


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

3. Flowchart to find the largest of 3 numbers.

RULES FOR DRAWING A FLOWCHART:


 Must have Start and Stop symbol
 Each symbol should have an Entry point and an Exit point
 The decision symbol have one Entry point and two exit points
 Try to draw the flowchart in one page
 Usual direction flow is fro left to right and top to bottom
 Should be clear, neat and easy to follow
 Connector symbols can be used instead of multiple flow lines

M.Kiruthika [AP/CSE] Page 14


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

ADVANTAGES:
 Good communication tools
 Used for documentation
 Act as guide or blueprint
 Helps programmers to identify and correct mistakes
 Aids the programmers in knowing the sequence

LIMITATIONS:
 Laborious & Time Consuming
 Difficult to represent a complex task
 Small change in program may lead to complete redrawing of flowchart
 No specific standards

PSEUDOCODES:
 It is a compact and informal high-level description of an algorithm
 It uses the structural conventions of a programming language
 An ideal pseudocode must be
o Complete - describing the entire logic of the algorithm
o Human readable
o Easy to translate into program

RULES FOR WRITING PSEUDOCODE:


 Write only one statement per line – each statement must exhibit one task
 Capitalize initial keywords like READ, WRITE, IF, ELSE, ENDIF, WHILE, END WHILE,
REPEAT, UNTIL, etc.
 Follow an indentation pattern to show the control structure used. The control structure may be
Sequence, Looping or Decision
 End the control structures used. Eg: ENDIF ends the IF statement
 Use the features of the programming language that is to be used for program

M.Kiruthika [AP/CSE] Page 15


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

NOTATIONS TO WRITE THE PSEUDOCODE:


 Receive information from the user / file using GET / READ
 Display the information using WRITE / DISPLAY
 Use actual Arithmetic symbols / words like CALCULATE, COMPUTE, ADD, etc.
 To assign value to a variable, use Initialize, Set, =
 Conditional statements can be given as
IF condition THEN
some actions
ELSE
alternative actions
ENDIF

WHILE condition is true


some actions
ENDWHILE

FOR a number of times


some actions
ENDFOR

ADVANTAGES:
 Makes reviewing an easier task
 Modifications can be easily done
 Easier to maintain than other documenting standards
 Reduced complexity
 No special symbols are used
 Very easy to translate pseudocode to high level language

DISADVANTAGES:
 There is no visual representation
 No specific standards are followed to write a pseudocode
M.Kiruthika [AP/CSE] Page 16
GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

EXAMPLES:
1. Write a pseudocode to calculate the price of the product.

.
2. Write a pseudocode to print the first n natural numbers.
Solution
1. Read n
2. Initialise i to 1
3. While i<=n, do:
Write i.
Increment i
End while

3. Write a pseudocode to print the first n natural numbers.


Solution
1. Read n
2. Initialise i to 1
3. While i<=n, do:
Increase sum by i
Increment i
End while
4. Write sum

M.Kiruthika [AP/CSE] Page 17


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

4. Write a pseudocode to print the Fibonacci series.


Solution
1. Read n
2. Declare an integer variable Sum
3. Declare an integer variable f1
4. Declare an integer variable f2
5. Set sum = 0
6. Set f1 and f2 to 1
7. Set n to 50
8. Repeat n times
a) sum = f1 + f2
b) f2 = f1
c) f1 = Sum
d) Display sum
Endloop

ALGORITHM FLOWCHART PSEUDOCODE

Step by step instructions to solve Diagrammatic representation of Detailed description of what a


the problem the problem computer program will do
Sequence of instruction flow is Implements the structured
Data flow is very clear
specified concept well
Bit difficult for a layman to It is not visual and hence difficult
Easy to understand
understand to understand
Only text is used to specify the Different symbols are used for Expressed as a formal styled
process different tasks natural language

Easy to make modifications Difficult to make modifications Can be easily modified

Difficult compared with drawing


Easy to draw flowchart Difficult to write pseudocode
flowchart

M.Kiruthika [AP/CSE] Page 18


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

No rules are followed to write Follow certain rules and


Follows few rules
algorithms notations

PROGRAMMING LANGUAGES:
 Once the algorithm is designed, it is essential to code the algorithms. The language used for
coding is called programming language
 Program is a set of instructions that instruct the computer to perform a specified task and a
program may be written using any programming language
 There are three types of Programming languages
1. Machine language
2. Assembly language
3. High Level language
 Machine and Assembly languages are low level languages
1. MACHINE LANGUAGE:
 It is language that is understood by the computer directly without a need of a translator
 It consists of 0s and 1s
Pros:
 Since it does not need a translator, it executes quickly
 Memory is used efficiently
Cons:
 It is very hard to write programs using 0s and 1s
 It is difficult find errors and debug
 It consumes more time to write a program in machine language
 No human readability
2. ASSEMBLY LANGUAGE:
 It is language that uses mnemonic codes instead of 0s and 1s
 Example of mnemonic codes are ADD, SUB
 Assemblers are needed to translate assembly language programs to machine language program
Pros:
 Easier to write, read and understand compared to machine language

M.Kiruthika [AP/CSE] Page 19


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

 Errors can be identified and debugged easily compared with ML


 Programs can be written faster compared with ML
Cons:
 It requires translators as it is not directly understood by the computer
 AL programs are machine dependent. Hence does not support portability
 Programmers must remember the mnemonic codes to write the program
3. HIGH LEVEL LANGUAGE (HLL):
 Each of the HLL have specific set of keywords, syntax and semantics
 Few examples of HLL include: BASIC, C, C ++, Java, Python, Pascal, FORTRAN, etc.
 This language uses English like words and mathematical notations to perform a task
 HLL programs are converted to machine language using two translators – Interpreter and
Compiler
Pros:
 Easy to understand
 Human readable, Simple, Flexible, Robust, Portable
 Easy to detect and correct Errors
 Consumes less time to write a HLL program
Cons:
 Consumes more time to execute compared with AL and ML
 Needs a translator

SELECTING A PROGRAMMING LANGUAGE:


 There are numerous PL available, each with its own merits and demerits
 Certain factors are considered for selecting a language. They are:
o Type of hardware and software for executing the program
o Type of program
o Expertise of programmers
o Features to be included
o Lower development and maintenance cost
o Reliability, Stability, Capability, Elasticity and Portability
o Domain of the application development
M.Kiruthika [AP/CSE] Page 20
GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

ILLUSTRATIVE PROBLEMS:
1. FIND MINIMUM IN A LIST
Problem Statement:
 To find the minimum number in a given list of numbers
Solution:
 Count of the numbers in the list is received from the user
 Numbers in the list is given by the user
 Consider the first number in the list as minimum number
 Compare this number with all numbers
 If another number is less than the minimum number, set this new number as minimum number
and do the same process until all numbers are compared and minimum is found
Algorithm:
Step 1: Start
Step 2: Read the count of numbers in list as N
Step 3: Set I = 0
Step 4: Set the first element in the list as MIN
Step 5: Repeat steps 6 to 8 until I < N
Step 6: Read the next number as NUM
Step 7: If NUM < MIN then set MIN = NUM
Step 8: Increment I
Step 9: Print MIN
Step 10: End
Pseudocode:
1. READ the count of numbers in list as N
2. SET I = 0
3. SET LIST[I] as MIN
4. WHILE I < N
READ the next number as LIST[I]
IF LIST[I] < MIN
MIN = LIST[I]
I=I+1

M.Kiruthika [AP/CSE] Page 21


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

END WHILE
5. WRITE MIN
Variables: N, I, MIN, NUM

Flowchart:

Start

Read the count


of numbers in a
list as N

I = 0, MIN = LIST [I]

No
Is I < N?

Yes
Read the next
element in list
as LIST [I]

No MIN = LIST
Is LIST [I] < MIN?
[I]

Yes

I=I+1

PRINT
MIN

End

M.Kiruthika [AP/CSE] Page 22


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

2. INSERT A CARD IN A LIST OF SORTED CARDS:


Problem Statement:
• To insert a card in a sorted list of cards
Solution:
• Count of the numbers of elements in the list
• Get the new element that is to be inserted
• Insert the new element by pushing the old element
• Ensure that the new element is inserted in the right place
Algorithm:
Step 1: Start
Step 2: Read the number of elements in sorted list as N
Step 3: Set I = 0, J=0
Step 4: Repeat steps 5 to 6 until I < N
Step 5: Read the element in sorted order as LIST[I]
Step 6: Increment I
Step 7: Read the element to be inserted as X
Step 8: Repeat steps 9 to 10 until J < N and X < LIST[J]
Step 9: LIST [J + 1] = LIST [J]
Step 10: Increment J
Step 11: LIST [J+1] = X
Step 12: End
Pseudocode:
1. READ the number of elements in sorted list as N
2. SET I = 0, J=0
3. WHILE I < N
READ the element in sorted order as LIST[I]
I=I+1
END WHILE
4. READ the element to be inserted as X
5. WHILE J < N and X < LIST[J]
LIST [J + 1] = LIST [J]

M.Kiruthika [AP/CSE] Page 23


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

J=J+1
END WHILE
6. LIST [J+1] = X
Variables: N, I, J, LIST, X

Flowchart:

Start

Read the
number of
elements as N

I = 0, J = 0

Read the
Yes elements in
Is I < N?
sorted list as
LIST [I]
No
Read the
I=I+1
elements in
sorted list as
LIST [I]

Is J < N and Yes LIST[J + 1] = LIST


X<LIST[J]? [J]

No
LIST [J + 1] J=J+1
=X

End

M.Kiruthika [AP/CSE] Page 24


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

3. GUESS AN INTEGER NUMBER IN A RANGE:


Problem Statement:
• User has to guess the number, that is randomly generated by the computer
• There is no upper limit on the number of guesses that can be made
Solution:
• Include functions to generate a random number
• Prompt the user for a number
• If there is a match between computer generated and user generated number then the user guess is
correct
• Otherwise the computer will give a clue specifying that the guessed number is high or low
Algorithm:
Step 1: Start
Step 2: Read the range of numbers as N
Step 3: Set X as randomly generated number between 1 and N
Step 4: Set the user given number as NUM
Step 5: If X and NUM are equal, then print “You win” and go to Step 8
Step 6: If X < NUM, then print “Value is too low….Play again” and go to Step 4
Step 7: If X > NUM, then print “Value is too high….Play again” and go to Step 4
Step 8: End
Pseudocode:
1. READ the range of numbers as N
2. SET X as randomly generated number between 1 and N
3. SET the user given number as NUM
4. IF X = = NUM
print “You win”
ELSE IF X < NUM
print “Value is too low….Play again”
ELSE
print “Value is too high….Play again”
END IF
Variables: N, X, NUM

M.Kiruthika [AP/CSE] Page 25


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

Flowchart:

Start

Read the
range of
numbers as N

X = random number
generated between 1
and N

NUM = number
guesses by the user

Yes
Print “You
Is X = = NUM?
Win”

No
Yes Print “Value
Is X = = NUM? is too low..
Play Again”
No

Print “Value
is too high..
Play Again”

End

M.Kiruthika [AP/CSE] Page 26


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

4. TOWERS OF HANOI: (APPLICATION OF RECURSION)


Problem Statement:
• There are three poles / towers named A, B. C
• There are n number of disks in tower A
• The user has to move the disks from A to C, using B as an Auxiliary disk
• Also the moving of disk has to satisfy certain rules as:
 Only one disk is moved from any tower at a time
 Only the top disk can be moved
 Large disks should not be placed over a small disk
Solution:
• Move the disks in a recursive fashion satisfying the conditions
Algorithm: Hanoi (N, A, C, B)
Step 1: Start
Step 2: If N is 1, go to Step 3 else to Step 4
Step 3: Move the disk from A to C and go to Step 7
Step 4: Call Hanoi (N – 1, A, B, C)
Step 5: Move disk from A to C
Step 6: Call Hanoi (N – 1, B, C, A)
Step 7: End
Pseudocode:
Begin Procedure Hanoi (N, A, C, B)
IF N = 1
Move disk from A to C
ELSE
CALL Hanoi (N – 1, A, B, C)
Move disk from A to C
CALL Hanoi (N – 1, B, C, A)
END IF
End Procedure Hanoi (N, A, C, B)
Variables: N, A, B, C

M.Kiruthika [AP/CSE] Page 27


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

Flowchart:

Hanoi (N,A,C,B)

No Yes

Is N = = 1?

Hanoi (N-1, A, B, C) Move disk from A to C

Hanoi (N-1, B, C, A)

End Hanoi

EXERCISES:
Develop an algorithm, flowchart and pseudocode for the following problems:
1. To find the area of a circle / square
2. To print “Hello JIT” 10 times
3. To convert Celsius to Fahrenheit [C = ((F-32)*5)/9]
4. To find a year is a leap year or not
5. To find the greatest of three numbers
6. To find the average and grade of a student (Marks are given as input)
7. To find the average and grade of „n‟ number of students (Marks are given as input)
8. To cook noodles
9. To find the roots of a Quadratic Equation

M.Kiruthika [AP/CSE] Page 28


GE8151 – PROBLEM SOLVING AND PYTHON PROGRAMMING UNIT I

10. To determine the salary of an employee based on the following conditions: Net Salary =
Basic_Pay + DA + TA + HRA, Gross Pay = Net_Salary – EPF – LIC
11. To login to facebook
12. To find the factorial of a number
13. To generate Fibonacci series
14. To find if a number is a prime number or not
15. To reverse a number
16. To swap two numbers using a temporary variable
17. To check if a string is a palindrome or not

REFERENCES:
1. Reema Tharaja, “Python Programming using Problem Solving Approach”, Oxford University
Press, First Edition, 2017
2. http://google.com

M.Kiruthika [AP/CSE] Page 29

You might also like