Download Introduction to Problem Solving Techniques: Algorithms, Flowcharts, and Programming and more Lecture notes Computer Programming in PDF only on Docsity!
Introduction to Problem Solving
Techniques
Dr. Fakhre Alam Khan MED UET Peshawar
Problem Solving
- (^) Problem solving is a process of identifying a problem and finding the best solution for it.
- (^) Problem solving is a skill that can be developed by following a well organized approach.
- (^) A problem may be solved in different ways.
- (^) One solution may be faster, less expensive; and more reliable than others. It is important to select the best suitable solution.
- Different problem-solving techniques are as follows:
- Program
- Algorithm
- Flowchart etc.
Advantages of Computer Program
Different advantages of computer program are as follows:
- (^) A computer program can solve many problems by giving instructions to computer.
- (^) A computer program can be used to perform a task repeatedly and quickly.
- (^) A program can process a large amount of data easily.
- (^) It can display the results in different styles.
- (^) The processing of a program is more efficient and less time consuming.
- (^) Different types of programs are used in different fields to perform certain tasks.
Algorithms & Pseudo Code
- (^) An algorithm is a step-by-step procedure to solve a problem.
- (^) The process of solving a problem becomes simpler and easier with help of algorithm.
- (^) lt is better to write algorithm before writing the actual computer program.
Algorithms & Pseudo Code
Pseudo code
- (^) Algorithms are written in a language that is similar to simple English called pseudo code.
- (^) There is no standard to write pseudo code. lt is used to specify program logic in an English like manner that is independent of any particular programming language.
- (^) Pseudo code simplifies program development by separating it into two main parts.
Programming approach
1. Logic Design - (^) In this part, the logic of the program is designed. We specify different steps required to solve the problem and the sequence of these steps. 2. Coding - (^) In this part, the algorithm is converted into a program. The steps of algorithm are translated into instructions of any programming language.
- (^) The use of pseudo code allows the programmer to focus on the planning of the program. After the planning is final, it can be written in any programming language.
Algorithm examples
Example 2 The following algorithm inputs radius from the user and calculates the area of circle. (Hint: Area = 3.14 radius radius)
- Start
- Input radius in r
- area = 3.14 * r * r
- Print area
- End
Algorithm examples
Example 3 The following algorithm calculates the distance covered by a car moving at an average speed of V m/s in time T. It should input average speed v and time t. (Hint: s = v*t , where s is the distance traveled).
- Start
- Input average speed in v
- Input time in t
- s = v* t
- Print s
- End
Advantages of Algorithms
Some advantages of algorithm are as follows:
1. Reduced Complexity Writing algorithm and program separately simplifies the overall task by dividing it into two simpler tasks. While writing the algorithm, we can focus on solving the problem instead of concentrating on a particular language. 2. Increased Flexibility Algorithm is written so that the code may be written in any language. Using the algorithm, the program could be written in Visual Basic, Java or C++ etc. 3. Ease of Understanding lt is not necessary to understand a particular programming language to understand an algorithm. It is written in an English like manner.
Flowchart
- (^) Flowchart is combination of two words flow and chart.
- (^) A chart consists of different symbols to display information about any program.
- (^) Flow indicates the direction of processing that takes place in the program.
- (^) Flowchart is a graphical representation of an algorithm.
- (^) It is a way of visually presenting the flow of data, operations performed on data and sequence of these operations.
Flowchart
Input / Output
- (^) Parallelogram symbol is used to represent an input or output step.
- (^) Input statement is used to get input from the user.
- (^) The output statement is used to display a message to the user or to display a value. Input Marks In Print Marks In
Flowchart
Process
- (^) Rectangle symbol is used to represent a process step. A process may be a complex calculation or simply an assignment statement Sum = A+B
Flowchart
Start / End
- (^) Oval symbol is used to represent the start or end of the flowchart. Flow Lines
- (^) Arrow symbols are used to represent the direction of flow in the flowchart. There are four types of flow lines.
Start End
Flowchart
Connector
- (^) Circle symbol is used to combine different flow lines.
- (^) It is used when two or more flow symbols come from different directions and move to one direction. Function Call
- (^) Rectangle symbol with double lines on left and right sides is used to call a function.
- (^) The name of function with parameters is written inside the symbol.