Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Algorithm, Pseudocode, Flowchart What Is An Algorithm?

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7
At a glance
Powered by AI
The key takeaways are that an algorithm is a well-defined procedure to solve a problem, pseudocode is used to represent algorithms without using a specific programming language syntax, and flowcharts are used to visualize processes and algorithms.

An algorithm is a well-defined sequence of unambiguous instructions to solve a problem.

An algorithm is the steps to solve a problem while pseudocode is a way to represent an algorithm without using a specific programming language syntax. Pseudocode uses structures from programming languages but is not executable code.

ALGORITHM, PSEUDOCODE, FLOWCHART

What Is an Algorithm?
Consider how you use a computer in a typical day. For example, you start working on a report,
and once you have completed a paragraph, you perform a spell check. You open up a spreadsheet
application to do some financial projections to see if you can afford a new car loan. You use a
web browser to search online for a kind of car you want to buy.
You may not think about this very consciously, but all of these operations performed by your
computer consist of algorithms. An algorithm is a well-defined procedure that allows a computer
to solve a problem. Another way to describe an algorithm is a sequence of unambiguous
instructions. The use of the term 'unambiguous' indicates that there is no room for subjective
interpretation. Every time you ask your computer to carry out the same algorithm, it will do it in
exactly the same manner with the exact same result.
Consider the earlier examples again. Spell checking uses algorithms. Financial calculations use
algorithms. A search engine uses algorithms. In fact, it is difficult to think of a task performed by
your computer that does not use algorithms.
How Do Algorithms Work?
Let's take a closer look at an example.
A very simple example of an algorithm would be to find the largest number in an unsorted list of
numbers. If you were given a list of five different numbers, you would have this figured out in no
time, no computer needed. Now, how about five million different numbers? Clearly, you are
going to need a computer to do this, and a computer needs an algorithm.
Here is what the algorithm could look like. Let's say the input consists of a list of numbers, and
this list is called L. The number L1 would be the first number in the list, L2 the second number,
etc. And we know the list is not sorted - otherwise the answer would be really easy. So, the input
to the algorithm is a list of numbers, and the output should be the largest number in the list.
The algorithm would look something like this:
Step 1: Let Largest = L1
This means you start by assuming that the first number is the largest number.
Step 2: For each item in the list:
This means you will go through the list of numbers one by one.
Step 3: If the itemLargest:

If you find a new largest number, move to step four. If not, go back to step two, which means you
move on to the next number in the list.
Step 4: Then Largest = the item
This replaces the old largest number with the new largest number you just found. Once this is
completed, return to step two until there are no more numbers left in the list.
Step 5: Return Largest
This produces the desired result.
An algorithm is a procedure for solving a problem in terms of the actions to be executed and the
order in which those actions are to be executed. An algorithm is merely the sequence of steps
taken to solve a problem. The steps are normally "sequence," "selection, " "iteration," and a casetype statement.
In C, "sequence statements" are imperatives. The "selection" is the "if then else" statement, and
the iteration is satisfied by a number of statements, such as the "while," " do," and the "for,"
while the case-type statement is satisfied by the "switch" statement.
Pseudocode is an artificial and informal language that helps programmers develop algorithms.
Pseudocode is a "text-based" detail (algorithmic) design tool.
The rules of Pseudocode are reasonably straightforward. All statements showing "dependency"
are to be indented. These include while, do, for, if, switch. Examples below will illustrate this
notion.
Examples:
1. If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"
2. Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Set the class average to the total divided by ten

Print the class average


3. Initialize total to zero
Initialize counter to zero
Input the first grade
while the user has not as yet entered the sentinel
add this grade into the running total
add one to the grade counter
input the next grade (possibly the sentinel)
if the counter is not equal to zero
set the average to the total divided by the counter
print the average
else
print 'no grades were entered'
4.
initialize passes to zero
initialize failures to zero
initialize student to one
while student counter is less than or equal to ten
input the next exam result
if the student passed
add one to passes
else
add one to failures
add one to student counter
print the number of passes
print the number of failures

