Identification of Computational Problems
Identification of Computational Problems
Identification of Computational Problems
Problems
What Is Computer Science?
Search Problems
Counting Problems
Optimization Problems
Requirements to solve computational
problems
• In order to solve a problem computationally,
two things are needed,
A representation that captures all the relevant
aspects of the problem
An algorithm that solves the problem by use of
the representation
Man, Cabbage, Goat, Wolf problem
• Simple algorithmic
approach - brute force
approach.
• Start State (initial state)
• Valid State
• Abstraction
What Is an Algorithm?
• It is a finite number of clearly described, unambiguous “doable” steps
that can be systematically followed to produce a desired result for
given input in a finite amount of time
• Computer algorithms are central to computer science.
• They provide step-by-step methods of computation that a machine can
carry out.
• Having high-speed machines (computers) that can consistently follow
and execute a given set of instructions provides a reliable and effective
means of realizing computation.
• However, the computation that a given computer performs is only as
good as the underlying algorithm used.
• Understanding what can be effectively programmed and executed by
computers, therefore, relies on the understanding of computer
algorithms
• Once an algorithm for solving a given problem is developed or found,
an important question is, “Can a solution to the problem be found in a
reasonable amount of time?” If not, then the particular algorithm is
of limited practical use.
Traveling Salesman Problem
• Only one flow line should come out from a process symbol.
• Only one flow line should enter a decision symbol, but two or three
flow lines, one for each possible answer, should leave the decision
symbol.
General Rules for flowcharting
• Write within standard symbols briefly. As necessary,
you can use the annotation symbol to describe data
or computational steps more clearly.
ALGORITHM:
1. Start
2. Read the sum from the user
3. Calculate average by dividing the number by 6.
4. Print the average
5. Stop
Problem: Find the average of six numbers, given
the sum of the numbers.
Pseudocode: Flowchart:
START Terminal
READ the sum
CALCULATE Average = sum / 6 Input
Output
Terminal
Decision Structure or Selection Structure
• It is the case where in the algorithm, one has to make a choice of
two alternatives by making decision depending on a given
condition.
• Selection structures are also called case selection structures when
there are two or more alternatives to choose from
Flowchart Pseudocode
Pseudocode:
START
READ temperature in Fahrenheit (F)
CALCULATE Celcius (C) temperature
with formula C=5/9*(F-32),
PRINT C
STOP
Determine Whether a Temperature is Below or
Above the Freezing Point
Pseudocode:
START
INPUT temperature
IF (temperature <32) THEN
PRINT “Below freezing point"
ELSE
PRINT “Above freezing point"
STOP
Print sum of first 100 natural numbers
Pseudocode:
START
SET N=1, Sum=0
WHILE N<=100
Sum=Sum+N
N=N+1
END WHILE
PRINT Sum
STOP
Difference between Algorithm,
Flowchart, and Pseudo Code
• An algorithm is a sequence of instructions used to solve a
particular problem.
• Flowchart and Pseudo code are tools to document and
represent the algorithm.
• In other words, an algorithm can be represented using a
flowchart or a pseudo code.
• Flowchart is a graphical representation of the algorithm.
• Pseudo code is a readable, formally styled English like
language representation of the algorithm.
• Both flowchart and pseudo code use structured constructs of
the programming language for representation.
• The user does not require the knowledge of a programming
language to write or understand a flowchart or a pseudo
code.