415 lecture note #3


[Ch 3] Algorithms (1)

3.1 Introduction & Notation

3.2 Example Algorithms

  1. Algorithm find_largest which finds the largest number in the sequence s1,..,sn.

    Input:  A list of integers s = {s1,..,sn}, and the length n of the list
    Output: A number which is the largest in s.

     

     

     

     

     

     

     

     

  2. Algorithm Div which calculate, for a given integer (n) and a positive integer (d),  the quotient (q) and remainder (r) where q and r ate integers.  Division is done by repeated subtraction, not by arithmetic division.

    Input:  n (an integer), and d (a positive integer)
    Output:  q and r (integers)

    procedure Div(n, d, q, r)
    
    
    

     

     

     

     

     

     

     

     

  3. Algorithm is_even which tests whether a positive integer m is even

    Input:  A positive integer m
    Output:  true if m is even; false if m is odd

     

 

 

 

 

 

3.3 The Euclidean Algorithm