0% found this document useful (0 votes)
437 views6 pages

Problem Solving Techniques and Algorithms

The document discusses problem solving techniques and algorithms. It defines problem solving as a systematic approach to define a problem and create potential solutions. Some key problem solving techniques mentioned are algorithms, flowcharts, pseudocode, and programs. The properties and qualities of good algorithms are also outlined. Algorithms can be constructed using basic building blocks like statements, state, control flow, and functions. Examples are provided to illustrate sequence, selection, and iteration as types of control flow. Functions are described as reusable blocks of code that perform specific tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
437 views6 pages

Problem Solving Techniques and Algorithms

The document discusses problem solving techniques and algorithms. It defines problem solving as a systematic approach to define a problem and create potential solutions. Some key problem solving techniques mentioned are algorithms, flowcharts, pseudocode, and programs. The properties and qualities of good algorithms are also outlined. Algorithms can be constructed using basic building blocks like statements, state, control flow, and functions. Examples are provided to illustrate sequence, selection, and iteration as types of control flow. Functions are described as reusable blocks of code that perform specific tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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
 
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
v   Should be written in simple English
v   Each and every instruction should be precise and unambiguous.
v   Instructions in an algorithm should not be repeated infinitely.
v   Algorithm should conclude after a finite number of steps.
v   Should have an end point
v   Derived results should be obtained only after the algorithm terminates.
 
Qualities of a good algorithm
The following are the primary factors that are often used to judge the
quality of the algorithms.
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

BUILDING BLOCKS OF ALGORITHMS (statements, state,


control flow, functions)
 
Algorithms can be constructed from basic building blocks namely,
sequence, selection and 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.
 
Example:

Add two numbers:


Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
 

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:
v   Function is a sub program which consists of block of code(set of
instructions) that performs a particular task.
v   For complex problems, the problem is been divided into smaller and
simpler tasks during algorithm design.

Benefits of Using Functions


 
v   Reduction in line of code
v   code reuse
v   Better readability
v   Information hiding
v   Easy to debug and test
v   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

Common questions

Powered by AI

Iteration improves efficiency by allowing repeated execution of code blocks until a condition is met, reducing redundancy in code. This approach is superior to linear execution when tasks need repetition, such as processing collections or performing cumulative calculations, as it automates repetitive tasks and minimizes errors associated with manual repetition .

A good algorithm is distinguished by its efficiency in time and memory usage and the accuracy of its results. Objectively assessing these qualities involves measuring the time complexity, which indicates the duration of execution, and the space complexity, which indicates memory utilization. Accuracy can be judged by comparing the output to expected results for various test inputs. A quick, memory-efficient, and accurate algorithm is deemed superior .

State transition in algorithms refers to the movement from one process to another under specified conditions within an allotted time. It is pivotal for controlling flow and managing states, especially in iterative and conditional scenarios, thereby enabling dynamic problem-solving and ensuring algorithms respond correctly to varying inputs and conditions .

A finite end point ensures that an algorithm will terminate after completing its intended task, providing a clear result. Neglecting this may lead to infinite loops, consuming unnecessary resources, causing programs to hang or crash, and failing to produce a result, which is detrimental to reliability and performance .

Flowcharts provide a visual representation of algorithms, making logical structures and flow transparent. They help in understanding and debugging by illustrating processes through symbols and logic flow, facilitating communication with others about how solutions are designed and intended to function. This visualization aids in identifying errors and understanding complex algorithms .

Functions in algorithms help break down complex problems into smaller, manageable tasks, leading to more organized and modular designs. Benefits include reduced code length, enhanced readability, easier debugging, code reuse, information concealment, and improved maintenance. These advantages streamline the problem-solving process and enhance code quality .

Sequence and selection execution properties facilitate control flow management, crucial for problem-solving. In particular, sequence ensures orderly execution, vital for tasks requiring strict instruction following. Selection, through decision branches, enables algorithms to choose execution paths based on conditions, supporting dynamic decision-making processes critical in conditional scenarios .

Sequence, selection, and iteration are control flow mechanisms used to manage the execution of instructions in algorithms. Sequence involves executing commands one after another. Selection allows execution based on condition evaluation, thus directing program control to specific parts based on conditions. Iteration enables repeated execution of a set of instructions multiple times until a condition is met, useful for tasks requiring repetition .

The primary factors affecting the quality of an algorithm are time, memory, and accuracy. The performance of an algorithm improves with lesser time and memory requirements. An algorithm that executes faster with minimal memory is considered superior. Additionally, algorithms that provide more accurate solutions tend to be preferred .

Pseudo codes serve as an intermediary step between an algorithm and program implementation. They use simple language to outline logic, making them accessible for understanding and communicating ideas before coding. Unlike algorithms which require precise steps, pseudo codes are more informal and focus on the logic rather than precise syntax, providing a flexible way to design solutions .

You might also like