if eight or more students passed


print "raise tuition"
Difference b/w algorithm and pseudocode
An algorithm is simply a solution to a problem. An algorithm presents the solution to a problem
as a well defined set of steps or instructions. Pseudo-code is a general way of describing an
algorithm. Pseudo-code does not use the syntax of a specific programming language, therefore
cannot be executed on a computer. But it closely resembles the structure of a programming
language and contains roughly the same level of detail.
Algorithm
An algorithm gives a solution to a particular problem as a well defined set of steps. A recipe in a
cookbook is a good example of an algorithm. When a computer is used for solving a particular
problem, the steps to the solution should be communicated to the computer. This makes the study
of algorithms a very important part in computer science. An algorithm is executed in a computer
by combining lot of elementary operations such as additions and subtractions to perform more
complex mathematical operations. But translating the idea of the algorithm in to computer code
is not straight forward. Specially, converting an algorithm in to a low level language such as
assembly language could be very tedious than using a high level language such as C or Java.
When designing an algorithm, it is important to do an analysis on the resources (such as time and
storage) required by the algorithm. Notations such as big O notation are used for performing time
and storage analysis on algorithms. Algorithms can be expressed using natural languages,
pseudocode, flowcharts, etc.
Pseudocode
Pseudocode is one of the methods that could be used to represent an algorithm. It is not written
in a specific syntax that is used by a programming language and therefore cannot be executed in
a computer. There are lots of formats used for writing pseudocodes and most of them borrow
some of the structures from popular programming languages such as C, Lisp, FORTRAN, etc.
Also, natural language is used when presenting details that are not important. Most of the
algorithms are presented using pseudocode since they can be read and understood using
programmers who are familiar with different programming languages. Some languages such as
Pascal have syntax that is very similar to pseudocode making the transformation from
pseudocode to the corresponding program code easier. Pseudocode allows to include control
structures such as WHILE, IF-THEN-ELSE, REPEAT-UNTIL, FOR, and CASE, which are
present in many high level languages.
What is the difference between Algorithm and Pseudocode?
An algorithm is a well defined sequence of steps that provides a solution for a given problem,
while a pseudocode is one of the methods that can be used to represent an algorithm. While

algorithms can be written in natural language, pseudocode is written in a format that is closely
related to high level programming language structures. But pseudocode does not use specific
programming language syntax and therefore could be understood by programmers who are
familiar with different programming languages. Additionally, transforming an algorithm
presented in pseudocode to programming code could be much easier than converting an
algorithm written in natural language.
FLOWCHARTS
A flowchart is a type of diagram that represents an algorithm, workflow or process, showing the
steps as boxes of various kinds, and their order by connecting them with arrows. This
diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used
in analyzing, designing, documenting or managing a process or program in various fields
Flowcharts are used in designing and documenting complex processes or programs. Like other
types of diagrams, they help visualize what is going on and thereby help the people to understand
a process, and perhaps also find flaws, bottlenecks, and other less-obvious features within it.
There are many different types of flowcharts, and each type has its own repertoire of boxes and
notational conventions. The two most common types of boxes in a flowchart are:

a processing step, usually called activity, and denoted as a rectangular box


a decision, usually denoted as a diamond.

A flowchart is described as "cross-functional" when the page is divided into different swimlanes
describing the control of different organizational units. A symbol appearing in a particular "lane"
is within the control of that organizational unit. This technique allows the author to locate the
responsibility for performing an action or making a decision correctly, showing the responsibility
of each organizational unit for different parts of a single process.

Symbol

Symbol Name
Flow Lines

Description
Used

to

connect

symbols
Terminal

Used to

represent start,

pause or halt in the


program logic.

Input/Output

Represents

the

information

entering or

leaving the system.

Processing

Represents

arithmetic

and logical instructions.

Decision

Represents a decision to
be made.

Connector

Used to
flow lines.

join different

You might also like