Algorithm 110801105245-phpapp01


Published on


Published in: Technology, Education
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Algorithm 110801105245-phpapp01

  1. 1. ALGORITHMwww.eshikshak.
  2. 2. Introduction to Algorithm● An algorithm is finite set of steps defining the solution of a particular problem.● It can be expressed in English like language, called pseudocode, in programming language or in the form of flowchart.
  3. 3. Characteristics● Input – There are zero or more values which are externally supplied.● Output – At least one value is produced● Definiteness – Each step must be clear and unambiguous● Finiteness – If we trace the steps of an algorithm, then for all cases, the algorithm must terminate after a finite number of steps● Effectiveness – Each step must be sufficiently basic that it can in principal be carried out by a person using only paper and pencil
  4. 4. Algorithm Complexity● There are basically two aspects of computer programming. ○ Data Organization (i.e Data & structure) ○ Algorithm● The choice of a particular algorithm depends on the following consideration : ○ Time Complexity (Performance Requirements) ○ Space Complexity (Memory Requirements)
  5. 5. Space Complexity● It means the amount of memory, algorithm or program needs to run to completion.● Some of the reasons for studying space complexity are ○ If a multi user system ○ Sufficient memory is available to run the program
  6. 6. Space Complexity (Cont.)● The space needed by a program consists of the following components. ○ Instruction Space : Space needed to store the executable version of the program ○ Data Space : Space needed to store all constants, variable values and has further following components ■ Constants, variables, structured variables like array and structure ■ Dynamically allocated space
  7. 7. Space Complexity (Cont.)● Environmental Stack Space : Space needed to store the information needed to resume the suspended functions. ○ Return Address ○ Values of all local variables and the values of formal parameters in the function being involved.
  8. 8. Time Complexity● It means the amount of time it needs to run to completion● Reasons for studying time complexity ○ Interested to know in advance that whether a program will provide a satisfactory real time response ○ There may be several possible solutions with different time requirements
  9. 9. Expressing Space and TimeComplexity● The space and/or time complexity is usually expressed in form of the function f(n) ○ Where n is the input size for a given instance of the problem being solved.● Expressing space and/ or time complexity as a function has following reasons ○ We may be interested to predict the rate of growth of complexity as the size of problem increases. ○ To Compare the complexities of two or more algorithm ○ Since in modern computers, the memory is not a sence constraint, therefore, our analysis of algorithms will be on the basis of time complexity.
  10. 10. Big ‘O’ Notation● Big O is a characterization scheme that allows to measure properties of algorithms such time and space complexity.● It is useful to set the prerequisites of algorithms and to develop and design efficient algorithms in terms of time and space complexity.
  11. 11. Categories of Algorithm● Based on Big O notation, the algorithm can be categorized as follows ○ Constant time O(1) ○ Logarithmic time O(log n) ○ Linear time O(n) ○ Polynomial time O(nk) (for k > 1) ○ Exponentail time O(kn) for k > 1
  12. 12. Algorithm Analysis● Different ways or algorithms to solve a problem.● Hence, some of the algorithm may be more efficient than the others● There are different types of time complexities which can be analyzed for an algorithm ○ Best Case Time Analysis ○ Average Case Time Analysis ○ Worst Case Time Analysis
  13. 13. Best Case Time Complexity● It is a measure of the minimum time that the algorithm will require for an input of size ‘n’.● The running time of many algorithms varies not only for the inputs of different sizes but also for the different inputs of same size ○ Example : Sorting or Searching
  14. 14. Worst Case Time Complexity● The worst case time complexity of an algorithm is a measure of the maximum time that the algorithm will require for an input of size ‘n’.● Example : If ‘n’ input data items are supplied in reverse order for any sorting algorithm, the algorithm will require n2 operations to perform the sort.
  15. 15. Average Case Time Complexity● The time that an algorithm will require to execute a typical input data of size ‘n’ is known as average case time complexity.