0% found this document useful (0 votes)
3 views19 pages

Introduction To Problem Solving

The document outlines the importance of problem solving in computer science, emphasizing the need for precise instructions to enable computers to solve problems effectively. It details the steps of problem solving, including identifying the problem, generating solutions, implementing the chosen solution, and monitoring progress. Additionally, it discusses algorithms, pseudocode, flow control, and the significance of decomposition in simplifying complex problems.

Uploaded by

raimanvi013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views19 pages

Introduction To Problem Solving

The document outlines the importance of problem solving in computer science, emphasizing the need for precise instructions to enable computers to solve problems effectively. It details the steps of problem solving, including identifying the problem, generating solutions, implementing the chosen solution, and monitoring progress. Additionally, it discusses algorithms, pseudocode, flow control, and the significance of decomposition in simplifying complex problems.

Uploaded by

raimanvi013
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to problem Solving

Today, computers are all around us. We use them for doing various tasks
in a faster and more accurate manner. For example, using a computer or
smartphone, we can book train tickets online.
Computers are used for solving various day-to-day problems and thus
problem solving is an essential skill that a computer science student
should know. Computers themselves cannot solve a problem. Precise
step-by-step instructions should be given by us to solve the problem.
Thus, the success of a computer in solving a problem depends on how
correctly and precisely we define the problem, design a solution
(algorithm) and implement the solution (program) using a programming
language. Thus, problem solving is the process of identifying a problem,
developing an algorithm for the identified problem and finally
implementing the algorithm to develop a computer program.
Problem Solving Steps
1. Identify the problem. The first step in solving any problem is to first identify it. This stage
requires analysis of the current situation, identification of the problem, evaluating why the
problem is occurring, and assessing who the problem is affecting. This stage also involves looking
at any contributing factors that are directly influencing the problem and where they are coming
from.
2. Look for solutions. The next step in solving a problem is to generate several possible solutions
that could remedy the issue. This step often involves brainstorming, prediction, and forecasting
and is sometimes done with two or more people. Complex problems are rarely able to be solved
by a single solution, so coming up with several potential interventions is the key to success in this
stage.
3. Choose a solution. Once you’ve come up with several potential solutions that could potentially
solve the problem, you’ll now need to carefully analyze each solution and select the most
appropriate one. This step can take some trial and error, as not all solutions are obvious. This step
also requires strong decision-making skills, especially when there are multiple solutions on the
table.
Problem Solving Steps
4. Implementation of the solution. After one solution has been chosen, it’s now time to
implement this solution to the problem. There should be clearly established benchmarks that will
show whether the solution is working along with a plan in case the solution doesn’t work.
5. Monitoring progress. After the solution has been implemented, progress must be monitored to
ensure the solution is effective. You can monitor how well the solution is working as well as ask
for feedback from others who are directly affected by the changes that were made. Based on
feedback and progress, adjustments may need to be made to continue seeing progress.
Algorithm
An algorithm is a process or set of rules which must be followed to complete a
particular task.
This is basically the step-by-step procedure to complete any task.
All the tasks are followed a particular algorithm, from making a cup of tea to
make high scalable software.
This is the way to divide a task into several parts.
If we draw an algorithm to complete a task then the task will be easier to
complete.
The algorithm is used for,
To develop a framework for instructing computers.
Introduced notation of basic functions to perform basic tasks.
For defining and describing a big problem in small parts, so that it is very easy
to execute.
Algorithm
Characteristics of Algorithm
1. An algorithm should be defined clearly.
2. An algorithm should produce at least one output.
3. An algorithm should have zero or more inputs.
4. An algorithm should be executed and finished in finite number of steps.
5. An algorithm should be basic and easy to perform.
6. Each step started with a specific indentation like, “Step-1”,
7. There must be “Start” as the first step and “End” as the last step of the
algorithm.
Algorithm
Let’s take an example to make a cup of tea,
Step 1: Start
Step 2: Take some water in a bowl.
Step 3: Put the water on a gas burner.
Step 4: Turn on the gas burner
Step 5: Wait for some time until the water is boiled.
Step 6: Add some tea leaves to the water according to the requirement.
Step 7: Then again wait for some time until the water is getting colorful as tea.
Step 8: Then add some sugar according to taste.
Step 9: Again, wait for some time until the sugar is melted.
Step 10: Turn off the gas burner and serve the tea in cups with biscuits.
Step 11: End
Algorithm
Advantages of Algorithm
An algorithm uses a definite procedure.
It is easy to understand because it is a step-by-step definition.
The algorithm is easy to debug if there is any error happens.
It is not dependent on any programming language
It is easier for a programmer to convert it into an actual program because the
algorithm divides a problem into smaller parts.
Disadvantages of Algorithms
An algorithm is Time-consuming, there is specific time complexity for different
algorithms.
Large tasks are difficult to solve in Algorithms because the time complexity
may be higher, so programmers have to find a good efficient way to solve that
task.
Looping and branching are difficult to define in algorithms.
Flow Chart
A flowchart is a visual representation of an algorithm. A flowchart is a diagram
made up of boxes, diamonds and other shapes, connected by arrows. Each shape
represents a step of the solution process and the arrow represents the order or link
among the steps. There are standardized symbols to draw flowcharts.
Write an algorithm to find the square of a
number.
Before developing the algorithm, let us
first identify the input, process and output:
• Input: Number whose square is required
• Process: Multiply the number by itself to
get its square
• Output: Square of the number
Algorithm to find square of a number.
Step 1: Input a number and store it to num
Step 2: Compute num * num and store it
in square
Step 3: Print square
Pseudocode
A Pseudocode(pronounced Soo-doh-kohd) is defined as a step-by-step
description of an algorithm. Pseudocode does not use any programming
language in its representation instead it uses the simple English language text
as it is intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its
implementation(code) in a high-level language.

