












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













1
1.1 Introduction
1.2 Problem Solving
1.3 Algorithm
1.3.1 Examples of Algorithm 1.3.2 Properties of an Algorithm
1.4 Flow Chart
1.4.1 Flow Chart Symbols
1.4.2 Some Flowchart Examples
1.4.3 Advantages of Flowcharts
2
Intelligence is one of the key characteristics which differentiate a human being from other living creatures on the earth. Basic intelligence covers day to day problem solving and making strategies to handle different situations which keep arising in day to day life. One person goes Bank to withdraw money. After knowing the balance in his account, he/she decides to with draw the entire amount from his account but he/she has to leave minimum balance in his account. Here deciding about how much amount he/she may with draw from the account is one of the examples of the basic intelligence. During the process of solving any problem, one tries to find the necessary steps to be taken in a sequence. In this Unit you will develop your understanding about problem solving and approaches.
Can you think of a day in your life which goes without problem solving? Answer to this question is of course, No. In our life we are bound to solve problems. In our day to day activity such as purchasing something from a general store and making payments, depositing fee in school, or withdrawing money from bank account. All these activities involve some kind of problem solving. It can be said that whatever activity a human being or machine do for achieving a specified objective comes under problem solving. To make it clearer, let us see some other examples.
Example1 : If you are watching a news channel on your TV and you want to change it to a sports channel, you need to do something i.e. move to that channel by pressing that channel number on your remote. This is a kind of problem solving.
4
Algorithm can be defined as: “A sequence of activities to be processed for getting desired output from a given input.” Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”. There may be more than one way to solve a problem, so there may be more than one algorithm for a problem. Now, if we take definition of algorithm as: “A sequence of activities to be processed for getting desired output from a given input.” Then we can say that:
‘+’ for Addition ‘-’ for Subtraction ‘’* for Multiplication ‘/’ for Division and ‘ ’ for assignment. For example A X3 means A will have a value of X3.
5
1.3.1 Example of Algorithm
Problem 1: Find the area of a Circle of radius r. Inputs to the algorithm: Radius r of the Circle. Expected output: Area of the Circle
Algorithm: Step1: Read\input the Radius r of the Circle Step2: Area PIrr // calculation of area Step3: Print Area
Problem2 : Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm:
First num1. Second num2.
Expected output:
Sum of the two numbers.
Algorithm : Step1: Start Step2: Read\input the first num1. Step3: Read\input the second num2. Step4: Sum num1+num2 // calculation of sum Step5: Print Sum Step6: End
7
Problem1 : write algorithm to find the greater number between two numbers
Step1: Start
Step2: Read/input A and B
Step3: If A greater than B then C=A
Step4: if B greater than A then C=B
Step5: Print C
Step6: End
Problem2 : write algorithm to find the result of equation: ( )^ {
Step1: Start
Step2: Read/input x
Step3: If X Less than zero then F=-X
Step4: if X greater than or equal zero then F=X
Step5: Print F
Step6: End
Problem3 : A algorithm to find the largest value of any three numbers.
Step1: Start
Step2: Read/input A,B and C
Step3: If (A>=B) and (A>=C) then Max=A
Step4: If (B>=A) and (B>=C) then Max=B
Step5:If (C>=A) and (C>=B) then Max=C
Step6: Print Max
Step7: End
8
The loop allows a statement or a sequence of statements to be repeatedly executed based on some loop condition. It is represented by the ‘while’ and ‘for’ constructs in most programming languages, for unbounded loops and bounded loops respectively. (Unbounded loops refer to those whose number of iterations depends on the eventuality that the termination condition is satisfied; bounded loops refer to those whose number of iterations is known before-hand.) In the flowcharts, a back arrow hints the presence of a loop. A trip around the loop is known as iteration. You must ensure that the condition for the termination of the looping must be satisfied after some finite number of iterations, otherwise it ends up as an infinite loop, a common mistake made by inexperienced programmers. The loop is also known as the repetition structure.
Examples:
Problem1 : An algorithm to calculate even numbers between 0 and 99
Problem2 : Design an algorithm which gets a natural value, n,as its input and calculates odd numbers equal or less than n. Then write them in the standard output:
10
level of nesting, in which case it is best to demarcate parts of the algorithm as separate smaller modules. Beginners must train themselves to be proficient in using and combining control structures appropriately, and go through the trouble of tracing through the algorithm before they convert it into code.
1.3.2 Properties of algorithm
Donald Ervin Knuth has given a list of five properties for a,algorithm, these properties are:
Finiteness: An algorithm must always terminate after a finite number of steps. It means after every step one reach closer to solution of the problem and after a finite number of steps algorithm reaches to an end point.
Definiteness: Each step of an algorithm must be precisely defined. It is done by well thought actions to be performed at each step of the algorithm. Also the actions are defined unambiguously for each activity in the algorithm.
Input: Any operation you perform need some beginning value/quantities associated with different activities in the operation. So the value/quantities are given to the algorithm before it begins.
Output: One always expects output/result (expected value/quantities) in terms of output from an algorithm. The result may be obtained at different stages of the algorithm. If some result is from the intermediate stage of the operation then it is known as intermediate result and result obtained at the end of algorithm is known as end result. The output is expected value/quantities always have a specified relation to the inputs
11
1.4 FLOWCHART
The flowchart is a diagram which visually presents the flow of data through processing systems. This means by seeing a flow chart one can know the operations performed and the sequence of these operations in a system. Algorithms are nothing but sequence of steps for solving problems. So a flow chart can be used for representing an algorithm. A flowchart, will describe the operations (and in what sequence) are required to solve a given problem. You can see a flow chart as a blueprint of a design you have made for solving a problem.
For example suppose you are going for a picnic with your friends then you plan for the activities you will do there. If you have a plan of activities then you know clearly when you will do what activity. Similarly when you have a problem to solve using computer or in other word you need to write a computer program for a problem then it will be good to draw a flowchart prior to writing a computer program. Flowchart is drawn according to defined rules.
13
1.4.2 General Rules for flowcharting
flowcharts.
programs or subroutines) symbol.
Flowcharting uses symbols that have been in use for a number of years to represent the type of operations and/or processes being performed. The standardised format provides a common method for people to visualise
14
problems together in the same manner. The use of standardised symbols makes the flow charts easier to interpret, however, standardizing symbols is not as important as the sequence of activities that make up the process.
1.4.4 Some examples of Flowcharts
Now, we will discuss some examples on flowcharting. These examples will help in proper understanding of flowcharting technique. This will help you in program development process in next unit of this block.
Problem 1: Find the area of a circle of radius r.
16
Problem5 : Algorithm for find the greater number between two numbers.
True False
Problem6 : Flowchart for the problem of printing even numbers between 9 and 100:
Start
Read A,B
Print A
If A>B
Print B
END
17
Problem7 : Flowchart for the problem of printing odd numbers less than a given number. It should also calculate their sum and count.
19
1.4.5 Advantages of using Flowcharts
As we discussed flow chart is used for representing algorithm in pictorial form. This pictorial representation of a solution/system is having many advantagrs.These advantages are as follows:
Communication: A Flowchart can be used as a better way of communication of the logic of a system and steps involve in the solution, to all concerned particularly to the client of system.
Effective analysis: A flowchart of a problem can be used for effective analysis of the problem.
Documentation of Program/System: Program flowcharts are a vital part of a good program documentation. Program document is used for various purposes like knowing the components in the program, complexity of the program etc.
Efficient Program Maintenance: Once a program is developed and becomes operational it needs time to time maintenance. With help of flowchart maintenance become easier.
Coding of the Program: Any design of solution of a problem is finally converted into computer program. Writing code referring the flowchart of the solution become easy.
20
Check Your Progress 1
What is an algorithm?
Explain need of an algorithm?
Write an algorithm to find average age of a group of 10 players?
Write algorithm to this problem:Ramshewak goes to market for buying some fruits and vegetables. He ishaving a currency of Rs 500 with him for marketing. From a shop he purchases 2.0 kg Apple priced Rs. 50. per kg, 1.5 kg Mango priced Rs.35.0 per kg, 2.5 kg Potato priced Rs.10. per kg, and 1.0 kg Tomato priced Rs.15 per kg. He gives the currency of Rs. 500 to the shopkeeper. Find out the amount shopkeeper will return to Ramshewak. and also tell the total item purchased.
Find factorial of N?
Explain steps involve in drawing of a flowchart.
Explain uses of Flowchart.
Draw a flowchart to find the sum of first 100 natural numbers.
Draw a flowchart to find the largest of three numbers x, y and z.
Draw flowchart for the problem of determining prime number?
Draw a flowchart which generates first 50 items of the Fibonacci series: 1, 1, 2, 3, 5, 8,…?
Design an algorithm to convert a decimal number, n, to binary format?