Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Unit I - Problemsolving - Intro

This document discusses problem solving in computer science. It begins by explaining that computers are used to solve complex tasks and problems, but that computers cannot solve problems on their own - humans must provide precise instructions. There are several key steps to problem solving: defining the problem, developing an algorithm or solution, coding the solution, testing and debugging. The document then provides examples of algorithms, flowcharts, and pseudocode to represent solutions to problems.

Uploaded by

sivamathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Unit I - Problemsolving - Intro

This document discusses problem solving in computer science. It begins by explaining that computers are used to solve complex tasks and problems, but that computers cannot solve problems on their own - humans must provide precise instructions. There are several key steps to problem solving: defining the problem, developing an algorithm or solution, coding the solution, testing and debugging. The document then provides examples of algorithms, flowcharts, and pseudocode to represent solutions to problems.

Uploaded by

sivamathi
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Unit I

Problem Solving
Problem Solving
• Today, computers are all around us.
• We use them for doing various tasks like banking, railway
reservation, travel booking etc.
• All such task are complex without computers.
• Hence, Computers are used for solving various day-to-day
problems
• Thus problem solving is an essential skill that a computer science
student should know.
• It is pertinent to mention that 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 and design a
solution .
• Problem solving is the process of identifying a problem,
developing an solution for the identified problem and finally
implementing the solution to develop a computer program.
STEPS FOR PROBLEM SOLVING

• Finding the solution to a problem might consist of multiple steps.

• Example: Noise from a car -> Problem. Solution ?

• Steps in problem solving:

1. Analysing the problem

2 Developing a Solution - Algorithm , Flowchart, process Chart

3 Coding - Pseudocode

4 Testing and Debugging


Algorithm
• It is essential to device a solution before writing a program code for a given
problem.

• The solution is represented in a form of algorithm, flowchart or process chart.

• An algorithm is defined as step by step procedure used to solve problems or


perform tasks.

• Example: Imagine an algorithm like a very well-written recipe for a dish, with
clearly defined steps that, if followed, one will end up preparing the dish.
• Before writing algorithm identify input, process and output.
• Input -> get from user
• Process -> task to be performed
• output -> final result.
Example Algorithm for addition of two numbers:
Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Add the given numbers i.e Sum= A+B
Step 4: Display the result i.e print Sum
Step 5: Stop.
Example Algorithm for biggest among two numbers:

Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Compare the given numbers i.e A>B or B>A
Step 4: Display the result i.e print biggest number
Step 5: Stop.

Try:
Area of Circle: Formula πr2
Perimeter of Circle: Formula 2πr
Example Algorithm for biggest among two numbers:

Step 1: Start
Step 2: Get two numbers say A , B
Step 3: Compare the given numbers i.e A>B or B>A
Step 4: Display the result i.e print biggest number
Step 5: Stop.

Try:
Area of Circle: Formula πr2
Perimeter of Circle: Formula 2πr
Flowchart
• 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 standardised symbols to draw flowcharts.


Example Flowchart for addition of two numbers
Problem : To find the square of a number.
Algorithm Flowchart
• Step 1: Start
• Step 2: Get a number say
num
• Step 3: Calculate num * num
and store it in square
• Step 4: Display square
• Step 5: Stop
Process Chart
• A process flow diagram, also known as a process flowchart or process
flow, is a type of flowchart that is used to represent a process or system.

• It uses symbols and lines to show the inputs, outputs, and steps in a
process, as well as the connections between them.

• Process flow diagrams are often used in manufacturing, engineering, and


other technical fields to document and communicate complex processes.
• In summary, a flowchart is a generic term that can refer to any type of
diagram that represents a process or workflow, while a process flow
diagram is a specific type of flowchart that is used to represent a
process or system in manufacturing, engineering, and other technical
fields
Pseudo code
• A pseudocode is another way of representing an algorithm.

• It is considered as a non-formal language that helps programmers to write algorithm.

• It is a detailed description of instructions that a computer must follow in a particular


order.

• It is intended for human reading and cannot be executed directly by the computer.

• No specific standard for writing a pseudocode exists.

• The word “pseudo” means “not real,” so “pseudocode” means “not real code”
• Example pseudocode:

INPUT

COMPUTE

PRINT

INCREMENT

DECREMENT

IF/ELSE

WHILE

TRUE/FALSE
Advantages of pseudo code

• Writing of pseudocode involves much less time and effort than


drawing an equivalent flowchart.

• Converting a pseudo code to a programming language is much more


easier as compared to converting a flowchart.

• It is easier to modify the pseudocode of a program logic when program


modifications are necessary.
Limitations of Pseudocode

• In case of pseudo code, a graphic representation of program logic is not


available.

• There are no standard rules to follow in using pseudocode.

• Different programmers use their own style of writing pseudocode


communication problems occur due to lack of standardization.

• For a beginner, it is more difficult to follow the logic or write the


pseudo code, as compared to flowcharting.
Examples using Algorithm, Flowchart and Pseudo
code
1. Area of Rectangle

Algorithm Flowchart Pseudocode

Step 1: Start BEGIN

Step 2: get l,b values READ l, b

Step 3: Calculate A=l*b CALCULATE A=l*b

Step 4: Display A DISPLAY A

Step 5: Stop END


2. Area and circumference of Circle

Algorithm Flowchart Pseudocode

Step 1: Start BEGIN

Step 2: get r value READ r

Step 3: Calculate A=3.14*r*r CALCULATE A and C

Step 4: Calculate C=2.3.14*r A=3.14*r*r

Step 5: Display A,C C=2*3.14*r

Step 6: Stop DISPLAY A

END
Try
• To Calculate simple interest
• To check positive or negative number

You might also like