Download presentation
1
Algorithms & Flowchart
2
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.
3
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.
4
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.
5
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).
7
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.
8
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.
9
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
10
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.
11
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
12
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 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
13
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
14
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.