1 / 32

Algorithm Properties and Definitions

Understand the key properties and definitions of algorithms, including input, output, definiteness, correctness, effectiveness, finiteness, and generality. Learn how algorithms work and their importance in computing.

aharding
Download Presentation

Algorithm Properties and Definitions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCE 222Discrete Structures for Computing Algorithms

  2. What is an Algorithm?

  3. An algorithm is a finite sequence of precise instructions for performing a computation or solving a problem. source: Discrete Mathematics and Its Applications, 7th edition by Rosen

  4. A Recipe is an Algorithm

  5. The set of steps to assemble a Piece of Furniture is an Algorithm.

  6. Describe an algorithm for finding the maximum value in a list of integers. • Take 2 minutes • Express the algorithm naturally (i.e. don’t use code)

  7. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality

  8. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set.

  9. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem.

  10. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem. The steps of an algorithm must be defined precisely.

  11. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem. The steps of an algorithm must be defined precisely. An algorithm should produce the correct output values for each set of input values.

  12. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. It must be possible to perform each step of an algorithm exactly and in a finite amount of time. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem. The steps of an algorithm must be defined precisely. An algorithm should produce the correct output values for each set of input values.

  13. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. It must be possible to perform each step of an algorithm exactly and in a finite amount of time. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem. An algorithm should produce the desired output after a finite (but perhaps large) number of steps for any input in the set. The steps of an algorithm must be defined precisely. An algorithm should produce the correct output values for each set of input values.

  14. Properties of Algorithms • Input • Output • Definiteness • Correctness • Effectiveness • Finiteness • Generality An algorithm has input values from a specified set. It must be possible to perform each step of an algorithm exactly and in a finite amount of time. From each set of input values, an algorithm produces output values from a specified set. The output values are the solution to the problem. An algorithm should produce the desired output after a finite (but perhaps large) number of steps for any input in the set. The steps of an algorithm must be defined precisely. An algorithm should produce the correct output values for each set of input values. The procedure should be applicable for all problems of the desired form, not just for a particular set of input values.

  15. Activity • What properties of algorithms do the following have? • Instant Ramen Instructions • IKEA Bookshelf Assembly Instructions Time limit: 5 minutes

  16. Psuedocode is an intermediate between an English description and an implementation in a particular language of an algorithm.

  17. Pseudocode for Finding the Max

  18. Does the max-finding algorithm have all of these properties? • Input • Output • Definiteness • Correctness • Finiteness • Effectiveness • Generality

  19. Activity • The hailstone path length of an integer is the number of times the hailstone function can be applied until the result becomes 1, i.e. the value of such that for . • What are the inputs? • What are the outputs? • What are the steps to solve the problem? • Write your algorithm in text form. Do not write in a programming language. • Time limit: 5 minutes

  20. Example Solution 1 (natural language) To compute the hailstone path length of an integer n, the input is the integer n, the output is an integer giving the length of the path, and the processing is to: declare a variable with initial value 0 to keep track of the path length, do the following until n is equal to 1: if n is even, then divide n by 2; otherwise, multiply n by 3 and add 1; add 1 to the value of the length counter; return the value of the length counter.

  21. Example Solution 2 (pseudocode) Procedurehailstone Inputs:n (integer) Outputs:m (integer) ifn is even then m = n / 2 else m = 3 * n + 1 returnm Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  22. Basic Elements of Pseudocode Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  23. Basic Elements of Pseudocode Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  24. Basic Elements of Pseudocode Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  25. Basic Elements of Pseudocode: Assignment Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  26. Basic Elements of Pseudocode: Loop Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  27. Basic Elements of Pseudocode: Subroutine Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path Procedurehailstone Inputs:n (integer) Outputs:m (integer) ifn is even then m = n / 2 else m = 3 * n + 1 returnm // the next element of the hailstone path

  28. Basic Elements of Pseudocode: Conditional Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path Procedurehailstone Inputs:n (integer) Outputs:m (integer) ifn is even then m = n / 2 else m = 3 * n + 1 returnm // the next element of the hailstone path

  29. Basic Elements of Pseudocode: Returned Values Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  30. Basic Elements of Pseudocode: Comments Procedurehailstone-path-length Inputs:n (integer) Outputs:l (integer) l = 0 whilen > 1 n = hailstone(n) l = l + 1 returnl// the length of the hailstone path

  31. Basic Outline of Pseudocode Procedure name-of-procedure Inputs:name (type), … Outputs:name (type), … // comments assumptions / initializations processing return name, …

  32. Questions?

More Related