Sunteți pe pagina 1din 8

ALGORITHM

1. Algorithm is a step-by-step procedure, which defines a set of instructions to


be executed in a certain order to get the desired output. An algorithm can be
implemented in more than one programming language. Algorithms have a
definite beginning and a definite end, and a finite number of steps. When
implement an algorithm using any programming language, then it is
said to be program.

2. An algorithm is a well defined computational procedure that takes some value


or set of values as input and gives or produces some value or set of values as
output. That is an algorithm is a sequence of computational steps that
transform the input in to output.

Characteristics of a Good Algorithm

1. Finiteness: An algorithm must terminate after a finite number of steps and


further each step must be executable in finite amount of time
2. Definiteness (no ambiguity): Each steps of an algorithm must be precisely
defined.
3. Inputs: An algorithm has zero or more but only finite number of inputs.
4. Output: An algorithm has one or more outputs. The outputs have specific
relation to the inputs, where the relation is defined by the algorithm.
5. Effectiveness: An algorithm should be effective. This means that each of the
operation to be performed in an algorithm must be done exactly in a finite
length of time. If a sequence of steps is not finite, then it cannot be effective
also.

Algorithm Complexity

 Time Factor − Time is measured by counting the number of key operations


such as comparisons in the sorting algorithm.
 Space Factor − Space is measured by counting the maximum memory space
required by the algorithm.

For each problem or class of problems, there may be many different


algorithms and for each algorithm, there may be many different
implementations (programs).

Write an algorithm to find average of two numbers.

Step 1: Input two numbers. (Suppose a=6, b=6)


Step 2: Do the total of two numbers (i.e a+b=12)
Step 3: Find the average by dividing the total by 2 (i.e 12/2=6)
Step 4: Display the answer. (6)
Step 5: End
An algorithm may be expressed in a number of ways, including:

1. Natural language: usually ambiguous


2. Flow charts: issues of ambiguity; difficult to modify without specialized tools.
3. Pseudo-code: also avoids most issues of ambiguity; unclearly resembles
common elements of programming languages; no particular agreement on
syntax.
4. Programming language : tend to require expressing low-level details that are
not necessary for a high-level understanding

FLOW CHART

A flowchart is a type of diagram that represents a workflow or process Also called:


process flowchart, process flow diagram.
OR
A flowchart is a picture (graphical representation) of the problem solving process.
OR
A flowchart gives a step-by-step procedure for solution of a problem.

Elements of a flowchart: Various geometrical shaped boxes represent the steps


of the solution. The boxes are connected by directional arrows to show the flow of
the solution.

Uses of a flowchart:
1. To specify the method of solving a problem.
2. To plan the sequence of a computer program.
3. Communicate ideas, solutions.

Drawing a flowchart
1. Identify input and output.
2. Apply reasoning skills to solve the problem.
3. Draw the flowchart using the appropriate symbols and arrows to show the
sequence of steps in solving the problem.

Basic Symbols used in Flowchart Designs

1. Terminal: The oval symbol indicates Start, Stop and Halt in a program’s logic
flow. Terminal is the first and last symbols in the flowchart.
2. Input/Output: Program instructions that take input from input devices and
display output on output devices are indicated with parallelogram in a
flowchat.
3. Processing: A box represents arithmetic instructions. All arithmetic
processes such as adding, subtracting, multiplication and division are
indicated by action or process symbol.
4. Decision Diamond symbol represents a decision point. Decision based
operations such as yes/no question or true/false are indicated by diamond in
flowchart.

5. Connectors: Whenever flowchart becomes complex or it spreads over more


than one page, it is useful to use connectors to avoid any confusions. It is
represented by a circle.

6. Flow lines: Flow lines indicate the exact sequence in which instructions are
executed. Arrows represent the direction of flow of control and relationship
among different symbols of flowchart.

Types of Flow Chart

Sterneckert (2003) suggested that flowcharts can be modeled from the perspective
of different user groups (such as managers, system analysts and clerks), and that
there are four general types:
 Document flowcharts, showing controls over a document-flow through a
system
 Data flowcharts, showing controls over a data-flow in a system
 System flowcharts, showing controls at a physical or resource level
 Program flowchart, showing the controls in a program within a system

Uses of Flowcharts

Flowcharts were originally used by industrial engineers to structure work processes


such as assembly line manufacturing. Today, flowcharts are used for a variety of
purposes in manufacturing, architecture, engineering, business, technology,
education, science, medicine, government, administration and many other
disciplines.
Here are some of the ways flowcharts are used today.

 Project planning
 Program or system design through flowchart programming
 Process documentation
 Audit a process for inefficiencies or malfunctions
 Map computer algorithms
 Documenting workflow

Disadvantages of Flow Chart

1. Complex logic: Sometimes, the program logic is quite complicated. In that