INPUT num1
INPUT num2
COMPUTE Result = num1 + num2
PRINT Result
Flow of Control
It basically analyzes and chooses in which direction a program flows based on
certain parameters or conditions. There are three basic types of logic, or flow
of control, known as:
• Sequence logic, or sequential flow
• Selection logic, or conditional flow
• Iteration logic, or repetitive flow
Sequential Logic (Sequential Flow)
Sequential logic as the name suggests follows a serial or sequential flow in
which the flow depends on the series of instructions given to the computer.
Unless new instructions are given, the modules are executed in the obvious
sequence.
Flow of Control
Selection Logic (Conditional Flow)
Selection Logic simply involves a number of
conditions or parameters which decides one If (condition) then:
out of several written modules. [Module A]
The structures which use these type of [End of If structure]
logic are known as Conditional Structures.

Iteration Logic (Repetitive Flow)


The Iteration logic employs a loop which involves a
repeat statement followed by a module known as
the body of a loop.
Comparison of Algorithm
There can be more than one approach to solve a problem using computer and hence
we can have more than one algorithm. Then one may ask which algorithm should be
used?
There can be four different ways to write algorithms to check whether a given
number is prime or not:
(i) Starting with divisor 2, divide the given number (dividend) and check if
there are any factors. Increase the divisor in each iteration and repeat the
previous steps as long as divisor < dividend. If there is a factor, then the
given number is not prime
(ii) Instead of testing all the numbers till the dividend, only test up to half of
the given value (dividend) because the divisor can not be more than half
of the dividend
(iii) In method (i), only test up to the square root of the dividend (numbers)
(iv) Given a prior list of prime number till 100, divide the given number by
each number in the list. If not divisible by any number, then the number
is a prime else it is not prime
Comparison of Algorithm
Algorithm (i) requires large number of calculations (means more
processing time) as it checks for all the numbers as long as the
divisor is less than the number. If the given number is large, this
method will take more time to give the output.
Algorithm (ii) is more efficient than (i) as it checks for divisibility till
half the number, and thus it reduces the time for computation of the
prime number.
Algorithm(iii) is even more efficient as it checks for divisibility till
square root of the number, thereby further reducing the time taken.
As algorithm (iv) uses only the prime numbers smaller than the given
number for divisibility, it further reduces the calculations. But in this
method we require to store the list of prime numbers first. Thus it
takes additional memory even though it requires lesser calculations.
Comparison of Algorithm
Hence, algorithms can be compared and analyzed on the basis of the
amount of processing time they need to run and the amount of
memory that is needed to execute the algorithm.
These are termed as time complexity and space complexity,
respectively.
The choice of an algorithm over another is done depending on how
efficient they are in terms of processing time required (time
complexity) and the memory they utilise (space complexity).
Coding
Once an algorithm is finalized, it should be coded in a high-level programming
language as selected by the programmer. The ordered set of instructions are written
in that programming language by following its syntax.
Syntax is the set of rules or grammar that governs the formulation of the statements
in the language, such as spellings, order of words, punctuation, etc.
The machine language or low-level language consisting of 0s and 1s only is the ideal
way to write a computer program.
Programs written using binary digits are directly understood by the computer
hardware, but they are difficult to deal with and comprehend by humans.
This led to the invention of high-level languages which are close to natural languages
and are easier to read, write, and maintain, but are not directly understood by the
computer hardware.
An advantage of using high-level languages is that they are portable, i.e., they can
run on different types of computers with little or no modifications.
Low-level programs can run on only one kind of computer and have to be rewritten
in order to run on another type of system. A wide variety of high-level languages,
such as FORTRAN, C, C++, Java, Python, etc., exist.
Coding
A program written in a high-level language is called source code. We need to translate
the source code into machine language using a compiler or an interpreter, so that it
can be understood by the computer.
There are multiple programming languages available and choosing the one suitable for
our requirements requires us to consider many factors. It depends on the platform
(OS) where the program will run.
We need to decide whether the application would be a desktop application, a mobile
application or a web application.
Desktop and mobile applications are generally developed for a particular operating
system and for certain hardware whereas the web applications are accessed in
different devices using web browsers and may use resources available over cloud.
Besides, programs are developed not only to work on a computer, mobile or a web
browser, but it may also be written for embedded systems like digital watch, mp3
players, traffic signals or vehicles, medical equipment's and other smart devices.
Decomposition
It involves breaking down a complex problem or system into smaller parts that
are more manageable and easier to understand. The smaller parts can then be
examined and solved, or designed individually, as they are simpler to work with.
Why is decomposition important?
If a problem is not decomposed, it is much harder to solve. Dealing with many
different stages all at once is much more difficult than breaking a problem down
into a number of smaller problems and solving each one, one at a time. Breaking the
problem down into smaller parts means that each smaller problem can be examined
in more detail.
Similarly, trying to understand how a complex system works is easier using
decomposition. For example, understanding how a bicycle works is more
straightforward if the whole bike is separated into smaller parts and each part is
examined to see how it works in more detail.
Decomposition
Solving a crime
Imagine that a crime has been committed. Solving a crime can be a very complex
problem as there are many things to consider.
For example, a police officer would need to know the answer to a series of smaller
problems:
what crime was committed
when the crime was committed
where the crime was committed
what evidence there is
if there were any witnesses
if there have recently been any similar crimes
The complex problem of the committed crime has now been broken down into
simpler problems that can be examined individually, in detail.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy