Class11_Introduction to problem solving revision notes
Class11_Introduction to problem solving revision notes
1
INTRODUCTION TO PROBLEM SOLVING
CONTENT:
• INTRODUCTION
• PROBLEM SOLVING CYCLE
• DESIGNING ALGORITHM
INTRODUCTION:
• Famous quote by Steve Jobs, “Everyone in this country should learn to program a
computer, because it teaches you think.
2
ANALYZE THE PROBLEM:
1. UNDERSTAND THE PROBLEM WELL:
• Problem is just not that appears but something else causing it.
2. ANALYZE THE PROBLEM:
• Identify processing components.
• Identifying the relationships among processing components.
3
TESTING AND DEBUGGING:
7. Test and debug your program
• Finding errors in it.
• Rectifying the errors
8. Complete your documentation
• Consist of detailed description of what program does and how to
use it.
4
NEED FOR DECOMPOSITION:
• Large problems are extremely harder to solve than smaller problems.
• It is much easier to write two small program than writing one large program.
• Harder and more difficult to solve large program compared to smaller program.
DESIGNING ALGORITHM:
• The set of rules that define how a particular problem can be solved in finite
number of steps is known as algorithm.
• An algorithm is composed of a finite set of steps, each of which may require one
or more operations.
• Type of operations as algorithm can include:
• Each operation must be definite
• Each operation must be effective
• Each operation must be finite.
COMPONENTS OF AN ALGORITHM:
• An algorithm identifies following components:
1. Input: The inputs can be provided by a user or can be self-
contained, reading from a file.
2. Processing: What and how the processing would use inputs to
produce the desired output.
3. Output: The output expected from the algorithm, the objective
of the algorithm.
5
FLOWCHART:
• A flowchart is a pictorial representation of step-by-step solution of a problem.
• Flowchart is not only pictorially represents but also used as an aid in developing
algorithm.
• Flowchart symbols are used to carry different messages and used for different
purposes.
FLOWCHART:
• A flowchart symbols are:
WRITING ALGORITHS:
• Rules for writing algorithms:
IDENTIFIERS:
• Identifiers are the names given to various components of a program.
• While choosing names for identifiers, make sure that they are meaningful and not
unnecessaryily long or sort names.
WRITING ALGORITHS:
ASSIGNMENT:
• The assignment of values to variables is done through assignment statements.
6
WRITING ALGORITHS:
WRITING ALGORITHS:
FLOWCHART EXAMPLE:
ALGORITHM FLOWCHART
STEP 1: Start
STEP 3: S N1 + N2
STEP 5: Stop
7
PSEUDOCODE:
• Pseudocode is an informal way of describing the steps of a programs solution
without using any strict programming language syntax or underlying technology
considerations.
• Example:
display “Passed”
else
display “Failed”
PSEUDOCODE:
PSEUDOCODE ADVANTAGES:
• It uses a language which is easy to understand.
• It highlights the sequence of instructions.
• The structure is clearly visible.
• Can be easily modified.
PSEUDOCODE DISADVANTAGES:
• Not visual tool like flowchart.
• No accepted standard for pseudocode.
• Only be tested on paper.
• Informal representation of an algorithm.
VERFIYING AN ALGORITHM:
• Verifying an algorithm means to ensure that the algorithm is working as planned.
• To verify we should test with sample inputs for which we know the answers.
• A useful mechanism of verifying an algorithm called Dry-Run is used.
DRY-RUN ALGORITHM:
• A Dry-Run is the process of programmer manually working through their code to
trace the value of variable.
• There is no software involved in this process.
• A Dry-Run would involve a print out of the code.
• Trace tables enables the variable values in an algorithm to be recorded as the
algorithm is dry run.
8
DRY-RUN ALGORITHM:
• Characteristics of a Dry-Run are:
1. It is carried out during design, implementation, testing or maintenance.
2. It is used to identify the logic errors in a code.
3. It cannot find execution errors in a code.
COMPARING ALGORITHM:
• In order to decide which algorithm to choose over another, their efficiency will be
the deciding factor.
• Major factor that governs the efficiency of an algorithm are:
1. The time it takes to find solution.
2. The resources which are consumed in the process.
• The two deciding factors for algorithm are:
1. Space-wise efficiency
2. Time-wise efficiency