case, flow chart becomes complex.
2. Alterations and Modifications: If alterations are required the flow chart may
require redrawing completely.
3. Reproduction: As the flow chart symbols cannot be typed, reproduction of
flow chart becomes a problem.
Pseudo Code

Pseudocode is an informal way of programming description that does not require


any strict programming language syntax or underlying technology considerations. It
is used for creating an outline or a rough draft of a program. Pseudocode
summarizes a program’s flow, but excludes underlying details. It is a simplified,
half-English, half-code outline of a computer program. It is sometimes given other
names, such as Program Definition Language (PDL).

Advantages of pseudocode –

• Pseudocode is understood by the programmers of all types.


• it enables the programmer to concentrate only on the algorithm part of the code
development.
• It cannot be compiled into an executable program. Example, C++ code:
if (i < 10) { i++; } pseudocode :if i is less than 10, increment i by 1.

Ex.- For a given value, Limit, what is the smallest positive integer Number for which
the sum Sum = 1 + 2 + ... + Number is greater than Limit.

Pseudocode:

1. Enter Limit
2. Set Number = 0.
3. Set Sum = 0.
4. Repeat the following:
a. If Sum > Limit, terminate the repetition , otherwise.
b. Increment Number by one.
c. Add Number to Sum and set equal to Sum.
5. Print Number and Sum.

Program

A computer program is a collection of instructions that performs a specific task


when executed by a computer. Most computer devices require programs to function
properly. A computer program is usually written by a computer programmer in a
programming language. From the program in its human-readable form of source
code, a compiler or assembler can derive machine code—a form consisting of
instructions that the computer can directly execute.

Alternatively, a computer program may be executed with the aid of an interpreter.


A collection of computer programs, libraries, and related data are referred to as
software. Computer programs may be categorized along functional lines, such as
application software and system software.
Compilers and Interpreters

A compiler takes the entire source code and converts it into object code or
machine code at once for compiling (generates errors if any) which is typically
stored in a file. The object code is also refereed as binary code and can be directly
executed by the machine after linking. It occupies more memory space and is slow
in debugging because it generates intermediate object code. Some of the
programming languages, such as C and C++ use compilers.

An interpreter decodes each line of source code to machine language. If any


errors occur while interpreting the code, immediately the error is thrown.
Interpreters are faster in debugging the code. It consumes less memory space.
Some of the famous programming languages using interpreters are Python and
Ruby.
The difference between an interpreter and a compiler
Interpreter Compiler
Translates program one statement at a Scans the entire program and translates
time. it as a whole into machine code.
It takes less amount of time to analyze It takes large amount of time to analyze
the source code but the overall the source code but the overall execution
execution time is slower. time is comparatively faster.
Generates intermediate object code which
No intermediate object code is
further requires linking, hence requires
generated, hence are memory efficient.
more memory.
Continues translating the program until It generates the error message only after
the first error is met, in which case it scanning the whole program. Hence
stops. Hence debugging is easy. debugging is comparatively hard.
Programming language like Python, Programming language like C, C++ use
Ruby ,Perl, PHP use interpreters. compilers.
MACHINE CODE

Machine languages are very close to the hardware. Every computer has its machine
language. A machine language programs are made up of series of binary pattern.
(Eg. 110110) It represents the simple operations which should be performed by the
computer. Machine language programs are executable so that they can be run
directly.

OBJECT CODE

On compilation of source code, the machine code generated for different processors
like Intel, AMD, an ARM is different. To make code portable, the source code is first
converted to Object Code. It is an intermediary code (similar to machine code) that
no processor will understand. At run time, the object code is converted to the
machine code of the underlying platform.

Java is both Compiled and Interpreted.

To exploit relative advantages of compilers are interpreters some programming


language like Java are both compiled and interpreted. The Java code itself is
compiled into Object Code. At run time, the JVM interprets the Object code into
machine code of the target computer.

Translators, compilers, interpreters and assemblers are all software programming


tools that convert code into another type of code, but each term has specific
meaning. All of the above work in some way towards getting a high-level
programming language translated into machine code that the central processing
unit (CPU) can understand. It’s important to note that all translators, compilers,
interpreters and assemblers are programs themselves.

Translators
The most general term for a software code converting tool is “translator.” A
translator, in software programming terms, is a generic term that could refer to a
compiler, assembler, or interpreter; anything that converts higher level code into
another high-level code (e.g., Basic, C++, Fortran, Java) or lower-level (i.e., a
language that the processor can understand), such as assembly language or
machine code. If you don’t know what the tool actually does other than that it
accomplishes some level of code conversion to a specific target language, then you
can safely call it a translator.

Assemblers
An assembler translates a program written in assembly language into machine
language and is effectively a compiler for the assembly language, but can also be
used interactively like an interpreter. Assembly language is a low-level
programming language. Low-level programming languages are less like human
language in that they are more difficult to understand

S-ar putea să vă placă și