algorithms & flowchart. algorithms an algorithm is the step that a programmer will write that...

14
Algorithms & Flowchart

Upload: theodora-peters

Post on 13-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Algorithms & Flowchart

Page 2: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Algorithms

An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured language called Pseudo code.

Pseudo code is language nonspecific; it could be used by any programmer to help him or her write the actual program using any programming language.

Each step of your algorithm will be directly translated into a line of code when it is time to write the program using the program language.

One line of the algorithm is equal to one line of code. Algorithms are written in sequential order of action and are

language on-specific.

Page 3: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Algorithms

An algorithm is a step-by-step procedure that will always produce a correct solution.

If an algorithm is written correctly, any programmer using any programming language could directly translate each line of the algorithm into a line of code.

If the algorithm is correctly written, the programmer knows that the program will work.

It is possible to desk check the algorithm; it saves a programmer a log of time to use any algorithm and trace it to make sure that the program will be correct rather than just sitting down at the computer and writing out the program using the program language.

To help write the algorithm, many programmers use other tools first. One tool is a flowchart.

Page 4: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Flowcharts

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 viewer to understand a process, and perhaps also find flaws, bottlenecks, and other less-obvious features within it.

A flow chart is a graphical or symbolic representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flow chart symbols are linked together with arrows showing the process flow direction.

Page 5: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Common Flowchart Symbols

Different flow chart symbols have different meanings. The most common flow chart symbols are:

Terminator: An oval flow chart shape indicating the start or end of the process.

Process: A rectangular flow chart shape indicating a normal process flow step.

Decision: A diamond flow chart shape indication a branch in the process flow.

Connector: A small, labeled, circular flow chart shape used to indicate a jump in the process flow. (Shown as the circle with the letter “A”, below.)

Data: A parallelogram that indicates data input or output (I/O) for a process.

Document: Used to indicate a document or report (see image in sample flow chart below).

Page 6: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured
Page 7: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Characteristics of Algorithm

An algorithm has following characteristics: Finiteness:

An algorithm must terminate after a finite number of steps and further each step must be executable in finite amount of time.

One or more instructions should not be repeated infinitely. It means that the algorithm must terminate ultimately.

Definiteness (no ambiguity): Each steps of an algorithm must be precisely defined; the

action to be carried out must be rigorously and unambiguously specified for each case.

Inputs: An algorithm has zero or more but only finite, number of

inputs.

Page 8: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Characteristics of Algorithm

Output: An algorithm has one or more outputs. The requirement of

at least one output is obviously essential, because, otherwise we cannot know the answer/ solution provided by the algorithm. The outputs have specific relation to the inputs, where the relation is defined by the algorithm.

Effectiveness: An algorithm should be effective. Algorithms have

effectively computable operations & they must produce a result.

Page 9: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Analysis of Algorithms

Efficiency of an algorithm can be measured in terms of: Execution time (time complexity) The amount of memory required (space complexity)

Which measure is more important? Answer often depends on the limitations of the technology

available at time of analysis

Page 10: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Complexity of Algorithms

An important question about algorithm is: How efficient is an algorithm or piece of code? Efficiency covers lots of resources, including: CPU (time) usage memory usage disk usage network usage

Be careful to differentiate between: Performance: how much time/memory/disk/... is actually used

when a program is run. This depends on the machine, compiler, etc. as well as the code.

Complexity: how do the resource requirements of a program or algorithm scale, i.e., what happens as the size of the problem being solved gets larger.

Page 11: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Time Complexity

Time complexity comparisons are more interesting than space complexity comparisons

Time complexity: A measure of the amount of time required to execute an algorithm.

Factors that should not affect time complexity analysis: The programming language chosen to implement the algorithm The quality of the compiler The speed of the computer on which the algorithm is to be executed

Time complexity analysis for an algorithm is independent of programming language, machine used

Objectives of time complexity analysis: To determine the feasibility of an algorithm by estimating an upper

bound on the amount of work performed To compare different algorithms before deciding on which one to

implement

Page 12: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Time Complexity

Analysis is based on the amount of work done by the algorithm Time complexity expresses the relationship between the size of the

input and the run time for the algorithm Usually expressed as a proportionality, rather than an exact function Analysis is based on the amount of work done by the algorithm• Time complexity expresses the relationship between the size of the

input and the run time for the algorithm Usually expressed as a proportionality, rather than an exact function To simplify analysis, we sometimes ignore work that takes a constant

amount of time, independent of the problem input size. When comparing two algorithms that perform the same task, we

often just concentrate on the differences between algorithms

Page 13: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Time Complexity

Simplified analysis can be based on: Number of arithmetic operations performed Number of comparisons made Number of times through a critical loop Number of array elements accessed

Page 14: Algorithms & Flowchart. Algorithms An algorithm is the step that a programmer will write that will become a program. It is written in a form of structured

Big-O Notation

Formally, the time complexity T(n) of an algorithm is O(f(n)) (of the order T(n)) if, for some positive constants C1 and C2 for all but finitely many values of n

C1*f(n) ≤ T(n) ≤ C2*f(n) This gives upper and lower bounds on the amount of work

done for all sufficiently large n